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.
This commit is contained in:
Bjarne Koll 2024-06-15 19:08:11 +02:00
parent 967ee0c7b1
commit 128085ba3e

View File

@ -30,9 +30,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ new org.bukkit.craftbukkit.util.RandomSourceWrapper(random),
+ internalStack,
+ levels,
+ enchantments.holders()
+ .<net.minecraft.core.Holder<Enchantment>>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);
+ }