-
Notifications
You must be signed in to change notification settings - Fork 753
/
ModPiston.java
100 lines (85 loc) · 3.12 KB
/
ModPiston.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package tconstruct.modifiers.tools;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import net.minecraft.util.StatCollector;
public class ModPiston extends ToolModTypeFilter
{
String tooltipName;
int max = 10;
public ModPiston(int effect, ItemStack[] items, int[] values)
{
super(effect, "Piston", items, values);
tooltipName = "\u00a77" + StatCollector.translateToLocal("modifier.tool.piston");
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
else
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
if (tags.hasKey(key))
{
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a74" + StatCollector.translateToLocal("modifier.tool.piston") + (" + increase + "/" + max + ");
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
tags.setIntArray(key, keyPair);
}
float knockback = tags.getFloat("Knockback");
knockback += 0.1 * increase;
tags.setFloat("Knockback", knockback);
}
void updateModTag (ItemStack tool, int[] keys)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a77" + StatCollector.translateToLocal("modifier.tool.piston") + (" + keys[0] + "/" + keys[1] + ");
tags.setString(tip, modName);
}
@Override
public boolean validType (ToolCore tool)
{
List list = Arrays.asList(tool.toolCategories());
return list.contains("weapon");
}
}