Search in sources :

Example 1 with AmadronRetrievalEvent

use of pneumaticCraft.api.drone.AmadronRetrievalEvent in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onDroneSuicide.

@SubscribeEvent
public void onDroneSuicide(DroneSuicideEvent event) {
    if (event.drone instanceof EntityDrone) {
        EntityDrone drone = (EntityDrone) event.drone;
        AmadronOffer offer = drone.getHandlingOffer();
        if (offer != null) {
            int times = drone.getOfferTimes();
            if (offer.getInput() instanceof ItemStack) {
                int requiredCount = ((ItemStack) offer.getInput()).stackSize * times;
                for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                    if (drone.getInventory().getStackInSlot(i) != null) {
                        requiredCount -= drone.getInventory().getStackInSlot(i).stackSize;
                    }
                }
                if (requiredCount <= 0) {
                    for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                        drone.getInventory().setInventorySlotContents(i, null);
                    }
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            } else {
                int requiredCount = ((FluidStack) offer.getInput()).amount * times;
                if (drone.getTank().getFluidAmount() >= requiredCount) {
                    MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
                }
            }
        }
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) AmadronRetrievalEvent(pneumaticCraft.api.drone.AmadronRetrievalEvent) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ItemStack (net.minecraft.item.ItemStack)1 AmadronRetrievalEvent (pneumaticCraft.api.drone.AmadronRetrievalEvent)1 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)1 AmadronOffer (pneumaticCraft.common.recipes.AmadronOffer)1