Skip to content

Commit

Permalink
Display Armor/Accessories correctly in toolstations/forges
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 24, 2014
1 parent b91c0cb commit c38a249
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 41 deletions.
2 changes: 2 additions & 0 deletions resources/assets/tinker/lang/en_US.lang
Expand Up @@ -758,6 +758,8 @@ gui.toolstation15=Mining Level:
gui.toolstation16=Usage Speed:
gui.toolstation17=Modifiers
gui.toolstation18=Modifiers remaining:
gui.toolstation19=Damage Reduction:
gui.toolstation20=Protection:

gui.mining1=Stone
gui.mining2=Iron
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/tconstruct/library/armor/ArmorCore.java
Expand Up @@ -183,14 +183,26 @@ public ArmorProperties getProperties (EntityLivingBase player, ItemStack armor,
if (tags.getBoolean("Broken"))
return new ArmorProperties(0, 0, 0);

double current = getProtection(tags);

return new ArmorProperties(0, current / 100, 100);
}

public double getProtection(ItemStack stack)
{
return getProtection(stack.getTagCompound().getCompoundTag(getBaseTagName()));
}

public double getProtection(NBTTagCompound tags)
{
float maxDurability = tags.getInteger("TotalDurability");
float currentDurability = maxDurability - tags.getInteger("Damage");
float ratio = currentDurability / maxDurability;
double base = tags.getDouble("BaseDefense");
double max = tags.getDouble("MaxDefense");
double current = (max - base) * ratio + base;

return new ArmorProperties(0, current / 100, 100);
return current;
}

@Override
Expand Down Expand Up @@ -388,7 +400,7 @@ public int getItemMaxDamageFromStackForDisplay (ItemStack stack)
return tags.getCompoundTag(getBaseTagName()).getInteger("Damage");
}

DecimalFormat df = new DecimalFormat("##.#");
private DecimalFormat df = new DecimalFormat("##.#");

@Override
@SideOnly(Side.CLIENT)
Expand All @@ -400,12 +412,7 @@ public void addInformation (ItemStack stack, EntityPlayer player, List list, boo
double protection = 0;
if (!tags.getBoolean("Broken"))
{
float maxDurability = tags.getInteger("TotalDurability");
float currentDurability = maxDurability - tags.getInteger("Damage");
float ratio = currentDurability / maxDurability;
double base = tags.getDouble("BaseDefense");
double max = tags.getDouble("MaxDefense");
protection = (max - base) * ratio + base;
protection = getProtection(tags);
}
if (protection > 0)
list.add("\u00a77Protection: " + df.format(protection) + "%");
Expand Down

0 comments on commit c38a249

Please sign in to comment.