From 128085ba3e1c61ae3c53931ec8deca6b51185d41 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. --- patches/server/Implement-enchantWithLevels-API.patch | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/patches/server/Implement-enchantWithLevels-API.patch b/patches/server/Implement-enchantWithLevels-API.patch index 6407b8e17..e3540018a 100644 --- a/patches/server/Implement-enchantWithLevels-API.patch +++ b/patches/server/Implement-enchantWithLevels-API.patch @@ -30,9 +30,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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); + }