-
Notifications
You must be signed in to change notification settings - Fork 755
/
ModButtertouch.java
115 lines (101 loc) · 3.62 KB
/
ModButtertouch.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package tconstruct.modifiers.tools;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import tconstruct.library.tools.ToolCore;
public class ModButtertouch extends ModBoolean
{
public ModButtertouch(ItemStack[] items, int effect)
{
super(items, effect, "Silk Touch", "\u00a7e", "Silky");
}
@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.getBoolean("Lava") && !tags.hasKey("Lapis"))
{
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean(key, true);
addEnchantment(tool, Enchantment.silkTouch, 1);
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
int attack = tags.getInteger("Attack");
attack -= 3;
if (attack < 0)
attack = 0;
tags.setInteger("Attack", attack);
int miningSpeed = tags.getInteger("MiningSpeed");
miningSpeed -= 300;
if (miningSpeed < 0)
miningSpeed = 0;
tags.setInteger("MiningSpeed", miningSpeed);
if (tags.hasKey("MiningSpeed2"))
{
int miningSpeed2 = tags.getInteger("MiningSpeed2");
miningSpeed2 -= 300;
if (miningSpeed2 < 0)
miningSpeed2 = 0;
tags.setInteger("MiningSpeed2", miningSpeed2);
}
addToolTip(tool, color + tooltipName, color + key);
}
public void addEnchantment (ItemStack tool, Enchantment enchant, int level)
{
NBTTagList tags = new NBTTagList();
Map enchantMap = EnchantmentHelper.getEnchantments(tool);
Iterator iterator = enchantMap.keySet().iterator();
int index;
int lvl;
boolean hasEnchant = false;
while (iterator.hasNext())
{
NBTTagCompound enchantTag = new NBTTagCompound();
index = ((Integer) iterator.next()).intValue();
lvl = (Integer) enchantMap.get(index);
if (index == enchant.effectId)
{
hasEnchant = true;
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) level));
tags.appendTag(enchantTag);
}
else
{
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) lvl));
tags.appendTag(enchantTag);
}
}
if (!hasEnchant)
{
NBTTagCompound enchantTag = new NBTTagCompound();
enchantTag.setShort("id", (short) enchant.effectId);
enchantTag.setShort("lvl", (short) ((byte) level));
tags.appendTag(enchantTag);
}
tool.stackTagCompound.setTag("ench", tags);
}
public boolean validType (ToolCore tool)
{
List list = Arrays.asList(tool.toolCategories());
return list.contains("weapon") || list.contains("harvest");
}
}