Files
MinecraftForge/patches/minecraft/net/minecraft/item/ItemStack.java.patch
T

132 lines
4.0 KiB
Diff

--- ../src-base/minecraft/net/minecraft/item/ItemStack.java
+++ ../src-work/minecraft/net/minecraft/item/ItemStack.java
@@ -50,6 +50,7 @@
private boolean canPlaceOnCacheResult;
private static final String __OBFID = "CL_00000043";
+ private net.minecraftforge.fml.common.registry.RegistryDelegate<Item> delegate;
public ItemStack(Block blockIn)
{
this((Block)blockIn, 1);
@@ -81,7 +82,7 @@
this.canDestroyCacheResult = false;
this.canPlaceOnCacheBlock = null;
this.canPlaceOnCacheResult = false;
- this.item = itemIn;
+ this.setItem(itemIn);
this.stackSize = amount;
this.itemDamage = meta;
@@ -121,11 +122,12 @@
public Item getItem()
{
- return this.item;
+ return this.delegate != null ? this.delegate.get() : null;
}
public boolean onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
+ if (!worldIn.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, playerIn, worldIn, pos, side, hitX, hitY, hitZ);
boolean flag = this.getItem().onItemUse(this, playerIn, worldIn, pos, side, hitX, hitY, hitZ);
if (flag)
@@ -170,11 +172,11 @@
{
if (nbt.hasKey("id", 8))
{
- this.item = Item.getByNameOrId(nbt.getString("id"));
+ this.setItem(Item.getByNameOrId(nbt.getString("id")));
}
else
{
- this.item = Item.getItemById(nbt.getShort("id"));
+ this.setItem(Item.getItemById(nbt.getShort("id")));
}
this.stackSize = nbt.getByte("Count");
@@ -198,7 +200,7 @@
public int getMaxStackSize()
{
- return this.getItem().getItemStackLimit();
+ return this.getItem().getItemStackLimit(this);
}
public boolean isStackable()
@@ -208,7 +210,7 @@
public boolean isItemStackDamageable()
{
- return this.item == null ? false : (this.item.getMaxDamage() <= 0 ? false : !this.hasTagCompound() || !this.getTagCompound().getBoolean("Unbreakable"));
+ return this.item == null ? false : (this.item.getMaxDamage(this) <= 0 ? false : !this.hasTagCompound() || !this.getTagCompound().getBoolean("Unbreakable"));
}
public boolean getHasSubtypes()
@@ -218,32 +220,27 @@
public boolean isItemDamaged()
{
- return this.isItemStackDamageable() && this.itemDamage > 0;
+ return this.isItemStackDamageable() && getItem().isDamaged(this);
}
public int getItemDamage()
{
- return this.itemDamage;
+ return getItem().getDamage(this);
}
public int getMetadata()
{
- return this.itemDamage;
+ return getItem().getMetadata(this);
}
public void setItemDamage(int meta)
{
- this.itemDamage = meta;
-
- if (this.itemDamage < 0)
- {
- this.itemDamage = 0;
- }
+ getItem().setDamage(this, meta);
}
public int getMaxDamage()
{
- return this.item.getMaxDamage();
+ return this.item.getMaxDamage(this);
}
public boolean attemptDamageItem(int amount, Random rand)
@@ -275,8 +272,8 @@
}
}
- this.itemDamage += amount;
- return this.itemDamage > this.getMaxDamage();
+ setItemDamage(getItemDamage() + amount); //Redirect through Item's callback if applicable.
+ return getItemDamage() > getMaxDamage();
}
}
@@ -335,7 +332,7 @@
public boolean canHarvestBlock(Block blockIn)
{
- return this.item.canHarvestBlock(blockIn);
+ return getItem().canHarvestBlock(blockIn, this);
}
public boolean interactWithEntity(EntityPlayer playerIn, EntityLivingBase entityIn)
@@ -861,6 +858,7 @@
public void setItem(Item newItem)
{
+ this.delegate = newItem != null ? newItem.delegate : null;
this.item = newItem;
}