From d8f5992282f7b92713420a4d8338914c25805e36 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 3 Aug 2020 17:25:27 +0200 Subject: [PATCH] Fixes #2103 --- CHANGELOG.md | 1 + .../items/multiblocks/BackpackCrafter.java | 25 ++++++++++++++++--- .../multiblocks/EnhancedCraftingTable.java | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23f526923..5a3457846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ #### Fixes * Fixed Programmable Androids rotating in the wrong direction * Fixed #2176 +* Fixed #2103 ## Release Candidate 15 (01 Aug 2020) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java index 6d2786244..89c537f04 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java @@ -13,7 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; -import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; @@ -24,9 +24,19 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * This abstract super class is responsible for some utility methods for machines which + * are capable of upgrading backpacks. + * + * @author TheBusyBiscuit + * + * @see EnhancedCraftingTable + * @see MagicWorkbench + * + */ abstract class BackpackCrafter extends MultiBlockMachine { - public BackpackCrafter(Category category, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) { + BackpackCrafter(Category category, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) { super(category, item, recipe, trigger); } @@ -34,7 +44,15 @@ abstract class BackpackCrafter extends MultiBlockMachine { Inventory fakeInv = Bukkit.createInventory(null, 9, "Fake Inventory"); for (int j = 0; j < inv.getContents().length; j++) { - ItemStack stack = inv.getContents()[j] != null && inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1) : null; + ItemStack stack = inv.getContents()[j]; + + // Fixes #2103 - Properly simulating the consumption + // (which may leave behind empty buckets or glass bottles) + if (stack != null) { + stack = stack.clone(); + ItemUtils.consumeItem(stack, true); + } + fakeInv.setItem(j, stack); } @@ -91,7 +109,6 @@ abstract class BackpackCrafter extends MultiBlockMachine { PlayerProfile.fromUUID(UUID.fromString(idSplit[0]), profile -> { Optional optional = profile.getBackpack(Integer.parseInt(idSplit[1])); - optional.ifPresent(playerBackpack -> playerBackpack.setSize(size)); }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java index 97b72b81a..e77b7bba8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java @@ -43,6 +43,7 @@ public class EnhancedCraftingTable extends BackpackCrafter { for (int i = 0; i < inputs.size(); i++) { if (isCraftable(inv, inputs.get(i))) { ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone(); + if (Slimefun.hasUnlocked(p, output, true)) { craft(inv, dispenser, p, b, output); }