Search in sources :

Example 1 with FuelOperation

use of io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation in project Slimefun4 by Slimefun.

the class Reactor method hasEnoughCoolant.

/**
 * This method cools the given {@link Reactor}.
 *
 * @param reactor
 *            The {@link Location} of this {@link Reactor}
 * @param menu
 *            The {@link Inventory} of this {@link Reactor}
 * @param accessPort
 *            The {@link ReactorAccessPort}, if available
 * @param operation
 *            The {@link FuelOperation} of this {@link Reactor}
 *
 * @return Whether the {@link Reactor} was successfully cooled, if not it should explode
 */
private boolean hasEnoughCoolant(@Nonnull Location reactor, @Nonnull BlockMenu menu, @Nullable BlockMenu accessPort, @Nonnull FuelOperation operation) {
    boolean requiresCoolant = operation.getProgress() % COOLANT_DURATION == 0;
    if (requiresCoolant) {
        ItemStack coolant = ItemStackWrapper.wrap(getCoolant());
        if (accessPort != null) {
            for (int slot : getCoolantSlots()) {
                if (SlimefunUtils.isItemSimilar(accessPort.getItemInSlot(slot), coolant, true, false)) {
                    ItemStack remainingItem = menu.pushItem(accessPort.getItemInSlot(slot), getCoolantSlots());
                    accessPort.replaceExistingItem(slot, remainingItem);
                }
            }
        }
        for (int slot : getCoolantSlots()) {
            if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), coolant, true, false)) {
                menu.consumeItem(slot);
                updateHologram(reactor.getBlock(), "&b\u2744 &7100%");
                return true;
            }
        }
        return false;
    } else {
        updateHologram(reactor.getBlock(), "&b\u2744 &7" + getPercentage(operation.getRemainingTicks(), operation.getTotalTicks()) + "%");
    }
    return true;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack)

Example 2 with FuelOperation

use of io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation in project GlobalWarming by poma123.

the class PollutionListener method onMachineOperationComplete.

@EventHandler
public void onMachineOperationComplete(AsyncMachineOperationFinishEvent e) {
    World world = e.getPosition().getWorld();
    if (!GlobalWarmingPlugin.getRegistry().isWorldEnabled(world.getName())) {
        return;
    }
    if (e.getProcessor() == null) {
        return;
    }
    String id = null;
    ItemStack[] inputs = new ItemStack[] {};
    if ((e.getProcessor().getOwner() instanceof Reactor || e.getProcessor().getOwner() instanceof AGenerator) && e.getOperation() instanceof FuelOperation) {
        id = e.getProcessor().getOwner().getId();
        FuelOperation operation = (FuelOperation) e.getOperation();
        inputs = new ItemStack[] { operation.getIngredient() };
    } else if (e.getProcessor().getOwner() instanceof AContainer && e.getOperation() instanceof CraftingOperation) {
        id = e.getProcessor().getOwner().getId();
        CraftingOperation operation = (CraftingOperation) e.getOperation();
        inputs = operation.getIngredients();
    }
    if (id != null) {
        risePollutionTry(world, id, inputs);
        descendPollutionTry(world, id);
    }
}
Also used : AGenerator(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator) CraftingOperation(io.github.thebusybiscuit.slimefun4.implementation.operations.CraftingOperation) FuelOperation(io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation) AContainer(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) Reactor(io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor) EventHandler(org.bukkit.event.EventHandler)

Example 3 with FuelOperation

use of io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation in project Slimefun4 by Slimefun.

the class AGenerator method getGeneratedOutput.

@Override
public int getGeneratedOutput(Location l, Config data) {
    BlockMenu inv = BlockStorage.getInventory(l);
    FuelOperation operation = processor.getOperation(l);
    if (operation != null) {
        if (!operation.isFinished()) {
            processor.updateProgressBar(inv, 22, operation);
            if (isChargeable()) {
                int charge = getCharge(l, data);
                if (getCapacity() - charge >= getEnergyProduction()) {
                    operation.addProgress(1);
                    return getEnergyProduction();
                }
                return 0;
            } else {
                operation.addProgress(1);
                return getEnergyProduction();
            }
        } else {
            ItemStack fuel = operation.getIngredient();
            if (isBucket(fuel)) {
                inv.pushItem(new ItemStack(Material.BUCKET), getOutputSlots());
            }
            inv.replaceExistingItem(22, new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, " "));
            processor.endOperation(l);
            return 0;
        }
    } else {
        Map<Integer, Integer> found = new HashMap<>();
        MachineFuel fuel = findRecipe(inv, found);
        if (fuel != null) {
            for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
                inv.consumeItem(entry.getKey(), entry.getValue());
            }
            processor.startOperation(l, new FuelOperation(fuel));
        }
        return 0;
    }
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) HashMap(java.util.HashMap) FuelOperation(io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with FuelOperation

use of io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation in project Slimefun4 by Slimefun.

the class Reactor method getGeneratedOutput.

@Override
public int getGeneratedOutput(Location l, Config data) {
    BlockMenu inv = BlockStorage.getInventory(l);
    BlockMenu accessPort = getAccessPort(l);
    FuelOperation operation = processor.getOperation(l);
    if (operation != null) {
        extraTick(l);
        if (!operation.isFinished()) {
            return generateEnergy(l, data, inv, accessPort, operation);
        } else {
            createByproduct(l, inv, accessPort, operation);
            return 0;
        }
    } else {
        burnNextFuel(l, inv, accessPort);
        return 0;
    }
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) FuelOperation(io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation)

Example 5 with FuelOperation

use of io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation in project Slimefun4 by Slimefun.

the class Reactor method burnNextFuel.

private void burnNextFuel(Location l, BlockMenu inv, BlockMenu accessPort) {
    Map<Integer, Integer> found = new HashMap<>();
    MachineFuel fuel = findFuel(inv, found);
    if (accessPort != null) {
        restockFuel(inv, accessPort);
    }
    if (fuel != null) {
        for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
            inv.consumeItem(entry.getKey(), entry.getValue());
        }
        processor.startOperation(l, new FuelOperation(fuel));
    }
}
Also used : HashMap(java.util.HashMap) FuelOperation(io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation) HashMap(java.util.HashMap) Map(java.util.Map) MachineFuel(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel)

Aggregations

FuelOperation (io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation)4 ItemStack (org.bukkit.inventory.ItemStack)4 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)3 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BlockMenu (me.mrCookieSlime.Slimefun.api.inventory.BlockMenu)2 Reactor (io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor)1 CraftingOperation (io.github.thebusybiscuit.slimefun4.implementation.operations.CraftingOperation)1 AContainer (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer)1 AGenerator (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator)1 MachineFuel (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel)1 World (org.bukkit.World)1 EventHandler (org.bukkit.event.EventHandler)1