From 9f64ef46e8af15c82d2bfe70f00500ce9969834d Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Sun, 19 Oct 2014 16:46:48 +0200 Subject: [PATCH] Projectile Weapons tooltip displays the max damage with the current ammo --- resources/assets/tinker/lang/en_US.lang | 1 + .../java/tconstruct/client/TProxyClient.java | 3 ++ .../library/entity/ProjectileBase.java | 2 +- .../library/weaponry/ProjectileWeapon.java | 33 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/resources/assets/tinker/lang/en_US.lang b/resources/assets/tinker/lang/en_US.lang index e88b2b24..14cd6fc2 100644 --- a/resources/assets/tinker/lang/en_US.lang +++ b/resources/assets/tinker/lang/en_US.lang @@ -820,6 +820,7 @@ modifier.tool.beheading=Beheading creativeModLock.tooltip=Target Lock: attribute.name.ammo.attackDamage=Base Damage +attribute.name.ammo.maxAttackDamage=Max. Damage tool.pickaxe=Pickaxe tool.shovel=Shovel diff --git a/src/main/java/tconstruct/client/TProxyClient.java b/src/main/java/tconstruct/client/TProxyClient.java index 6f517f5c..a16518c2 100644 --- a/src/main/java/tconstruct/client/TProxyClient.java +++ b/src/main/java/tconstruct/client/TProxyClient.java @@ -1,6 +1,7 @@ package tconstruct.client; import java.io.InputStream; +import java.text.DecimalFormat; import javax.xml.parsers.*; import mantle.client.SmallFontRenderer; import mantle.lib.client.MantleClientRegistry; @@ -18,6 +19,8 @@ import tconstruct.tools.items.ManualInfo; public class TProxyClient extends TProxyCommon { + public static DecimalFormat df = new DecimalFormat("##.#"); + /* TODO: Split this class up into its respective parts */ public static SmallFontRenderer smallFontRenderer; public static IIcon metalBall; diff --git a/src/main/java/tconstruct/library/entity/ProjectileBase.java b/src/main/java/tconstruct/library/entity/ProjectileBase.java index 8ced6d17..847b90b3 100644 --- a/src/main/java/tconstruct/library/entity/ProjectileBase.java +++ b/src/main/java/tconstruct/library/entity/ProjectileBase.java @@ -178,7 +178,7 @@ public abstract class ProjectileBase extends EntityArrow implements IEntityAddit public void onHitEntity(MovingObjectPosition movingobjectposition) { NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool"); float speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); - float damage = speed * tags.getInteger("Attack"); + float damage = speed * tags.getInteger("Attack"); // todo: potentially change this back to MathHelper.ceiling_float_int to get 1/2 heart steps back // Damage calculations and stuff. For reference see AbilityHelper.onLeftClickEntity ToolCore ammo = (ToolCore)returnStack.getItem(); diff --git a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java index ae055c09..461b87cc 100644 --- a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java +++ b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java @@ -1,5 +1,8 @@ package tconstruct.library.weaponry; +import net.minecraft.init.Items; +import net.minecraft.util.StatCollector; +import tconstruct.client.TProxyClient; import tconstruct.library.TConstructRegistry; import tconstruct.weaponry.TinkerWeaponry; import tconstruct.weaponry.client.CrosshairType; @@ -21,6 +24,7 @@ import tconstruct.library.tools.ToolCore; import tconstruct.library.util.TextureHelper; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -361,4 +365,33 @@ public abstract class ProjectileWeapon extends ToolCore implements IAccuracy, IW icons.put(entry.getKey(), anims); } } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { + super.addInformation(stack, player, list, par4); + + if(!stack.hasTagCompound()) + return; + + // also display max damage with current ammo + ItemStack currentAmmo = searchForAmmo(player, stack); + if(currentAmmo == null) + return; + + float damage; + if(currentAmmo.getItem() == Items.arrow) + damage = 2; + else if(currentAmmo.getItem() instanceof AmmoItem && currentAmmo.hasTagCompound()) + damage = currentAmmo.getTagCompound().getCompoundTag("InfiTool").getInteger("Attack"); + else + return; + + damage *= getProjectileSpeed(stack); + damage /= 2; + + list.remove(list.size()-1); // remove last item (the damage of the bow itself) + list.add(currentAmmo.getDisplayName()); + list.add(StatCollector.translateToLocal("attribute.name.ammo.maxAttackDamage") + ": " + TProxyClient.df.format(damage)); + } }