Files
TinkersConstruct/src/main/java/tconstruct/modifiers/tools/ModBlaze.java
T

101 lines
3.0 KiB
Java
Raw Normal View History

2013-12-06 11:37:06 -08:00
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;
2014-04-16 15:15:51 +02:00
import net.minecraft.util.StatCollector;
public class ModBlaze extends ToolModTypeFilter
{
String tooltipName;
int max;
public ModBlaze(int effect, ItemStack[] items, int[] values)
{
super(effect, "Blaze", items, values);
2014-04-16 15:15:51 +02:00
tooltipName = "\u00a76" + StatCollector.translateToLocal("modifier.tool.blaze");
max = 25;
}
@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)
{
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 = "\u00a76Blaze (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
tags.setIntArray(key, keyPair);
}
int fiery = tags.getInteger("Fiery");
fiery += (increase);
tags.setInteger("Fiery", fiery);
}
void updateModTag (ItemStack tool, int[] keys)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a76Blaze (" + keys[0] + "/" + keys[1] + ")";
tags.setString(tip, modName);
}
2014-02-17 00:31:43 -05:00
@Override
public boolean validType (ToolCore tool)
{
List list = Arrays.asList(tool.toolCategories());
return list.contains("melee") || list.contains("ammo");
}
}