Changed order in which EntityItemPickupEvent is called, it will no longer be called if the 'delay' on the item is still active. Also EntityItems that are in the world with invalid item stacks will now kill themselves.

This commit is contained in:
LexManos 2012-08-18 21:07:29 -07:00
parent 9d7a6bbb2e
commit 87e0fced25
1 changed files with 34 additions and 17 deletions

View File

@ -10,30 +10,47 @@
public class EntityItem extends Entity
{
@@ -238,6 +241,26 @@
@@ -120,6 +123,11 @@
{
int var2 = this.item.stackSize;
this.setDead();
}
+
+ if (this.item == null || this.item.stackSize <= 0)
+ {
+ this.setDead();
+ }
}
public boolean func_70289_a(EntityItem par1EntityItem)
@@ -223,7 +231,7 @@
NBTTagCompound var2 = par1NBTTagCompound.getCompoundTag("Item");
this.item = ItemStack.loadItemStackFromNBT(var2);
- if (this.item == null)
+ if (this.item == null || this.item.stackSize <= 0)
{
this.setDead();
}
@@ -236,9 +244,21 @@
{
if (!this.worldObj.isRemote)
{
+ if (this.delayBeforeCanPickup > 0)
+ {
+ return;
+ }
+
+ EntityItemPickupEvent event = new EntityItemPickupEvent(par1EntityPlayer, this);
+
+ if (MinecraftForge.EVENT_BUS.post(event))
+ {
+ return;
+ }
+
+ if (delayBeforeCanPickup == 0 && (event.isHandled() || item.stackSize <= 0))
+ {
+ //FML Notify pickup
+ worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
+ par1EntityPlayer.onItemPickup(this, var2);
+
+ if (item.stackSize <= 0)
+ {
+ setDead();
+ }
+ }
+
+ var2 = item.stackSize;
+
if (this.delayBeforeCanPickup == 0 && par1EntityPlayer.inventory.addItemStackToInventory(this.item))
int var2 = this.item.stackSize;
- if (this.delayBeforeCanPickup == 0 && par1EntityPlayer.inventory.addItemStackToInventory(this.item))
+ if (this.delayBeforeCanPickup <= 0 && (event.isHandled() || var2 <= 0 || par1EntityPlayer.inventory.addItemStackToInventory(this.item)))
{
if (this.item.itemID == Block.wood.blockID)
{