aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjarne Koll <[email protected]>2024-06-15 19:08:11 +0200
committerBjarne Koll <[email protected]>2024-06-15 19:08:11 +0200
commit04dad71064013b47a0c47e269ae41b4fea4f8336 (patch)
tree6311ede30aca2afbccb9301342a60986d7e558a2
parenta835ad1076a4fccbc168554b9bf20e7c0fead761 (diff)
downloadPaper-04dad71064013b47a0c47e269ae41b4fea4f8336.tar.gz
Paper-04dad71064013b47a0c47e269ae41b4fea4f8336.zip
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.
-rw-r--r--patches/server/0685-Implement-enchantWithLevels-API.patch15
1 files 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()
-+ .<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);
+ }