ItemStack delegation to Item for damage values.

This commit is contained in:
Christian 2013-04-23 19:04:18 -04:00
parent 7aa91ca635
commit b56d05ef9d
3 changed files with 92 additions and 3 deletions

View file

@ -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
protected aww.*() #MD:GuiIngame/* # All private -> protected
#ItemStack
default wm.e #FD:ItemStack/field_77991_e # make default access for itemDamage

View file

@ -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;
+ }
+ }
}

View file

@ -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)
{