Search in sources :

Example 1 with EntityItemPickupEvent

use of net.minecraftforge.event.entity.player.EntityItemPickupEvent in project PneumaticCraft by MineMaarten.

the class DroneEntityAIPickupItems method continueExecuting.

/**
     * Returns whether an in-progress EntityAIBase should continue executing
     */
@Override
public boolean continueExecuting() {
    if (curPickingUpEntity.isDead)
        return false;
    if (Vec3.createVectorHelper(curPickingUpEntity.posX, curPickingUpEntity.posY, curPickingUpEntity.posZ).distanceTo(drone.getPosition()) < 1.5) {
        ItemStack stack = curPickingUpEntity.getEntityItem();
        if (itemPickupWidget.isItemValidForFilters(stack)) {
            //not posting the event globally, as I don't have a way of handling a canceled event.
            new EventHandlerPneumaticCraft().onPlayerPickup(new EntityItemPickupEvent(drone.getFakePlayer(), curPickingUpEntity));
            int stackSize = stack.stackSize;
            //side doesn't matter, drones aren't ISided.
            ItemStack remainder = PneumaticCraftUtils.exportStackToInventory(drone.getInventory(), stack, ForgeDirection.UP);
            if (remainder == null) {
                drone.onItemPickupEvent(curPickingUpEntity, stackSize);
                curPickingUpEntity.setDead();
            }
        }
        return false;
    }
    return !drone.getPathNavigator().hasNoPath();
}
Also used : ItemStack(net.minecraft.item.ItemStack) EventHandlerPneumaticCraft(pneumaticCraft.common.EventHandlerPneumaticCraft) EntityItemPickupEvent(net.minecraftforge.event.entity.player.EntityItemPickupEvent)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 EntityItemPickupEvent (net.minecraftforge.event.entity.player.EntityItemPickupEvent)1 EventHandlerPneumaticCraft (pneumaticCraft.common.EventHandlerPneumaticCraft)1