70 lines
1.7 KiB
Java
70 lines
1.7 KiB
Java
package mods.tinker.tconstruct.modifiers;
|
|
|
|
import mods.tinker.tconstruct.library.tools.ToolMod;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
/* 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);
|
|
|
|
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);
|
|
}
|
|
|
|
}
|