From b9aea8b2032f0842645b9434c3ca5a68a80aefc6 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 28 Jun 2024 08:28:17 +0800 Subject: [PATCH 1/7] Update SlimefunUtils.java --- .../slimefun4/utils/SlimefunUtils.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 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 5fc3bda47f..413eece022 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -388,14 +388,15 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac * 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); + Debug.log(TestCase.CARGO_INPUT_TESTING, " sfitem is ItemStackWrapper - possible SF Item: {}", item); - ItemMeta possibleSfItemMeta = sfitem.getItemMeta(); - String id = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); - String possibleItemId = Slimefun.getItemDataService().getItemData(possibleSfItemMeta).orElse(null); + ItemMeta sfItemMeta = sfitem.getItemMeta(); + String possibleItemId = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); + String sfItemId = Slimefun.getItemDataService() + .getItemData(sfItemMeta).get(); // Prioritize SlimefunItem id comparison over ItemMeta comparison - if (id != null && id.equals(possibleItemId)) { - Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); + if (possibleItemId != null && possibleItemId.equals(sfItemId)) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " SlimefunItem IDs matched!"); /* * PR #3417 @@ -403,15 +404,13 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac * 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); + Optional optionalDistinctive = getDistinctiveItem(possibleItemId); if (optionalDistinctive.isPresent()) { - return optionalDistinctive.get().canStack(possibleSfItemMeta, itemMeta); + return optionalDistinctive.get().canStack(sfItemMeta, 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); } + return false; } else if (sfitem.hasItemMeta()) { ItemMeta sfItemMeta = sfitem.getItemMeta(); Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore); From 4ff4edbb8a2e18cd61a78a228915cc6143492a78 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Tue, 2 Jul 2024 10:49:30 +0800 Subject: [PATCH 2/7] Update SlimefunUtils.java --- .../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 413eece022..e64d46a9ba 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -409,8 +409,9 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return optionalDistinctive.get().canStack(sfItemMeta, itemMeta); } return true; + } else { + return false; } - return false; } else if (sfitem.hasItemMeta()) { ItemMeta sfItemMeta = sfitem.getItemMeta(); Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore); From e3adbb228ecd1a520d242849ede75a1f9060ad9d Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Wed, 10 Jul 2024 15:06:39 +0800 Subject: [PATCH 3/7] Make LimitedUseItem be DistinctiveItem LimitedUseItem has 'uses left' attr --- .../implementation/items/LimitedUseItem.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index c4377d4585..a2bc748d37 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -38,7 +38,7 @@ * * @see StormStaff */ -public abstract class LimitedUseItem extends SimpleSlimefunItem { +public abstract class LimitedUseItem extends SimpleSlimefunItem implements DistinctiveItem { private final NamespacedKey defaultUsageKey; private int maxUseCount = -1; @@ -149,4 +149,13 @@ private void updateItemLore(ItemStack item, ItemMeta meta, int usesLeft) { } } + @Override + public boolean canStack(ItemMeta itemMetaOne, ItemMeta itemMetaTwo) { + NamespacedKey key = getStorageKey(); + PersistentDataContainer pdc1 = itemMetaOne.getPersistentDataContainer(); + int usesLeft1 = pdc1.getOrDefault(key, PersistentDataType.INTEGER, getMaxUseCount()); + PersistentDataContainer pdc2 = itemMetaTwo.getPersistentDataContainer(); + int usesLeft2 = pdc2.getOrDefault(key, PersistentDataType.INTEGER, getMaxUseCount()); + return usesLeft1 == usesLeft2; + } } From 1a7096d4427a4641420bf0a2009e1d3ddb1865f1 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 19:11:48 +0800 Subject: [PATCH 4/7] Update LimitedUseItem.java --- .../slimefun4/implementation/items/LimitedUseItem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index a2bc748d37..e037c38ee6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -20,6 +20,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.attributes.DistinctiveItem; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; From d277b24c65cd455e17761c7309473698227ca15e Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Sun, 28 Jul 2024 18:19:08 +0800 Subject: [PATCH 5/7] Update LimitedUseItem.java --- .../slimefun4/implementation/items/LimitedUseItem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index e037c38ee6..18f8b8f38e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -152,6 +152,9 @@ private void updateItemLore(ItemStack item, ItemMeta meta, int usesLeft) { @Override public boolean canStack(ItemMeta itemMetaOne, ItemMeta itemMetaTwo) { + if (Slimefun.getItemDataService().getItemData(itemMetaOne) != Slimefun.getItemDataService().getItemData(itemMetaTwo)) { + return false; + } NamespacedKey key = getStorageKey(); PersistentDataContainer pdc1 = itemMetaOne.getPersistentDataContainer(); int usesLeft1 = pdc1.getOrDefault(key, PersistentDataType.INTEGER, getMaxUseCount()); From faab6dc41711f61f3ed6cd247a0bff8641784e57 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Mon, 29 Jul 2024 00:32:59 +0800 Subject: [PATCH 6/7] Update LimitedUseItem.java --- .../implementation/items/LimitedUseItem.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index 18f8b8f38e..2ee5fac640 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -16,6 +16,7 @@ import org.bukkit.persistence.PersistentDataType; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -67,7 +68,7 @@ public final int getMaxUseCount() { * * @param count * The maximum number of times this item can be used. - * + * * @return The {@link LimitedUseItem} for chaining of setters */ public final @Nonnull LimitedUseItem setMaxUseCount(int count) { @@ -152,14 +153,13 @@ private void updateItemLore(ItemStack item, ItemMeta meta, int usesLeft) { @Override public boolean canStack(ItemMeta itemMetaOne, ItemMeta itemMetaTwo) { - if (Slimefun.getItemDataService().getItemData(itemMetaOne) != Slimefun.getItemDataService().getItemData(itemMetaTwo)) { + if (!Slimefun.getItemDataService().getItemData(itemMetaOne).equals(Slimefun.getItemDataService().getItemData(itemMetaTwo))) { return false; } + NamespacedKey key = getStorageKey(); - PersistentDataContainer pdc1 = itemMetaOne.getPersistentDataContainer(); - int usesLeft1 = pdc1.getOrDefault(key, PersistentDataType.INTEGER, getMaxUseCount()); - PersistentDataContainer pdc2 = itemMetaTwo.getPersistentDataContainer(); - int usesLeft2 = pdc2.getOrDefault(key, PersistentDataType.INTEGER, getMaxUseCount()); - return usesLeft1 == usesLeft2; + int usesLeft1 = PersistentDataAPI.getInt(itemMetaOne, key); + int usesLeft2 = PersistentDataAPI.getInt(itemMetaTwo, key); + return usesLeft1 != -1 && usesLeft1 == usesLeft2; } } From e2974c09e52f76f4a21a92dd17105243ef8cdc62 Mon Sep 17 00:00:00 2001 From: qscbm187531 <1309635304@qq.com> Date: Mon, 29 Jul 2024 00:46:08 +0800 Subject: [PATCH 7/7] Update LimitedUseItem.java --- .../slimefun4/implementation/items/LimitedUseItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index 2ee5fac640..5d83f5bcf1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -160,6 +160,6 @@ public boolean canStack(ItemMeta itemMetaOne, ItemMeta itemMetaTwo) { NamespacedKey key = getStorageKey(); int usesLeft1 = PersistentDataAPI.getInt(itemMetaOne, key); int usesLeft2 = PersistentDataAPI.getInt(itemMetaTwo, key); - return usesLeft1 != -1 && usesLeft1 == usesLeft2; + return usesLeft1 == usesLeft2; } }