3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00

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.
Dieser Commit ist enthalten in:
Bjarne Koll 2024-06-15 19:08:11 +02:00
Ursprung a835ad1076
Commit 04dad71064
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 27F6CCCF55D2EE62

Datei anzeigen

@ -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);
+ }