From 5fd3ea67563b58853a254f384a991a2aae185c60 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Fri, 13 Jun 2025 20:44:28 +0200 Subject: [PATCH 1/6] Fix DistinctiveItem#canStack --- .../io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index ed5bdb9b4d..88ba5972e0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -355,7 +355,7 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac * in which case we want to use the method provided to compare */ if (checkDistinction && sf_sfitem instanceof DistinctiveItem distinctive && sf_item instanceof DistinctiveItem) { - return distinctive.canStack(sf_sfitem.getItem().getItemMeta(), sf_item.getItem().getItemMeta()); + return distinctive.canStack(sfitem.getItemMeta(), item.getItemMeta()); } return true; } else if (item.hasItemMeta()) { From 1c3321ac20c87ed0603d4b95ae1573ae4a0c7e4b Mon Sep 17 00:00:00 2001 From: Intybyte Date: Fri, 13 Jun 2025 20:53:35 +0200 Subject: [PATCH 2/6] Fix other one too --- .../io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 88ba5972e0..2f9f4774cd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -382,7 +382,7 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return id.equals((sf_sfitem.getId())); } - ItemMeta meta = sf_sfitem.getItem().getItemMeta(); + ItemMeta meta = sfitem.getItemMeta(); return equalsItemMeta(itemMeta, meta, checkLore); } else if (sfitem instanceof ItemStackWrapper && sfitem.hasItemMeta()) { Debug.log(TestCase.CARGO_INPUT_TESTING, " is wrapper"); From 8173bdc8eed44a99dd11832694b15c0a71990ad3 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Fri, 13 Jun 2025 20:56:13 +0200 Subject: [PATCH 3/6] Nuke redundant section and apply inversion --- .../slimefun4/utils/SlimefunUtils.java | 122 ++++++++---------- 1 file changed, 55 insertions(+), 67 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 2f9f4774cd..665a0d94f9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -341,90 +341,78 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac } else if (checkAmount && item.getAmount() < sfitem.getAmount()) { return false; } + SlimefunItem sf_sfitem = SlimefunItem.getByItem(sfitem); - SlimefunItem sf_item = SlimefunItem.getByItem(item); - - if (sf_sfitem != null && sf_item != null) { - if (!sf_sfitem.getId().equals(sf_item.getId())) { - return false; + if (!item.hasItemMeta()) { + return !sfitem.hasItemMeta(); + } + + Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()"); + ItemMeta itemMeta = item.getItemMeta(); + + if (sf_sfitem != null) { + String id = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); + + if (id == null) { + ItemMeta meta = sfitem.getItemMeta(); + return equalsItemMeta(itemMeta, meta, checkLore); + } + + if (!checkDistinction) { + return id.equals((sf_sfitem.getId())); } + /* * PR #3417 * * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem} * in which case we want to use the method provided to compare */ - if (checkDistinction && sf_sfitem instanceof DistinctiveItem distinctive && sf_item instanceof DistinctiveItem) { - return distinctive.canStack(sfitem.getItemMeta(), item.getItemMeta()); + Optional optionalDistinctive = getDistinctiveItem(id); + if (optionalDistinctive.isPresent()) { + ItemMeta sfItemMeta = sfitem.getItemMeta(); + return optionalDistinctive.get().canStack(sfItemMeta, itemMeta); } - return true; - } else if (item.hasItemMeta()) { - Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()"); - ItemMeta itemMeta = item.getItemMeta(); - - if (sf_sfitem != null) { - String id = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); - - if (id != null) { - if (checkDistinction) { - /* - * PR #3417 - * - * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem} - * in which case we want to use the method provided to compare - */ - Optional optionalDistinctive = getDistinctiveItem(id); - if (optionalDistinctive.isPresent()) { - ItemMeta sfItemMeta = sfitem.getItemMeta(); - return optionalDistinctive.get().canStack(sfItemMeta, itemMeta); - } - } - return id.equals((sf_sfitem.getId())); - } - ItemMeta meta = sfitem.getItemMeta(); - return equalsItemMeta(itemMeta, meta, checkLore); - } else if (sfitem instanceof ItemStackWrapper && sfitem.hasItemMeta()) { - Debug.log(TestCase.CARGO_INPUT_TESTING, " is wrapper"); + return id.equals((sf_sfitem.getId())); + } else if (sfitem instanceof ItemStackWrapper && sfitem.hasItemMeta()) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " is wrapper"); + /* + * Cargo optimization (PR #3258) + * + * Slimefun items may be ItemStackWrapper's in the context of cargo + * so let's try to do an ID comparison before meta comparison + */ + Debug.log(TestCase.CARGO_INPUT_TESTING, " sfitem is ItemStackWrapper - possible SF Item: {}", sfitem); + + ItemMeta possibleSfItemMeta = sfitem.getItemMeta(); + String id = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); + String possibleItemId = Slimefun.getItemDataService().getItemData(possibleSfItemMeta).orElse(null); + // Prioritize SlimefunItem id comparison over ItemMeta comparison + if (id != null && id.equals(possibleItemId)) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); + /* - * Cargo optimization (PR #3258) + * PR #3417 * - * Slimefun items may be ItemStackWrapper's in the context of cargo - * so let's try to do an ID comparison before meta comparison + * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem} + * in which case we want to use the method provided to compare */ - Debug.log(TestCase.CARGO_INPUT_TESTING, " sfitem is ItemStackWrapper - possible SF Item: {}", sfitem); - - ItemMeta possibleSfItemMeta = sfitem.getItemMeta(); - String id = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); - String possibleItemId = Slimefun.getItemDataService().getItemData(possibleSfItemMeta).orElse(null); - // Prioritize SlimefunItem id comparison over ItemMeta comparison - if (id != null && id.equals(possibleItemId)) { - Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); - - /* - * PR #3417 - * - * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem} - * in which case we want to use the method provided to compare - */ - Optional optionalDistinctive = getDistinctiveItem(id); - if (optionalDistinctive.isPresent()) { - return optionalDistinctive.get().canStack(possibleSfItemMeta, itemMeta); - } - return true; - } else { - Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore); - return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore); + Optional optionalDistinctive = getDistinctiveItem(id); + if (optionalDistinctive.isPresent()) { + return optionalDistinctive.get().canStack(possibleSfItemMeta, itemMeta); } - } else if (sfitem.hasItemMeta()) { - ItemMeta sfItemMeta = sfitem.getItemMeta(); - Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore); - return equalsItemMeta(itemMeta, sfItemMeta, checkLore); + return true; } else { - return false; + Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore); + return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore); } + } else if (sfitem.hasItemMeta()) { + ItemMeta sfItemMeta = sfitem.getItemMeta(); + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore); + return equalsItemMeta(itemMeta, sfItemMeta, checkLore); } else { - return !sfitem.hasItemMeta(); + return false; } } From 748349542849575726d34d0072e29bc5a692471f Mon Sep 17 00:00:00 2001 From: Intybyte Date: Fri, 13 Jun 2025 21:02:44 +0200 Subject: [PATCH 4/6] Move stuff --- .../github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 665a0d94f9..49f5a5f9da 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -342,12 +342,13 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return false; } - SlimefunItem sf_sfitem = SlimefunItem.getByItem(sfitem); if (!item.hasItemMeta()) { return !sfitem.hasItemMeta(); } Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()"); + + SlimefunItem sf_sfitem = SlimefunItem.getByItem(sfitem); ItemMeta itemMeta = item.getItemMeta(); if (sf_sfitem != null) { From 9fcff9cea27aa89be474e5f3e4d42a3666cd91f1 Mon Sep 17 00:00:00 2001 From: Vaan1310 <61906290+Intybyte@users.noreply.github.com> Date: Fri, 13 Jun 2025 21:04:33 +0200 Subject: [PATCH 5/6] Update src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java Co-authored-by: ybw0014 --- .../io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 49f5a5f9da..4d9c314a3c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -360,7 +360,7 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac } if (!checkDistinction) { - return id.equals((sf_sfitem.getId())); + return id.equals(sf_sfitem.getId()); } /* From 1b0f2739149b76ba8d64afe1021447453ed8f9a2 Mon Sep 17 00:00:00 2001 From: Vaan1310 <61906290+Intybyte@users.noreply.github.com> Date: Fri, 13 Jun 2025 21:04:45 +0200 Subject: [PATCH 6/6] Update src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java Co-authored-by: ybw0014 --- .../io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 4d9c314a3c..3b4f4064e4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -375,7 +375,7 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return optionalDistinctive.get().canStack(sfItemMeta, itemMeta); } - return id.equals((sf_sfitem.getId())); + return id.equals(sf_sfitem.getId()); } else if (sfitem instanceof ItemStackWrapper && sfitem.hasItemMeta()) { Debug.log(TestCase.CARGO_INPUT_TESTING, " is wrapper"); /*