Projectile Weapons tooltip displays the max damage with the current ammo

This commit is contained in:
Bernhard Bonigl committed 2014-10-19 16:49:04 +02:00
1 parent 591954cce1
commit 9f64ef46e8
4 files changed
+38 -1

No files matched your search

@@ -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;
@@ -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();
@@ -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));
}
}