-
Notifications
You must be signed in to change notification settings - Fork 755
/
AModKnockbackResistance.java
90 lines (79 loc) · 3.11 KB
/
AModKnockbackResistance.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
package tconstruct.modifiers.armor;
import java.util.EnumSet;
import java.util.UUID;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.armor.ArmorModTypeFilter;
import tconstruct.library.armor.EnumArmorPart;
//TODO: Condense attribute modifiers into one class
public class AModKnockbackResistance extends ArmorModTypeFilter
{
final boolean modifierType;
final int modifyAmount = 2;
public AModKnockbackResistance(int effect, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items, int[] values, boolean type)
{
super(effect, "ExoKnockback" + (type ? "Percent" : "Flat"), armorTypes, items, values);
this.modifierType = type;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(getTagName());
int amount = matchingItems(input) * modifyAmount;
return tags.getInteger("Modifiers") >= amount;
}
@Override
public void modify (ItemStack[] input, ItemStack armor)
{
NBTTagCompound baseTag = armor.getTagCompound();
NBTTagCompound armorTag = armor.getTagCompound().getCompoundTag(getTagName());
int modifiers = armorTag.getInteger("Modifiers");
modifiers -= matchingAmount(input) * modifyAmount;
armorTag.setInteger("Modifiers", modifiers);
int amount = matchingAmount(input);
if (armorTag.hasKey(key))
{
amount += armorTag.getInteger(key);
}
armorTag.setInteger(key, amount);
NBTTagList attributes;
if (baseTag.hasKey("AttributeModifiers"))
{
attributes = baseTag.getTagList("AttributeModifiers");
for (int iter = 0; iter < attributes.tagCount(); iter++)
{
NBTTagCompound tag = (NBTTagCompound) attributes.tagAt(iter);
if (tag.getString("AttributeName").equals("generic.knockbackResistance"))
attributes.removeTag(iter);
}
}
else
{
attributes = new NBTTagList();
baseTag.setTag("AttributeModifiers", attributes);
}
attributes.appendTag(getAttributeTag("generic.knockbackResistance", key, amount*0.01, modifierType, getUUIDFromItem(armor)));
}
private static final UUID head = UUID.fromString("4188779d-69d4-487c-b307-c4c182522c44");
private static final UUID chest = UUID.fromString("4188779d-69d4-487c-b307-c4c182522c45");
private static final UUID pants = UUID.fromString("4188779d-69d4-487c-b307-c4c182522c46");
private static final UUID shoes = UUID.fromString("4188779d-69d4-487c-b307-c4c182522c47");
UUID getUUIDFromItem (ItemStack stack)
{
ArmorCore item = (ArmorCore) stack.getItem();
switch (item.armorPart)
{
case HELMET:
return head;
case CHEST:
return chest;
case PANTS:
return pants;
case SHOES:
return shoes;
}
return null;
}
}