From b56d05ef9d6be5f3413cb62f2940f5b9cf3a8549 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Apr 2013 19:04:18 -0400 Subject: [PATCH] ItemStack delegation to Item for damage values. --- common/forge_at.cfg | 4 +- .../net/minecraft/item/Item.java.patch | 48 ++++++++++++++++++- .../net/minecraft/item/ItemStack.java.patch | 43 ++++++++++++++++- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/common/forge_at.cfg b/common/forge_at.cfg index fea2f9b01..cdf8a89e8 100644 --- a/common/forge_at.cfg +++ b/common/forge_at.cfg @@ -150,4 +150,6 @@ public ml.b #FD:PotionEffect/field_76460_b #duration protected ane.a #FD:BlockFluid/field_94425_a #theIcon #GuiIngame protected aww.* #FD:GuiIngame/* # All private -> protected -protected aww.*() #MD:GuiIngame/* # All private -> protected \ No newline at end of file +protected aww.*() #MD:GuiIngame/* # All private -> protected +#ItemStack +default wm.e #FD:ItemStack/field_77991_e # make default access for itemDamage \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch index 1fd41397b..313fade7f 100644 --- a/patches/minecraft/net/minecraft/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/item/Item.java.patch @@ -60,7 +60,7 @@ Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3); return par1World.rayTraceBlocks_do_do(vec3, vec31, par3, !par3); } -@@ -720,4 +736,434 @@ +@@ -720,4 +736,480 @@ { StatList.initStats(); } @@ -494,4 +494,50 @@ + */ + @SideOnly(Side.CLIENT) + public void renderHelmetOverlay(ItemStack stack, EntityPlayer player, ScaledResolution resolution, float partialTicks, boolean hasScreen, int mouseX, int mouseY){} ++ ++ /** ++ * Return the itemDamage represented by this ItemStack. Defaults to the itemDamage field on ItemStack, but can be overridden here for other sources such as NBT. ++ * ++ * @param stack The itemstack that is damaged ++ * @return the damage value ++ */ ++ public int getItemDamageFromStack(ItemStack stack) ++ { ++ return stack.itemDamage; ++ } ++ ++ /** ++ * Return the itemDamage display value represented by this itemstack. ++ * @param stack the stack ++ * @return the damage value ++ */ ++ public int getItemDamageFromStackForDisplay(ItemStack stack) ++ { ++ return stack.itemDamage; ++ } ++ ++ /** ++ * Return if this itemstack is damaged. Note only called if {@link #isDamageable()} is true. ++ * @param stack the stack ++ * @return if the stack is damaged ++ */ ++ public boolean isItemStackDamaged(ItemStack stack) ++ { ++ return stack.itemDamage > 0; ++ } ++ ++ /** ++ * Set the damage for this itemstack. Note, this method is responsible for zero checking. ++ * @param stack the stack ++ * @param damage the new damage value ++ */ ++ public void setItemDamageForStack(ItemStack stack, int damage) ++ { ++ stack.itemDamage = damage; ++ ++ if (stack.itemDamage < 0) ++ { ++ stack.itemDamage = 0; ++ } ++ } } diff --git a/patches/minecraft/net/minecraft/item/ItemStack.java.patch b/patches/minecraft/net/minecraft/item/ItemStack.java.patch index 9e7d8f2eb..d891a45bc 100644 --- a/patches/minecraft/net/minecraft/item/ItemStack.java.patch +++ b/patches/minecraft/net/minecraft/item/ItemStack.java.patch @@ -1,6 +1,47 @@ --- ../src_base/minecraft/net/minecraft/item/ItemStack.java +++ ../src_work/minecraft/net/minecraft/item/ItemStack.java -@@ -382,7 +382,7 @@ +@@ -249,7 +249,7 @@ + */ + public boolean isItemDamaged() + { +- return this.isItemStackDamageable() && this.itemDamage > 0; ++ return this.isItemStackDamageable() && this.getItem().isItemStackDamaged(this); + } + + /** +@@ -257,7 +257,7 @@ + */ + public int getItemDamageForDisplay() + { +- return this.itemDamage; ++ return this.getItem().getItemDamageFromStackForDisplay(this); + } + + /** +@@ -265,7 +265,7 @@ + */ + public int getItemDamage() + { +- return this.itemDamage; ++ return this.getItem().getItemDamageFromStack(this); + } + + /** +@@ -273,12 +273,7 @@ + */ + public void setItemDamage(int par1) + { +- this.itemDamage = par1; +- +- if (this.itemDamage < 0) +- { +- this.itemDamage = 0; +- } ++ this.getItem().setItemDamageForStack(this, par1); + } + + /** +@@ -382,7 +377,7 @@ */ public int getDamageVsEntity(Entity par1Entity) {