diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index f6bf728ab..60a8a13f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -80,10 +80,7 @@ public class SlimefunRegistry { private final Map chunks = new HashMap<>(); private final Map layouts = new EnumMap<>(SlimefunGuideLayout.class); private final Map> mobDrops = new EnumMap<>(EntityType.class); - - @Deprecated - private final Map capacities = new HashMap<>(); - + private final Map blockMenuPresets = new HashMap<>(); private final Map universalInventories = new HashMap<>(); private final Map, Set> globalItemHandlers = new HashMap<>(); @@ -237,11 +234,6 @@ public class SlimefunRegistry { return slimefunIds; } - @Deprecated - public Map getEnergyCapacities() { - return capacities; - } - public Map getMenuPresets() { return blockMenuPresets; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java index 8cbd760a1..eed867d0c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java @@ -2,19 +2,30 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets import java.util.Optional; -import org.bukkit.block.Block; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler; +import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; +import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; +/** + * The {@link Multimeter} is used to measure charge and capacity of any {@link EnergyNetComponent}. + * + * @author TheBusyBiscuit + * + * @see EnergyNet + * @see EnergyNetComponent + * + */ public class Multimeter extends SimpleSlimefunItem { public Multimeter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { @@ -24,21 +35,26 @@ public class Multimeter extends SimpleSlimefunItem { @Override public ItemUseHandler getItemHandler() { return e -> { - Optional block = e.getClickedBlock(); + Optional block = e.getSlimefunBlock(); - if (block.isPresent()) { - Block b = block.get(); + if (e.getClickedBlock().isPresent() && block.isPresent()) { + SlimefunItem item = block.get(); - if (ChargableBlock.isChargable(b)) { - e.cancel(); + if (item instanceof EnergyNetComponent) { + EnergyNetComponent component = (EnergyNetComponent) item; - String stored = DoubleHandler.getFancyDouble(ChargableBlock.getCharge(b)) + " J"; - String capacity = DoubleHandler.getFancyDouble(ChargableBlock.getMaxCharge(b)) + " J"; + if (component.isChargeable()) { + e.cancel(); - Player p = e.getPlayer(); - p.sendMessage(""); - SlimefunPlugin.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity)); - p.sendMessage(""); + Location l = e.getClickedBlock().get().getLocation(); + String stored = DoubleHandler.getFancyDouble(component.getCharge(l)) + " J"; + String capacity = DoubleHandler.getFancyDouble(component.getCapacity()) + " J"; + + Player p = e.getPlayer(); + p.sendMessage(""); + SlimefunPlugin.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity)); + p.sendMessage(""); + } } } }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java index 8b5080df7..d1de20267 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java @@ -30,7 +30,6 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; @@ -195,7 +194,7 @@ public abstract class AbstractEntityAssembler extends SimpleSl return; } - if (lifetime % 60 == 0 && ChargableBlock.getCharge(b) >= getEnergyConsumption()) { + if (lifetime % 60 == 0 && getCharge(b.getLocation()) >= getEnergyConsumption()) { BlockMenu menu = BlockStorage.getInventory(b); boolean hasBody = findResource(menu, getBody(), bodySlots); @@ -204,7 +203,7 @@ public abstract class AbstractEntityAssembler extends SimpleSl if (hasBody && hasHead) { consumeResources(menu); - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), KEY_OFFSET)); Slimefun.runSync(() -> { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java index 8302880b8..0c984af35 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java @@ -23,7 +23,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -47,7 +46,7 @@ public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBl if (inv != null) { inv.dropItems(b.getLocation(), getInputSlots()); } - + return true; }); } @@ -100,11 +99,11 @@ public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBl for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 3.0, 3.0, 3.0, n -> n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult())) { for (int slot : getInputSlots()) { if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) { - if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) { + if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) { return; } - ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION); + removeCharge(b.getLocation(), ENERGY_CONSUMPTION); inv.consumeItem(slot); ((Ageable) n).setAge(((Ageable) n).getAge() + 2000); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java index 831583010..2e15e23dd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java @@ -16,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public abstract class AutoAnvil extends AContainer { @@ -57,15 +56,15 @@ public abstract class AutoAnvil extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots()); progress.remove(b); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBreeder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBreeder.java index b88db024e..b607e2a17 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBreeder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBreeder.java @@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -90,6 +89,7 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN public boolean isSynchronized() { return true; } + }); } @@ -99,11 +99,11 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, this::canBreed)) { for (int slot : getInputSlots()) { if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) { - if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) { + if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) { return; } - ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION); + removeCharge(b.getLocation(), ENERGY_CONSUMPTION); inv.consumeItem(slot); ((Animals) n).setLoveModeTicks(600); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index 85cb3d60e..50fa528f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; /** @@ -68,11 +67,11 @@ public abstract class AutoBrewer extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java index ff9b03605..5c52da238 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java @@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; /** @@ -78,11 +77,11 @@ public class AutoDisenchanter extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java index c25892873..86a56448c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java @@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; /** @@ -104,15 +103,15 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots()); progress.remove(b); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java index afcb3f41f..d77a19913 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java @@ -24,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public class AutoEnchanter extends AContainer { @@ -67,15 +66,15 @@ public class AutoEnchanter extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); for (ItemStack item : processing.get(b).getOutput()) { menu.pushItem(item, getOutputSlots()); @@ -137,6 +136,7 @@ public class AutoEnchanter extends AContainer { emeraldEnchantments.add(enchantment); } } + specialAmount += EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java index 13d61ab95..9b05adb57 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java @@ -31,7 +31,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; @@ -56,7 +55,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I @Override public void newInstance(BlockMenu menu, Block b) { if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) { - menu.replaceExistingItem(6, new CustomItem(new ItemStack(Material.GUNPOWDER), "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine")); + menu.replaceExistingItem(6, new CustomItem(Material.GUNPOWDER, "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine")); menu.addMenuClickHandler(6, (p, slot, item, action) -> { BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true)); newInstance(menu, b); @@ -64,7 +63,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I }); } else { - menu.replaceExistingItem(6, new CustomItem(new ItemStack(Material.REDSTONE), "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine")); + menu.replaceExistingItem(6, new CustomItem(Material.REDSTONE, "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine")); menu.addMenuClickHandler(6, (p, slot, item, action) -> { BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false)); newInstance(menu, b); @@ -72,7 +71,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I }); } - menu.replaceExistingItem(7, new CustomItem(new ItemStack(Material.CRAFTING_TABLE), "&7Craft Last", "", "&e> Click to craft the last shaped recipe", "&cOnly works with the last one")); + menu.replaceExistingItem(7, new CustomItem(Material.CRAFTING_TABLE, "&7Craft Last", "", "&e> Click to craft the last shaped recipe", "&cOnly works with the last one")); menu.addMenuClickHandler(7, (p, slot, item, action) -> { tick(b, true); return false; @@ -215,7 +214,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I return; } - if (ChargableBlock.getCharge(block) < getEnergyConsumption()) { + if (getCharge(block.getLocation()) < getEnergyConsumption()) { return; } @@ -259,7 +258,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I ItemStack output = SlimefunPlugin.getRegistry().getAutomatedCraftingChamberRecipes().get(input); if (output != null && menu.fits(output, getOutputSlots())) { menu.pushItem(output.clone(), getOutputSlots()); - ChargableBlock.addCharge(block, -getEnergyConsumption()); + removeCharge(block.getLocation(), getEnergyConsumption()); for (int j = 0; j < 9; j++) { if (menu.getItemInSlot(getInputSlots()[j]) != null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java index 59ecfbc9b..ae4932013 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java @@ -11,7 +11,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public class ChargingBench extends AContainer { @@ -42,7 +41,7 @@ public class ChargingBench extends AContainer { @Override protected void tick(Block b) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } @@ -64,7 +63,7 @@ public class ChargingBench extends AContainer { float charge = getEnergyConsumption() / 2F; if (((Rechargeable) sfItem).addItemCharge(item, charge)) { - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); } else if (inv.fits(item, getOutputSlots())) { inv.pushItem(item, getOutputSlots()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java index f48be3bc8..e31cf4484 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java @@ -26,7 +26,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -116,7 +115,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem implements Inve protected void tick(Block b) { BlockMenu inv = BlockStorage.getInventory(b); - if (ChargableBlock.getCharge(b) >= getEnergyConsumption()) { + if (getCharge(b.getLocation()) >= getEnergyConsumption()) { for (int x = -getRadius(); x <= getRadius(); x++) { for (int z = -getRadius(); z <= getRadius(); z++) { Block block = b.getRelative(x, 0, z); @@ -135,7 +134,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem implements Inve if (ageable.getAge() < ageable.getMaximumAge()) { for (int slot : getInputSlots()) { if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) { - ChargableBlock.addCharge(machine, -getEnergyConsumption()); + removeCharge(machine.getLocation(), getEnergyConsumption()); inv.consumeItem(slot); ageable.setAge(ageable.getAge() + 1); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java index 4f037164e..eccd31b8b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java @@ -16,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public abstract class ElectricDustWasher extends AContainer { @@ -59,21 +58,21 @@ public abstract class ElectricDustWasher extends AContainer { if (timeleft > 0 && getSpeed() < 10) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots()); progress.remove(b); @@ -90,7 +89,7 @@ public abstract class ElectricDustWasher extends AContainer { } private boolean process(Block b, BlockMenu menu, int slot) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true)) { + if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true, false)) { if (!legacyMode && !hasFreeSlot(menu)) { return true; } @@ -106,7 +105,7 @@ public abstract class ElectricDustWasher extends AContainer { return true; } - else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true)) { + else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true, false)) { MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER }); if (menu.fits(r.getOutput()[0], getOutputSlots())) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java index f8e75b2e4..874cc1cb6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java @@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public abstract class ElectricGoldPan extends AContainer implements RecipeDisplayItem { @@ -63,21 +62,21 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla if (timeleft > 0 && getSpeed() < 10) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); ItemStack output = processing.get(b).getOutput()[0]; @@ -109,7 +108,7 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla } private boolean process(Block b, BlockMenu menu, int slot) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true)) { + if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true, false)) { ItemStack output = goldPan.getRandomOutput(); MachineRecipe r = new MachineRecipe(3 / getSpeed(), new ItemStack[0], new ItemStack[] { output }); @@ -122,7 +121,7 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla return true; } - else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) { + else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true, false)) { ItemStack output = netherGoldPan.getRandomOutput(); MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { output }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java index 6fe0a343b..94e2eb6c5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java @@ -27,7 +27,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -59,14 +58,14 @@ public class FluidPump extends SimpleSlimefunItem implements Invent private void constructMenu(BlockMenuPreset preset) { for (int i : border) { - preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler()); + preset.addItem(i, new CustomItem(Material.GRAY_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); } for (int i : inputBorder) { - preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler()); + preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); } for (int i : outputBorder) { - preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler()); + preset.addItem(i, new CustomItem(Material.ORANGE_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); } for (int i : getOutputSlots()) { @@ -109,16 +108,16 @@ public class FluidPump extends SimpleSlimefunItem implements Invent Block fluid = b.getRelative(BlockFace.DOWN); Optional bucket = getFilledBucket(fluid); - if (bucket.isPresent() && ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) { + if (bucket.isPresent() && getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) { BlockMenu menu = BlockStorage.getInventory(b); for (int slot : getInputSlots()) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) { + if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true, false)) { if (!menu.fits(bucket.get(), getOutputSlots())) { return; } - ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION); + removeCharge(b.getLocation(), ENERGY_CONSUMPTION); menu.consumeItem(slot); menu.pushItem(bucket.get().clone(), getOutputSlots()); consumeFluid(fluid); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java index e13a6b319..383510cd4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java @@ -3,9 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.bukkit.Material; import org.bukkit.block.Block; @@ -16,19 +14,11 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; -import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; @@ -57,7 +47,9 @@ public abstract class HeatedPressureChamber extends AContainer { @Override public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) { - if (flow == ItemTransportFlow.WITHDRAW) return getOutputSlots(); + if (flow == ItemTransportFlow.WITHDRAW) { + return getOutputSlots(); + } List slots = new ArrayList<>(); @@ -122,88 +114,6 @@ public abstract class HeatedPressureChamber extends AContainer { return new int[] { 24, 25 }; } - @Override - public void preRegister() { - addItemHandler(new BlockTicker() { - - @Override - public void tick(Block b, SlimefunItem sf, Config data) { - HeatedPressureChamber.this.tick(b); - } - - @Override - public boolean isSynchronized() { - return false; - } - }); - } - - @Override - protected void tick(Block b) { - BlockMenu menu = BlockStorage.getInventory(b); - - if (isProcessing(b)) { - int timeleft = progress.get(b); - - if (timeleft > 0) { - ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } - - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); - menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots()); - - progress.remove(b); - processing.remove(b); - } - } - else { - Map found = new HashMap<>(); - MachineRecipe recipe = findRecipe(menu, found); - - if (recipe != null) { - if (!menu.fits(recipe.getOutput()[0], getOutputSlots())) { - return; - } - - for (Map.Entry entry : found.entrySet()) { - menu.consumeItem(entry.getKey(), entry.getValue()); - } - - processing.put(b, recipe); - progress.put(b, recipe.getTicks()); - } - } - } - - private MachineRecipe findRecipe(BlockMenu menu, Map found) { - for (MachineRecipe recipe : recipes) { - for (ItemStack input : recipe.getInput()) { - for (int slot : getInputSlots()) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), input, true)) { - found.put(slot, input.getAmount()); - break; - } - } - } - - if (found.size() == recipe.getInput().length) { - return recipe; - } - else { - found.clear(); - } - } - - return null; - } - @Override public String getMachineIdentifier() { return "HEATED_PRESSURE_CHAMBER"; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java index 875657a6d..91b5a0f6c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java @@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -107,7 +106,7 @@ public class TreeGrowthAccelerator extends SlimefunItem implements InventoryBloc protected void tick(Block b) { BlockMenu inv = BlockStorage.getInventory(b); - if (ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) { + if (getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) { for (int x = -RADIUS; x <= RADIUS; x++) { for (int z = -RADIUS; z <= RADIUS; z++) { Block block = b.getRelative(x, 0, z); @@ -126,8 +125,8 @@ public class TreeGrowthAccelerator extends SlimefunItem implements InventoryBloc private boolean grow(Block machine, Block block, BlockMenu inv, Sapling sapling) { for (int slot : getInputSlots()) { - if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) { - ChargableBlock.addCharge(machine, -ENERGY_CONSUMPTION); + if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false, false)) { + removeCharge(machine.getLocation(), ENERGY_CONSUMPTION); sapling.setStage(sapling.getStage() + 1); block.setBlockData(sapling); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java index 98b75f825..93af5064a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java @@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -109,13 +108,13 @@ public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyN while (iterator.hasNext() && experiencePoints == 0) { Entity entity = iterator.next(); - if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) { + if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) { return; } experiencePoints = getStoredExperience(b) + ((ExperienceOrb) entity).getExperience(); - ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION); + removeCharge(b.getLocation(), ENERGY_CONSUMPTION); entity.remove(); int withdrawn = 0; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index 160d170a4..fe60f11e2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecip import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -149,16 +148,15 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec if (timeleft > 0) { ChestMenuUtils.updateProgressbar(inv, 4, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - inv.replaceExistingItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + inv.replaceExistingItem(4, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); inv.pushItem(processing.get(b).getOutput()[0], getOutputSlots()); progress.remove(b); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java index 721020aa2..c0bf229eb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java @@ -24,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; @@ -101,11 +100,11 @@ public abstract class OilPump extends AContainer implements RecipeDisplayItem { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java index a9248431e..b68ba0e83 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java @@ -18,7 +18,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; public abstract class GPSTransmitter extends SimpleSlimefunItem implements EnergyNetComponent { @@ -53,12 +52,12 @@ public abstract class GPSTransmitter extends SimpleSlimefunItem imp @Override public void tick(Block b, SlimefunItem item, Config data) { - int charge = ChargableBlock.getCharge(b); + int charge = getCharge(b.getLocation()); UUID owner = UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")); if (charge >= getEnergyConsumption()) { SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, true); - ChargableBlock.setCharge(b.getLocation(), charge - getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); } else { SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, false); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 8282df268..2a79478d4 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -27,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemExcepti import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.ItemState; -import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable; @@ -370,14 +369,6 @@ public class SlimefunItem implements Placeable { SlimefunPlugin.getRegistry().getRadioactiveItems().add(this); } - if (this instanceof EnergyNetComponent && !SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(getID())) { - int capacity = ((EnergyNetComponent) this).getCapacity(); - - if (capacity > 0) { - SlimefunPlugin.getRegistry().getEnergyCapacities().put(id, capacity); - } - } - if (SlimefunPlugin.getItemCfg().getBoolean(id + ".enabled")) { if (!category.isRegistered()) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index d54662972..fda50f104 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -234,11 +233,11 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock, ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); if (isChargeable()) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - ChargableBlock.addCharge(b, -getEnergyConsumption()); + removeCharge(b.getLocation(), getEnergyConsumption()); progress.put(b, timeleft - 1); } else { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index ce1c3cb74..41a20f16a 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -25,7 +25,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; @@ -141,7 +140,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar()); if (isChargeable()) { - int charge = ChargableBlock.getCharge(l); + int charge = getCharge(l); if (getCapacity() - charge >= getEnergyProduction()) { progress.put(l, timeleft - 1); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java index a7d7acc41..7e3a84c25 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.block.Block; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.Capacitor; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -27,13 +26,8 @@ public final class ChargableBlock { } public static boolean isChargable(Location l) { - String id = BlockStorage.checkID(l); - - if (id == null) { - return false; - } - - return SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(id); + SlimefunItem item = BlockStorage.check(l); + return item instanceof EnergyNetComponent && ((EnergyNetComponent) item).isChargeable(); } public static int getCharge(Block b) { @@ -84,14 +78,14 @@ public final class ChargableBlock { } public static int addCharge(Location l, int addedCharge) { - String id = BlockStorage.checkID(l); + SlimefunItem item = BlockStorage.check(l); - if (id == null) { + if (item == null) { BlockStorage.clearBlockInfo(l); return 0; } - int capacity = SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0); + int capacity = ((EnergyNetComponent) item).getCapacity(); int charge = getCharge(l); int availableSpace = capacity - charge; @@ -109,7 +103,7 @@ public final class ChargableBlock { setCharge(l, charge); - if (SlimefunItem.getByID(id) instanceof Capacitor) { + if (item instanceof Capacitor) { SlimefunUtils.updateCapacitorTexture(l, charge, capacity); } } @@ -117,7 +111,7 @@ public final class ChargableBlock { charge += addedCharge; setCharge(l, charge); - if (SlimefunItem.getByID(id) instanceof Capacitor) { + if (item instanceof Capacitor) { SlimefunUtils.updateCapacitorTexture(l, charge, capacity); } } @@ -130,14 +124,15 @@ public final class ChargableBlock { } public static int getMaxCharge(Location l) { - String id = BlockStorage.checkID(l); + SlimefunItem item = BlockStorage.check(l); - if (id == null) { + if (item == null) { BlockStorage.clearBlockInfo(l); return 0; } - return SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0); + return item instanceof EnergyNetComponent ? ((EnergyNetComponent) item).getCapacity() : 0; + } }