From ae9b8efe221735e332d1adb36fe82b45eaa4aab1 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Mon, 4 Nov 2024 22:18:15 +0100 Subject: [PATCH] Getting started on SlimefunUtils --- .../slimefun4/utils/SlimefunUtils.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 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 a509b207f3..42214c393c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -340,20 +340,24 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return false; } else if (checkAmount && item.getAmount() < sfitem.getAmount()) { return false; - } else if (sfitem instanceof SlimefunItemStack stackOne && item instanceof SlimefunItemStack stackTwo) { - if (stackOne.getItemId().equals(stackTwo.getItemId())) { - /* - * 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 && stackOne instanceof DistinctiveItem distinctive && stackTwo instanceof DistinctiveItem) { - return distinctive.canStack(stackOne.getItemMeta(), stackTwo.getItemMeta()); - } - return true; + } + SlimefunItem sfItemSI = SlimefunItem.getByItem(sfitem); + SlimefunItem itemSI = SlimefunItem.getByItem(item); + + if (sfItemSI != null && itemSI != null) { + if (!sfItemSI.getId().equals(itemSI.getId())) { + return false; } - return false; + /* + * 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 && sfItemSI instanceof DistinctiveItem distinctive && itemSI instanceof DistinctiveItem) { + return distinctive.canStack(item.getItemMeta(), sfitem.getItemMeta()); + } + return true; } else if (item.hasItemMeta()) { Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()"); ItemMeta itemMeta = item.getItemMeta();