ForgePatch/patches/minecraft/net/minecraft/entity/item/EntityItem.java.patch

105 lines
3.5 KiB
Diff
Raw Normal View History

2012-12-13 07:45:13 +00:00
--- ../src_base/minecraft/net/minecraft/entity/item/EntityItem.java
+++ ../src_work/minecraft/net/minecraft/entity/item/EntityItem.java
@@ -1,6 +1,11 @@
2012-12-13 07:45:13 +00:00
package net.minecraft.entity.item;
import java.util.Iterator;
+
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.Event.Result;
+import net.minecraftforge.event.entity.item.ItemExpireEvent;
+import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import cpw.mods.fml.common.registry.GameRegistry;
2012-12-13 07:45:13 +00:00
import net.minecraft.block.Block;
@@ -33,6 +38,11 @@
/** The EntityItem's random initial float height. */
public float hoverStart = (float)(Math.random() * Math.PI * 2.0D);
2012-12-13 07:45:13 +00:00
+ /**
+ * The maximum age of this EntityItem. The item is expired once this is reached.
+ */
+ public int lifespan = 6000;
2012-12-13 07:45:13 +00:00
+
public EntityItem(World par1World, double par2, double par4, double par6, ItemStack par8ItemStack)
{
2012-12-13 07:45:13 +00:00
super(par1World);
@@ -44,6 +54,7 @@
this.motionX = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));
this.motionY = 0.20000000298023224D;
this.motionZ = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));
+ this.lifespan = (par8ItemStack.getItem() == null ? 6000 : par8ItemStack.getItem().getEntityLifespan(par8ItemStack, par1World));
}
/**
2012-12-13 07:45:13 +00:00
@@ -124,7 +135,20 @@
++this.age;
- if (!this.worldObj.isRemote && this.age >= 6000)
+ if (!this.worldObj.isRemote && this.age >= lifespan)
+ {
+ ItemExpireEvent event = new ItemExpireEvent(this, (item.getItem() == null ? 6000 : item.getItem().getEntityLifespan(item, worldObj)));
+ if (MinecraftForge.EVENT_BUS.post(event))
+ {
+ lifespan += event.extraLife;
+ }
+ else
+ {
+ this.setDead();
+ }
+ }
+
+ if (this.item == null || this.item.stackSize <= 0)
{
this.setDead();
}
2012-12-13 07:45:13 +00:00
@@ -240,6 +264,7 @@
{
par1NBTTagCompound.setShort("Health", (short)((byte)this.health));
par1NBTTagCompound.setShort("Age", (short)this.age);
+ par1NBTTagCompound.setInteger("Lifespan", lifespan);
if (this.item != null)
{
2012-12-13 07:45:13 +00:00
@@ -257,10 +282,15 @@
NBTTagCompound var2 = par1NBTTagCompound.getCompoundTag("Item");
this.item = ItemStack.loadItemStackFromNBT(var2);
- if (this.item == null)
+ if (this.item == null || this.item.stackSize <= 0)
{
this.setDead();
}
+
+ if (par1NBTTagCompound.hasKey("Lifespan"))
+ {
+ lifespan = par1NBTTagCompound.getInteger("Lifespan");
+ }
}
/**
2012-12-13 07:45:13 +00:00
@@ -270,9 +300,21 @@
{
if (!this.worldObj.isRemote)
{
+ if (this.delayBeforeCanPickup > 0)
+ {
+ return;
+ }
+
+ EntityItemPickupEvent event = new EntityItemPickupEvent(par1EntityPlayer, this);
+
+ if (MinecraftForge.EVENT_BUS.post(event))
+ {
+ return;
+ }
+
int var2 = this.item.stackSize;
- if (this.delayBeforeCanPickup == 0 && par1EntityPlayer.inventory.addItemStackToInventory(this.item))
+ if (this.delayBeforeCanPickup <= 0 && (event.getResult() == Result.ALLOW || var2 <= 0 || par1EntityPlayer.inventory.addItemStackToInventory(this.item)))
{
if (this.item.itemID == Block.wood.blockID)
{