2013-12-06 11:37:06 -08:00
|
|
|
package tconstruct.modifiers.tools;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-05 10:28:54 -05:00
|
|
|
import tconstruct.library.tools.ToolCore;
|
2014-04-16 16:09:06 +02:00
|
|
|
import net.minecraft.util.StatCollector;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-12-12 14:21:30 -08:00
|
|
|
public class ModRedstone extends ToolModTypeFilter
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
String tooltipName;
|
2013-12-12 14:21:30 -08:00
|
|
|
int max = 50;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-12-12 14:21:30 -08:00
|
|
|
public ModRedstone(int effect, ItemStack[] items, int[] values)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-12 14:21:30 -08:00
|
|
|
super(effect, "Redstone", items, values);
|
2014-04-16 16:09:06 +02:00
|
|
|
tooltipName = "\u00a74" + StatCollector.translateToLocal("modifier.tool.redstone");
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
2013-12-12 14:21:30 -08:00
|
|
|
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
|
2013-07-26 21:18:53 -07:00
|
|
|
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[] keyPair;
|
2013-12-12 14:21:30 -08:00
|
|
|
int increase = matchingAmount(input);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (tags.hasKey(key))
|
|
|
|
|
{
|
|
|
|
|
keyPair = tags.getIntArray(key);
|
|
|
|
|
if (keyPair[0] % max == 0)
|
|
|
|
|
{
|
|
|
|
|
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);
|
2014-04-16 16:09:06 +02:00
|
|
|
String modName = "\u00a74" + StatCollector.translateToLocal("modifier.tool.redstone") + (" + increase + "/" + max + ");
|
2013-07-26 21:18:53 -07:00
|
|
|
int tooltipIndex = addToolTip(tool, tooltipName, modName);
|
|
|
|
|
keyPair = new int[] { increase, max, tooltipIndex };
|
|
|
|
|
tags.setIntArray(key, keyPair);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int miningSpeed = tags.getInteger("MiningSpeed");
|
|
|
|
|
miningSpeed += (increase * 8);
|
|
|
|
|
tags.setInteger("MiningSpeed", miningSpeed);
|
|
|
|
|
|
2013-11-10 17:51:18 -08:00
|
|
|
String[] type = { "MiningSpeed2", "MiningSpeedHandle", "MiningSpeedExtra" };
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-10 17:51:18 -08:00
|
|
|
if (tags.hasKey(type[i]))
|
|
|
|
|
{
|
|
|
|
|
int speed = tags.getInteger(type[i]);
|
|
|
|
|
speed += (increase * 8);
|
|
|
|
|
tags.setInteger(type[i], speed);
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tags.hasKey("DrawSpeed"))
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
// int drawSpeed = tags.getInteger("DrawSpeed");
|
2013-07-26 21:18:53 -07:00
|
|
|
int baseDrawSpeed = tags.getInteger("BaseDrawSpeed");
|
|
|
|
|
int drawSpeed = (int) (baseDrawSpeed - (0.1f * baseDrawSpeed * (keyPair[0] / 50f)));
|
|
|
|
|
tags.setInteger("DrawSpeed", drawSpeed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateModTag (ItemStack tool, int[] keys)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
String tip = "ModifierTip" + keys[2];
|
2014-04-16 16:09:06 +02:00
|
|
|
String modName = "\u00a74" + StatCollector.translateToLocal("modifier.tool.redstone") + (" + keys[0] + "/" + keys[1] + ");
|
2013-07-26 21:18:53 -07:00
|
|
|
tags.setString(tip, modName);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public boolean validType (ToolCore tool)
|
|
|
|
|
{
|
|
|
|
|
List list = Arrays.asList(tool.toolCategories());
|
|
|
|
|
return list.contains("harvest") || list.contains("utility") || list.contains("bow");
|
|
|
|
|
}
|
|
|
|
|
}
|