mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-27 15:33:18 +00:00
133 lines
4.1 KiB
Diff
133 lines
4.1 KiB
Diff
--- ../src_base/minecraft/net/minecraft/entity/item/EntityItem.java
|
|
+++ ../src_work/minecraft/net/minecraft/entity/item/EntityItem.java
|
|
@@ -1,6 +1,11 @@
|
|
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;
|
|
import net.minecraft.block.Block;
|
|
@@ -30,6 +35,11 @@
|
|
/** The EntityItem's random initial float height. */
|
|
public float hoverStart;
|
|
|
|
+ /**
|
|
+ * The maximum age of this EntityItem. The item is expired once this is reached.
|
|
+ */
|
|
+ public int lifespan = 6000;
|
|
+
|
|
public EntityItem(World par1World, double par2, double par4, double par6)
|
|
{
|
|
super(par1World);
|
|
@@ -48,6 +58,7 @@
|
|
{
|
|
this(par1World, par2, par4, par6);
|
|
this.setEntityItemStack(par8ItemStack);
|
|
+ this.lifespan = (par8ItemStack.getItem() == null ? 6000 : par8ItemStack.getItem().getEntityLifespan(par8ItemStack, par1World));
|
|
}
|
|
|
|
/**
|
|
@@ -78,6 +89,15 @@
|
|
*/
|
|
public void onUpdate()
|
|
{
|
|
+ ItemStack stack = this.getDataWatcher().getWatchableObjectItemStack(10);
|
|
+ if (stack != null && stack.getItem() != null)
|
|
+ {
|
|
+ if (stack.getItem().onEntityItemUpdate(this))
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+
|
|
super.onUpdate();
|
|
|
|
if (this.delayBeforeCanPickup > 0)
|
|
@@ -133,7 +153,29 @@
|
|
|
|
++this.age;
|
|
|
|
- if (!this.worldObj.isRemote && this.age >= 6000)
|
|
+ ItemStack item = getDataWatcher().getWatchableObjectItemStack(10);
|
|
+
|
|
+ if (!this.worldObj.isRemote && this.age >= lifespan)
|
|
+ {
|
|
+ if (item != null)
|
|
+ {
|
|
+ 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();
|
|
+ }
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ this.setDead();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (item != null && item.stackSize <= 0)
|
|
{
|
|
this.setDead();
|
|
}
|
|
@@ -268,6 +310,7 @@
|
|
{
|
|
par1NBTTagCompound.setShort("Health", (short)((byte)this.health));
|
|
par1NBTTagCompound.setShort("Age", (short)this.age);
|
|
+ par1NBTTagCompound.setInteger("Lifespan", lifespan);
|
|
|
|
if (this.getEntityItem() != null)
|
|
{
|
|
@@ -285,10 +328,17 @@
|
|
NBTTagCompound nbttagcompound1 = par1NBTTagCompound.getCompoundTag("Item");
|
|
this.setEntityItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound1));
|
|
|
|
- if (this.getEntityItem() == null)
|
|
+ ItemStack item = getDataWatcher().getWatchableObjectItemStack(10);
|
|
+
|
|
+ if (item == null || item.stackSize <= 0)
|
|
{
|
|
this.setDead();
|
|
}
|
|
+
|
|
+ if (par1NBTTagCompound.hasKey("Lifespan"))
|
|
+ {
|
|
+ lifespan = par1NBTTagCompound.getInteger("Lifespan");
|
|
+ }
|
|
}
|
|
|
|
/**
|
|
@@ -298,10 +348,22 @@
|
|
{
|
|
if (!this.worldObj.isRemote)
|
|
{
|
|
+ if (this.delayBeforeCanPickup > 0)
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ EntityItemPickupEvent event = new EntityItemPickupEvent(par1EntityPlayer, this);
|
|
+
|
|
+ if (MinecraftForge.EVENT_BUS.post(event))
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
ItemStack itemstack = this.getEntityItem();
|
|
int i = itemstack.stackSize;
|
|
|
|
- if (this.delayBeforeCanPickup == 0 && par1EntityPlayer.inventory.addItemStackToInventory(itemstack))
|
|
+ if (this.delayBeforeCanPickup <= 0 && (event.getResult() == Result.ALLOW || i <= 0 || par1EntityPlayer.inventory.addItemStackToInventory(itemstack)))
|
|
{
|
|
if (itemstack.itemID == Block.wood.blockID)
|
|
{
|