Example usage for net.minecraftforge.event.entity.item ItemExpireEvent ItemExpireEvent

List of usage examples for net.minecraftforge.event.entity.item ItemExpireEvent ItemExpireEvent

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.item ItemExpireEvent ItemExpireEvent.

Prototype

public ItemExpireEvent(ItemEntity entityItem, int extraLife) 

Source Link

Document

Creates a new event for an expiring EntityItem.

Usage

From source file:v3XzZ.mFC.EntityCauldronItem.java

License:LGPL

/**
  * Called to update the entity's position/logic.
  *//*from  w  w  w  .  j  a v a  2s.c o m*/
public void onUpdate() {
    this.onEntityUpdate();

    if (shouldDespawn) {
        this.setDead();
    }
    this.shouldDespawn = true;

    this.delayBeforeCanPickup = 10;

    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);

    if (this.onGround) {
        this.motionY *= -0.5D;
    }

    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();
    }
}