From 04dad71064013b47a0c47e269ae41b4fea4f8336 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Sat, 15 Jun 2024 19:08:11 +0200 Subject: [PATCH] Improve enchantWithLevels logic Previously would stream and optionally filter out all entries in the enchantment registry. Moves it to using the empty optional if treasure is allowed, leaving the logic to EnchantmentHelper. --- .../0685-Implement-enchantWithLevels-API.patch | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/patches/server/0685-Implement-enchantWithLevels-API.patch b/patches/server/0685-Implement-enchantWithLevels-API.patch index e228c3dfc4..7bf61f04ba 100644 --- a/patches/server/0685-Implement-enchantWithLevels-API.patch +++ b/patches/server/0685-Implement-enchantWithLevels-API.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Implement enchantWithLevels API diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java -index 803a19063c03627dbea79cb1c395ae35aaef2834..aeb72f7c1bef0407eb00f1116948a0d96ff2ea7b 100644 +index 803a19063c03627dbea79cb1c395ae35aaef2834..317af98f8bd166a5a534f74e6ba177be9afb6a8f 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java -@@ -302,4 +302,29 @@ public final class CraftItemFactory implements ItemFactory { +@@ -302,4 +302,34 @@ public final class CraftItemFactory implements ItemFactory { return eggItem == null ? null : new net.minecraft.world.item.ItemStack(eggItem).asBukkitMirror(); } // Paper end - old getSpawnEgg API @@ -30,9 +30,14 @@ index 803a19063c03627dbea79cb1c395ae35aaef2834..aeb72f7c1bef0407eb00f1116948a0d9 + new org.bukkit.craftbukkit.util.RandomSourceWrapper(random), + internalStack, + levels, -+ enchantments.holders() -+ .>map(r -> r) -+ .filter(r -> allowTreasure || !r.is(EnchantmentTags.TREASURE)) ++ registryAccess, ++ allowTreasure ++ ? Optional.empty() ++ // While IN_ENCHANTING_TABLE is not logically the same as all but TREASURE, the tag is defined as ++ // NON_TREASURE, which does contain all enchantments not in the treasure tag. ++ // Additionally, the allowTreasure boolean is more intended to configure this method to behave like ++ // an enchanting table. ++ : registryAccess.registryOrThrow(Registries.ENCHANTMENT).getTag(EnchantmentTags.IN_ENCHANTING_TABLE) + ); + return CraftItemStack.asCraftMirror(enchanted); + }