Search in sources :

Example 1 with AmadronRetrievalEvent

use of me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent in project pnc-repressurized by TeamPneumatic.

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()).getCount() * times;
                for (int i = 0; i < drone.getInv().getSlots(); i++) {
                    requiredCount -= drone.getInv().getStackInSlot(i).getCount();
                }
                if (requiredCount <= 0) {
                    for (int i = 0; i < drone.getInv().getSlots(); i++) {
                        drone.getInv().setStackInSlot(i, ItemStack.EMPTY);
                    }
                    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(me.desht.pneumaticcraft.common.entity.living.EntityDrone) AmadronRetrievalEvent(me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

AmadronRetrievalEvent (me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent)1 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)1 AmadronOffer (me.desht.pneumaticcraft.common.recipes.AmadronOffer)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1