diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java index 3b33869ec..54bb9ce09 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java @@ -17,6 +17,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -135,7 +136,7 @@ abstract class AbstractItemNetwork extends Network { Optional target = getAttachedBlock(l); if (target.isPresent()) { - item = CargoUtils.insert(this, inventories, l.getBlock(), target.get(), false, item); + item = CargoUtils.insert(this, inventories, l.getBlock(), target.get(), false, item, ItemStackWrapper.ofItem(item)); if (item == null) { terminal.replaceExistingItem(request.getSlot(), null); @@ -232,10 +233,10 @@ abstract class AbstractItemNetwork extends Network { long timestamp = SlimefunPlugin.getProfiler().newEntry(); BlockMenu menu = BlockStorage.getInventory(bus); - if (menu.getItemInSlot(17) != null) { + ItemStack itemSlot17 = menu.getItemInSlot(17); + if (itemSlot17 != null) { Optional target = getAttachedBlock(bus); - - target.ifPresent(block -> menu.replaceExistingItem(17, CargoUtils.insert(this, inventories, bus.getBlock(), block, false, menu.getItemInSlot(17)))); + target.ifPresent(block -> menu.replaceExistingItem(17, CargoUtils.insert(this, inventories, bus.getBlock(), block, false, itemSlot17, ItemStackWrapper.ofItem(itemSlot17)))); } if (menu.getItemInSlot(17) == null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java index 1227a49bd..4256df16a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java @@ -15,6 +15,7 @@ import java.util.logging.Level; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.inventory.Inventory; @@ -112,7 +113,7 @@ class CargoNetworkTask implements Runnable { return; } - ItemStack stack = slot.getItemStackWrapper(); + ItemStack stack = slot.getItem(); int previousSlot = slot.getInt(); List destinations = outputNodes.get(frequency); @@ -184,7 +185,8 @@ class CargoNetworkTask implements Runnable { Optional target = network.getAttachedBlock(output); if (target.isPresent()) { - item = CargoUtils.insert(network, inventories, output.getBlock(), target.get(), smartFill, item); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(item); + item = CargoUtils.insert(network, inventories, output.getBlock(), target.get(), smartFill, item, wrapper); if (item == null) { break; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index f419254be..a89bb926c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -152,12 +152,13 @@ final class CargoUtils { return null; } - ItemStackWrapper wrapper = ItemStackWrapper.ofItem(template); + ItemStackWrapper wrapperTemplate = ItemStackWrapper.ofItem(template); for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) { ItemStack is = menu.getItemInSlot(slot); + ItemStackWrapper wrapperItemInSlot = ItemStackWrapper.ofItem(is); - if (SlimefunUtils.isItemSimilar(is, wrapper, true) && matchesFilter(network, node, is)) { + if (SlimefunUtils.isItemSimilar(wrapperItemInSlot, wrapperTemplate, true) && matchesFilter(network, node, wrapperItemInSlot)) { if (is.getAmount() > template.getAmount()) { is.setAmount(is.getAmount() - template.getAmount()); menu.replaceExistingItem(slot, is); @@ -184,8 +185,9 @@ final class CargoUtils { for (int slot = minSlot; slot < maxSlot; slot++) { // Changes to these ItemStacks are synchronized with the Item in the Inventory ItemStack itemInSlot = contents[slot]; + ItemStackWrapper wrapperInSlot = ItemStackWrapper.ofItem(itemInSlot); - if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false) && matchesFilter(network, node, itemInSlot)) { + if (SlimefunUtils.isItemSimilar(wrapperInSlot, wrapper, true, false) && matchesFilter(network, node, wrapperInSlot)) { if (itemInSlot.getAmount() > template.getAmount()) { itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount()); return template; @@ -252,7 +254,7 @@ final class CargoUtils { } @Nullable - static ItemStack insert(AbstractItemNetwork network, Map inventories, Block node, Block target, boolean smartFill, ItemStack stack) { + static ItemStack insert(AbstractItemNetwork network, Map inventories, Block node, Block target, boolean smartFill, ItemStack stack, ItemStackWrapper wrapper) { if (!matchesFilter(network, node, stack)) { return stack; } @@ -264,7 +266,7 @@ final class CargoUtils { Inventory inventory = inventories.get(target.getLocation()); if (inventory != null) { - return insertIntoVanillaInventory(stack, smartFill, inventory); + return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory); } BlockState state = PaperLib.getBlockState(target, false).getState(); @@ -272,15 +274,13 @@ final class CargoUtils { if (state instanceof InventoryHolder) { inventory = ((InventoryHolder) state).getInventory(); inventories.put(target.getLocation(), inventory); - return insertIntoVanillaInventory(stack, smartFill, inventory); + return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory); } } return stack; } - ItemStackWrapper wrapper = ItemStackWrapper.ofItem(stack); - for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.INSERT, wrapper)) { ItemStack itemInSlot = menu.getItemInSlot(slot); @@ -320,7 +320,7 @@ final class CargoUtils { } @Nullable - private static ItemStack insertIntoVanillaInventory(@Nonnull ItemStack stack, boolean smartFill, @Nonnull Inventory inv) { + private static ItemStack insertIntoVanillaInventory(@Nonnull ItemStack stack, @Nonnull ItemStackWrapper wrapper, boolean smartFill, @Nonnull Inventory inv) { /* * If the Inventory does not accept this Item Type, bounce the item back. * Example: Shulker boxes within shulker boxes (fixes #2662) @@ -334,8 +334,6 @@ final class CargoUtils { int minSlot = range[0]; int maxSlot = range[1]; - ItemStackWrapper wrapper = ItemStackWrapper.ofItem(stack); - for (int slot = minSlot; slot < maxSlot; slot++) { // Changes to this ItemStack are synchronized with the Item in the Inventory ItemStack itemInSlot = contents[slot];