Skip to content

Commit

Permalink
Modifiers now check explicitly for Tool. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Lydeamore committed Jan 14, 2015
1 parent 8e865fd commit e0c4b0c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
42 changes: 22 additions & 20 deletions src/main/java/ExAstris/Modifier/ModCrooked.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,33 @@ public class ModCrooked extends ModBoolean {
static String name = "Crooked";
static String color = "\u00a77";
static String tooltip = "Crooked";

public ModCrooked(ItemStack[] items, int effect) {
super(items, effect, name, color, tooltip);
}

@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.getBoolean("Lava") && !tags.hasKey("Lapis") && !tags.hasKey("Silk Touch") && !tags.hasKey("Hammered"))
if (tool.getItem() instanceof ToolCore)
{
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
ToolCore toolitem = (ToolCore) tool.getItem();
if (!validType(toolitem)) return false;

NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.getBoolean("Lava") && !tags.hasKey("Lapis") && !tags.hasKey("Silk Touch") && !tags.hasKey("Hammered"))
{
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
}
}

return false;
}

public void modify(ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean(name, true);

int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
Expand All @@ -46,26 +48,26 @@ public void modify(ItemStack[] input, ItemStack tool)
int miningSpeed = tags.getInteger("MiningSpeed");
miningSpeed -= 300;
if (miningSpeed < 0)
miningSpeed = 0;
miningSpeed = 0;
tags.setInteger("MiningSpeed", miningSpeed);

if (tags.hasKey("MiningSpeed2"))
{
int miningSpeed2 = tags.getInteger("MiningSpeed2");
miningSpeed2 -= 300;
if (miningSpeed2 < 0)
int miningSpeed2 = tags.getInteger("MiningSpeed2");
miningSpeed2 -= 300;
if (miningSpeed2 < 0)
miningSpeed2 = 0;
tags.setInteger("MiningSpeed2", miningSpeed2);
tags.setInteger("MiningSpeed2", miningSpeed2);
}

float knockback = tags.getFloat("Knockback");

knockback += 1.5F;
tags.setFloat("Knockback", knockback);
knockback += 1.5F;
tags.setFloat("Knockback", knockback);

addToolTip(tool, color + tooltip, color + key);
}

public boolean validType (ToolCore tool)
{
if(tool.getToolName().equals("Mattock") ||
Expand All @@ -80,7 +82,7 @@ public boolean validType (ToolCore tool)
{
return true;
}

return false;
}

Expand Down
33 changes: 18 additions & 15 deletions src/main/java/ExAstris/Modifier/ModHammered.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,52 @@ public class ModHammered extends ModBoolean {
static String name = "Hammered";
static String color = "\u00a79";
static String tooltip = "Smashing";

public ModHammered(ItemStack[] items, int i)
{
super(items, i, name, color, tooltip);
}

@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.getBoolean("Lava") && !tags.hasKey("Lapis") && !tags.hasKey("Silk Touch") && !tags.hasKey("Crooked"))
if (tool.getItem() instanceof ToolCore)
{
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
ToolCore toolitem = (ToolCore) tool.getItem();
if (!validType(toolitem)) return false;

NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");

if (!tags.getBoolean("Lava") && !tags.hasKey("Lapis") && !tags.hasKey("Silk Touch") && !tags.hasKey("Crooked"))
{
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
}
}
return false;
return false;
}

public void modify(ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean(name, true);

int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);

int miningSpeed = tags.getInteger("MiningSpeed");
miningSpeed -= 400;
if (miningSpeed < 0)
miningSpeed = 0;
miningSpeed = 0;
tags.setInteger("MiningSpeed", miningSpeed);

int attack = tags.getInteger("Attack");
attack += 3;
tags.setInteger("Attack", attack);

addToolTip(tool, color + tooltip, color + key);
}

public boolean validType (ToolCore tool)
{
if(tool.getToolName().equals("Pickaxe") ||
Expand Down

0 comments on commit e0c4b0c

Please sign in to comment.