-
Notifications
You must be signed in to change notification settings - Fork 755
/
ModDurability.java
73 lines (59 loc) · 2.02 KB
/
ModDurability.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
package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolMod;
import tconstruct.util.config.PHConstruct;
/* Adds an integer NBTTag */
public class ModDurability extends ToolMod
{
String tooltipName;
String color;
int durability;
float modifier;
int miningLevel;
public ModDurability(ItemStack[] items, int effect, int dur, float mod, int level, String k, String tip, String c)
{
super(items, effect, k);
durability = dur;
modifier = mod;
miningLevel = level;
tooltipName = tip;
color = c;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey(key))
return false;
return super.canModify(tool, input);
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int base = tags.getInteger("BaseDurability");
int bonus = tags.getInteger("BonusDurability");
float modDur = tags.getFloat("ModDurability");
bonus += durability;
modDur += modifier;
int total = (int) ((base + bonus) * (modDur + 1f));
if (total <= 0)
total = 1;
tags.setInteger("TotalDurability", total);
tags.setInteger("BonusDurability", bonus);
tags.setFloat("ModDurability", modDur);
if (PHConstruct.miningLevelIncrease)
{
int mLevel = tags.getInteger("HarvestLevel");
if (mLevel < miningLevel)
tags.setInteger("HarvestLevel", miningLevel);
}
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
tags.setBoolean(key, true);
String modTip = color + key;
addToolTip(tool, tooltipName, modTip);
}
}