From 0df31bdeb3b6942a590699115827199909c2699a Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 17 Aug 2024 13:58:36 -0700 Subject: [PATCH] Add even more Enchantment API (#11115) --- .../api/Add-even-more-Enchantment-API.patch | 69 +++++++++++++++++++ patches/api/More-Enchantment-API.patch | 16 +++-- .../Add-even-more-Enchantment-API.patch | 47 +++++++++++++ .../Add-methods-to-get-translation-keys.patch | 20 ++++-- patches/server/More-Enchantment-API.patch | 28 ++++---- 5 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 patches/api/Add-even-more-Enchantment-API.patch create mode 100644 patches/server/Add-even-more-Enchantment-API.patch diff --git a/patches/api/Add-even-more-Enchantment-API.patch b/patches/api/Add-even-more-Enchantment-API.patch new file mode 100644 index 0000000000..90b448d058 --- /dev/null +++ b/patches/api/Add-even-more-Enchantment-API.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Fri, 19 Jul 2024 08:43:01 -0700 +Subject: [PATCH] Add even more Enchantment API + +In a separate patch because it uses RegistryKeySet which +is after the previous "more enchant api" patch. + +diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/enchantments/Enchantment.java ++++ b/src/main/java/org/bukkit/enchantments/Enchantment.java +@@ -0,0 +0,0 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve + public abstract java.util.Set getActiveSlotGroups(); + // Paper end - more Enchantment API + ++ // Paper start - even more Enchantment API ++ /** ++ * Provides the description of this enchantment entry as displayed to the client, e.g. "Sharpness" for the sharpness ++ * enchantment. ++ * ++ * @return the description component. ++ */ ++ public abstract net.kyori.adventure.text.@NotNull Component description(); ++ ++ /** ++ * Provides the registry key set referencing the items this enchantment is supported on. ++ * ++ * @return the registry key set. ++ */ ++ @org.jetbrains.annotations.ApiStatus.Experimental ++ public abstract io.papermc.paper.registry.set.@NotNull RegistryKeySet getSupportedItems(); ++ ++ /** ++ * Provides the registry key set referencing the item types this enchantment can be applied to when ++ * enchanting in an enchantment table. ++ *

++ * If this value is {@code null}, {@link #getSupportedItems()} will be sourced instead in the context of an enchantment table. ++ * Additionally, the tag {@link io.papermc.paper.registry.keys.tags.EnchantmentTagKeys#IN_ENCHANTING_TABLE} defines ++ * which enchantments can even show up in an enchantment table. ++ * ++ * @return the registry key set. ++ */ ++ @org.jetbrains.annotations.ApiStatus.Experimental ++ public abstract io.papermc.paper.registry.set.@Nullable RegistryKeySet getPrimaryItems(); ++ ++ /** ++ * Provides the weight of this enchantment used by the weighted random when selecting enchantments. ++ * ++ * @return the weight value. ++ * @see https://minecraft.wiki/w/Enchanting for examplary weights. ++ */ ++ public abstract int getWeight(); ++ ++ /** ++ * Provides the registry key set of enchantments that this enchantment is exclusive with. ++ *

++ * Exclusive enchantments prohibit the application of this enchantment to an item if they are already present on ++ * said item. ++ * ++ * @return a registry set of enchantments exclusive to this one. ++ */ ++ @org.jetbrains.annotations.ApiStatus.Experimental ++ public abstract io.papermc.paper.registry.set.@NotNull RegistryKeySet getExclusiveWith(); ++ // Paper end - even more Enchantment API ++ + // Paper start - mark translation key as deprecated + /** + * @deprecated this method assumes that the enchantments description diff --git a/patches/api/More-Enchantment-API.patch b/patches/api/More-Enchantment-API.patch index 0461dfeb0c..10f513d329 100644 --- a/patches/api/More-Enchantment-API.patch +++ b/patches/api/More-Enchantment-API.patch @@ -57,10 +57,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 /** @@ -0,0 +0,0 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve - * @return the name of the enchantment with {@code level} applied - */ public abstract net.kyori.adventure.text.@NotNull Component displayName(int level); -+ + // Paper end + ++ // Paper start - more Enchantment API + /** + * Checks if this enchantment can be found in villager trades. + * @@ -129,7 +129,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return the damage increase + * @deprecated Enchantments now have a complex effect systems that cannot be reduced to a simple damage increase. + */ -+ @Contract("-> fail") ++ @Contract("_, _ -> fail") + @Deprecated(forRemoval = true, since = "1.20.5") + public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityCategory entityCategory); + @@ -141,7 +141,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return the damage increase + * @deprecated Enchantments now have a complex effect systems that cannot be reduced to a simple damage increase. + */ -+ @Contract("-> fail") ++ @Contract("_, _ -> fail") + @Deprecated(forRemoval = true, since = "1.21") + public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityType entityType); + @@ -170,9 +170,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + */ + @NotNull + public abstract java.util.Set getActiveSlotGroups(); - // Paper end - ++ // Paper end - more Enchantment API ++ // Paper start - mark translation key as deprecated + /** + * @deprecated this method assumes that the enchantments description diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java diff --git a/patches/server/Add-even-more-Enchantment-API.patch b/patches/server/Add-even-more-Enchantment-API.patch new file mode 100644 index 0000000000..26ed0476e4 --- /dev/null +++ b/patches/server/Add-even-more-Enchantment-API.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Fri, 19 Jul 2024 08:42:45 -0700 +Subject: [PATCH] Add even more Enchantment API + +In a separate patch because RegistryKeySet is used +and the previous "more enchant api" patch is before that. + +diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java ++++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +@@ -0,0 +0,0 @@ public class CraftEnchantment extends Enchantment implements Handleable getSupportedItems() { ++ return io.papermc.paper.registry.set.PaperRegistrySets.convertToApi(io.papermc.paper.registry.RegistryKey.ITEM, this.handle.value().getSupportedItems()); ++ } ++ ++ @Override ++ public io.papermc.paper.registry.set.RegistryKeySet getPrimaryItems() { ++ final java.util.Optional> primaryItems = this.handle.value().definition().primaryItems(); ++ return primaryItems.map(holders -> io.papermc.paper.registry.set.PaperRegistrySets.convertToApi(io.papermc.paper.registry.RegistryKey.ITEM, holders)).orElse(null); ++ } ++ ++ @Override ++ public int getWeight() { ++ return this.handle.value().getWeight(); ++ } ++ ++ @Override ++ public io.papermc.paper.registry.set.RegistryKeySet getExclusiveWith() { ++ return io.papermc.paper.registry.set.PaperRegistrySets.convertToApi(io.papermc.paper.registry.RegistryKey.ENCHANTMENT, this.handle.value().exclusiveSet()); ++ } ++ // Paper end - even more Enchantment API ++ + @Override + public String getTranslationKey() { + return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location()); diff --git a/patches/server/Add-methods-to-get-translation-keys.patch b/patches/server/Add-methods-to-get-translation-keys.patch index 57b325e173..7bfe637393 100644 --- a/patches/server/Add-methods-to-get-translation-keys.patch +++ b/patches/server/Add-methods-to-get-translation-keys.patch @@ -46,17 +46,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -0,0 +0,0 @@ public class CraftEnchantment extends Enchantment implements Handleable