@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int slotID, boolean isHand) {
if (itemStack.getItem() == this && itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("delTime", NBT.TAG_LONG)) {
long delTime = itemStack.getTagCompound().getLong("delTime");
if (delTime <= world.getTotalWorldTime()) {
if (entity instanceof EntityPlayer)
((EntityPlayer)entity).inventory.setInventorySlotContents(slotID, null);
else
entity.setCurrentItemOrArmor(slotID, null);
}
}
}
@Override
public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
if (!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound());
itemStack.getTagCompound().setLong("delTime", world.getTotalWorldTime() + 3000L);
}
@Override
public boolean onEntityItemUpdate(EntityItem entityItem) {
if (entityItem.worldObj.isRemote) return super.onEntityItemUpdate(entityItem);
ItemStack stack = entityItem.getEntityItem();
if (stack.getItem() == this && stack.hasTagCompound() && stack.getTagCompound().hasKey("delTime", NBT.TAG_LONG)) {
long delTime = stack.getTagCompound().getLong("delTime");
if (delTime <= entityItem.worldObj.getTotalWorldTime())
entityItem.setDead();
}
return super.onEntityItemUpdate(entityItem);
}