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