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 328126123..f419254be 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,7 +152,7 @@ final class CargoUtils { return null; } - ItemStackWrapper wrapper = new ItemStackWrapper(template); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(template); for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) { ItemStack is = menu.getItemInSlot(slot); @@ -179,7 +179,7 @@ final class CargoUtils { int minSlot = range[0]; int maxSlot = range[1]; - ItemStackWrapper wrapper = new ItemStackWrapper(template); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(template); for (int slot = minSlot; slot < maxSlot; slot++) { // Changes to these ItemStacks are synchronized with the Item in the Inventory @@ -279,7 +279,7 @@ final class CargoUtils { return stack; } - ItemStackWrapper wrapper = new ItemStackWrapper(stack); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(stack); for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.INSERT, wrapper)) { ItemStack itemInSlot = menu.getItemInSlot(slot); @@ -334,7 +334,7 @@ final class CargoUtils { int minSlot = range[0]; int maxSlot = range[1]; - ItemStackWrapper wrapper = new ItemStackWrapper(stack); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(stack); for (int slot = minSlot; slot < maxSlot; slot++) { // Changes to this ItemStack are synchronized with the Item in the Inventory @@ -358,7 +358,7 @@ final class CargoUtils { if (amount > maxStackSize) { stack.setAmount(amount - maxStackSize); - itemInSlot.setAmount(Math.min(amount, maxStackSize)); + itemInSlot.setAmount(maxStackSize); return stack; } else { itemInSlot.setAmount(Math.min(amount, maxStackSize)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemFilter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemFilter.java index 713b3395e..6c92d8f9b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemFilter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemFilter.java @@ -189,7 +189,7 @@ class ItemFilter implements Predicate { * If there is more than one potential match, create a wrapper to save * performance on the ItemMeta otherwise just use the item directly. */ - ItemStack subject = potentialMatches == 1 ? item : new ItemStackWrapper(item); + ItemStack subject = potentialMatches == 1 ? item : ItemStackWrapper.ofItem(item); /* * If there is only one match, we won't need to create a Wrapper diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java index 395f6856e..b76896e89 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java @@ -25,7 +25,7 @@ class ItemStackAndInteger { public ItemStackWrapper getItemStackWrapper() { if (wrapper == null && item != null) { - wrapper = new ItemStackWrapper(item); + wrapper = ItemStackWrapper.ofItem(item); } return wrapper; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java index 54c693867..c6eee797c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java @@ -46,6 +46,13 @@ public final class ItemStackWrapper extends ItemStack { this(new ItemStack(material)); } + public static @Nonnull ItemStackWrapper ofItem(@Nonnull ItemStack itemStack) { + if (itemStack instanceof ItemStackWrapper) { + return (ItemStackWrapper) itemStack; + } + return new ItemStackWrapper(itemStack); + } + @Override public boolean hasItemMeta() { return hasItemMeta;