diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java index fea9a18beb..ecef5ae41d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java @@ -77,6 +77,14 @@ default float getItemCharge(ItemStack item) { return ChargeUtils.getCharge(item.getItemMeta()); } + default float getDistanceToMaxCharge(ItemStack item) { + ItemMeta meta = item.getItemMeta(); + float currentCharge = ChargeUtils.getCharge(meta); + float maximum = getMaxItemCharge(item); + + return maximum - currentCharge; + } + /** * This method adds the given charge to the provided {@link ItemStack}. * The method will also return whether this operation was successful. @@ -100,7 +108,6 @@ default boolean addItemCharge(ItemStack item, float charge) { float currentCharge = ChargeUtils.getCharge(meta); float maximum = getMaxItemCharge(item); - // If the item is already fully charged, we abort. if (currentCharge >= maximum) { return false; } 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 e556a0a127..b643cacde6 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 @@ -6,6 +6,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable; +import io.github.thebusybiscuit.slimefun4.core.debug.Debug; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import org.bukkit.Material; @@ -34,50 +36,23 @@ protected void tick(Block b) { if (getCharge(b.getLocation()) < getEnergyConsumption()) { return; } - BlockMenu inv = StorageCacheUtils.getMenu(b.getLocation()); for (int slot : getInputSlots()) { ItemStack item = inv.getItemInSlot(slot); - if (item.getAmount() != 1) { - if (chargeOne(b, inv, slot, item)) { + if (item != null) { + if (charge(b, inv, slot, item)) { return; } } - if (charge(b, inv, slot, item)) { - return; - } } } - - private boolean chargeOne(Block b, BlockMenu inv, int slot, ItemStack item) { - SlimefunItem sfItem = SlimefunItem.getByItem(item); - - if (sfItem instanceof Rechargeable rechargeable) { - float charge = getEnergyConsumption() / 2F; - - if (rechargeable.addItemCharge(item, charge)) { - removeCharge(b.getLocation(), getEnergyConsumption()); - } else if (inv.fits(item, getOutputSlots())) { - inv.pushItem((SlimefunItemStack) sfItem.getItem(), getOutputSlots()); - item.setAmount(item.getAmount() - 1); - } - - return true; - } else if (sfItem != null && inv.fits(item, getOutputSlots())) { - inv.pushItem((SlimefunItemStack) sfItem.getItem(), getOutputSlots()); - // 不可充电物品直接过 - inv.replaceExistingItem(slot, null); - } - return false; - } - private boolean charge(Block b, BlockMenu inv, int slot, ItemStack item) { SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem instanceof Rechargeable rechargeable) { - float charge = getEnergyConsumption() / 2F; + float charge = getEnergyConsumption() / 2F / item.getAmount(); if (rechargeable.addItemCharge(item, charge)) { removeCharge(b.getLocation(), getEnergyConsumption());