Search in sources :

Example 1 with AContainer

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer in project Slimefun4 by Slimefun.

the class PostSetup method loadSmelteryRecipes.

private static void loadSmelteryRecipes() {
    Smeltery smeltery = (Smeltery) SlimefunItems.SMELTERY.getItem();
    if (smeltery != null && !smeltery.isDisabled()) {
        MakeshiftSmeltery makeshiftSmeltery = ((MakeshiftSmeltery) SlimefunItems.MAKESHIFT_SMELTERY.getItem());
        ItemStack[] input = null;
        for (ItemStack[] output : smeltery.getRecipes()) {
            if (input == null) {
                input = output;
            } else {
                if (input[0] != null && output[0] != null) {
                    addSmelteryRecipe(input, output, makeshiftSmeltery);
                }
                input = null;
            }
        }
        for (SlimefunItem item : Slimefun.getRegistry().getEnabledSlimefunItems()) {
            if (item instanceof AContainer) {
                AContainer machine = (AContainer) item;
                if (machine.getMachineIdentifier().equals("ELECTRIC_SMELTERY")) {
                    List<MachineRecipe> recipes = machine.getMachineRecipes();
                    Collections.sort(recipes, Comparator.comparingInt(recipe -> recipe == null ? 0 : -recipe.getInput().length));
                }
            }
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) MakeshiftSmeltery(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) JsonElement(com.google.gson.JsonElement) SlimefunItems(io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems) MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) Map(java.util.Map) GrindStone(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone) JsonUtils(io.github.thebusybiscuit.slimefun4.utils.JsonUtils) Smeltery(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery) Nonnull(javax.annotation.Nonnull) Bukkit(org.bukkit.Bukkit) CommandSender(org.bukkit.command.CommandSender) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Iterator(java.util.Iterator) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Stream(java.util.stream.Stream) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) AContainer(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer) ChatColor(org.bukkit.ChatColor) OreCrusher(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher) BufferedReader(java.io.BufferedReader) Comparator(java.util.Comparator) Collections(java.util.Collections) MakeshiftSmeltery(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery) Smeltery(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery) MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) AContainer(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer) MakeshiftSmeltery(io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with AContainer

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer 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 AContainer

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer in project SupplementalServiceableness by NCBPFluffyBear.

the class Voltmeter method consumerStatistics.

private void consumerStatistics(Player player, EnergyNet energyNet) {
    Map<Location, EnergyNetComponent> consumers = null;
    try {
        Field consumersField = energyNet.getClass().getDeclaredField("consumers");
        consumersField.setAccessible(true);
        consumers = (Map<Location, EnergyNetComponent>) consumersField.get(energyNet);
    } catch (NoSuchFieldException | IllegalAccessException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "An error has occurred while trying to access private fields: " + System.lineSeparator() + ex);
    }
    int numberOfConsumers = consumers.size();
    int joulesPerSecConsumed = 0;
    int minConsumption = Integer.MAX_VALUE;
    int maxConsumption = 0;
    EnergyNetComponent smallestConsumer = null;
    EnergyNetComponent largestConsumer = null;
    for (Location loc : consumers.keySet()) {
        if (consumers.get(loc) instanceof AContainer) {
            AContainer consumer = (AContainer) consumers.get(loc);
            int consumption = consumer.getEnergyConsumption();
            joulesPerSecConsumed += consumption;
            if (consumption < minConsumption) {
                minConsumption = consumption;
                smallestConsumer = consumer;
            }
            if (consumption > maxConsumption) {
                maxConsumption = consumption;
                largestConsumer = consumer;
            }
        }
    }
    Utils.sendChatMsg(player, "&7========== &5Consumers &7==========");
    Utils.sendChatMsg(player, "");
    Utils.sendChatMsg(player, "&5Number of consumers: &7" + numberOfConsumers);
    Utils.sendChatMsg(player, "&5Joules consumed: &7" + joulesPerSecConsumed + " J/s");
    Utils.sendChatMsg(player, "&5Smallest consumer: &7" + (Objects.isNull(smallestConsumer) ? "None" : pretifyId(smallestConsumer.getId())) + " &5with &7" + (Objects.isNull(smallestConsumer) ? "0" : minConsumption) + " J/s");
    Utils.sendChatMsg(player, "&5Largest consumer: &7" + (Objects.isNull(largestConsumer) ? "None" : pretifyId(largestConsumer.getId())) + " &5with &7" + maxConsumption + " J/s");
    Utils.sendChatMsg(player, "");
    Utils.sendChatMsg(player, "&7===============================");
}
Also used : Field(java.lang.reflect.Field) EnergyNetComponent(io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent) AContainer(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer) Location(org.bukkit.Location)

Aggregations

AContainer (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer)3 ItemStack (org.bukkit.inventory.ItemStack)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)1 EnergyNetComponent (io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent)1 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)1 SlimefunItems (io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems)1 Reactor (io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor)1 GrindStone (io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone)1 MakeshiftSmeltery (io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery)1 OreCrusher (io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher)1 Smeltery (io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery)1 CraftingOperation (io.github.thebusybiscuit.slimefun4.implementation.operations.CraftingOperation)1 FuelOperation (io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation)1 JsonUtils (io.github.thebusybiscuit.slimefun4.utils.JsonUtils)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Field (java.lang.reflect.Field)1