From 2e82fd2d2c1881665e27654977390fa48f5ec346 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) --- patches/api/0273-More-Enchantment-API.patch | 20 +++--- .../0484-Add-even-more-Enchantment-API.patch | 69 +++++++++++++++++++ ...-Add-methods-to-get-translation-keys.patch | 24 ++++--- .../server/0536-More-Enchantment-API.patch | 32 +++++---- .../1048-Add-even-more-Enchantment-API.patch | 47 +++++++++++++ 5 files changed, 160 insertions(+), 32 deletions(-) create mode 100644 patches/api/0484-Add-even-more-Enchantment-API.patch create mode 100644 patches/server/1048-Add-even-more-Enchantment-API.patch diff --git a/patches/api/0273-More-Enchantment-API.patch b/patches/api/0273-More-Enchantment-API.patch index 14f5473ccb..1119346aaa 100644 --- a/patches/api/0273-More-Enchantment-API.patch +++ b/patches/api/0273-More-Enchantment-API.patch @@ -41,7 +41,7 @@ index 0000000000000000000000000000000000000000..aec3b41d7c3388e26fa203e3c062f1e6 + } +} diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java -index daae9bb234d2e10530b2bed35fada98652514e0e..fc30fbffd83285d4ec102a18454ed95289329667 100644 +index daae9bb234d2e10530b2bed35fada98652514e0e..53dbb852d6a34f0814b81852c7f10f55c38299e7 100644 --- a/src/main/java/org/bukkit/enchantments/Enchantment.java +++ b/src/main/java/org/bukkit/enchantments/Enchantment.java @@ -290,11 +290,7 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve @@ -56,11 +56,11 @@ index daae9bb234d2e10530b2bed35fada98652514e0e..fc30fbffd83285d4ec102a18454ed952 public abstract boolean isCursed(); /** -@@ -328,6 +324,116 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve - * @return the name of the enchantment with {@code level} applied - */ +@@ -330,6 +326,118 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve 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 daae9bb234d2e10530b2bed35fada98652514e0e..fc30fbffd83285d4ec102a18454ed952 + * @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 daae9bb234d2e10530b2bed35fada98652514e0e..fc30fbffd83285d4ec102a18454ed952 + * @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 daae9bb234d2e10530b2bed35fada98652514e0e..fc30fbffd83285d4ec102a18454ed952 + */ + @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 ac0371285370594d4de1554871b19bbcd2311730..da5d153a3e55a38b767359564001ad8663f9730b 100644 --- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java diff --git a/patches/api/0484-Add-even-more-Enchantment-API.patch b/patches/api/0484-Add-even-more-Enchantment-API.patch new file mode 100644 index 0000000000..c9813d353e --- /dev/null +++ b/patches/api/0484-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 53dbb852d6a34f0814b81852c7f10f55c38299e7..f38321c437b19125d57d25419e3cb564e3928d89 100644 +--- a/src/main/java/org/bukkit/enchantments/Enchantment.java ++++ b/src/main/java/org/bukkit/enchantments/Enchantment.java +@@ -438,6 +438,56 @@ 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/server/0406-Add-methods-to-get-translation-keys.patch b/patches/server/0406-Add-methods-to-get-translation-keys.patch index e8e4f5ac2d..5b5a9288df 100644 --- a/patches/server/0406-Add-methods-to-get-translation-keys.patch +++ b/patches/server/0406-Add-methods-to-get-translation-keys.patch @@ -42,21 +42,27 @@ index 338a8f4acf413ef24fedab60c19c7a51a0ea19a6..2d8a509446c0ed0d7358f10f67ef29c4 + // Paper end - add Translatable } diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java -index f73017bff613bd62b86c974b29576e241c24c927..fc6606e1bf2e2c35cb6c84af78859c3441775907 100644 +index f73017bff613bd62b86c974b29576e241c24c927..59c9c970b83f62245d860994c4ac0c21dcc15398 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java -@@ -150,6 +150,11 @@ public class CraftEnchantment extends Enchantment implements Handleable Co-authored-by: Janet Blackquill diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java -index fc6606e1bf2e2c35cb6c84af78859c3441775907..edf4df4d13dc814e98b897a3f8a5fd4757284299 100644 +index 59c9c970b83f62245d860994c4ac0c21dcc15398..4221a1e9cba35c8dc58e51e162e7fcbd0e8b31af 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -5,6 +5,7 @@ import java.util.Locale; @@ -30,23 +30,24 @@ index fc6606e1bf2e2c35cb6c84af78859c3441775907..edf4df4d13dc814e98b897a3f8a5fd47 } @Override -@@ -148,12 +149,66 @@ public class CraftEnchantment extends Enchantment implements Handleable +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 4221a1e9cba35c8dc58e51e162e7fcbd0e8b31af..34934f0dbe66ee200cd99c002c53645660041548 100644 +--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java ++++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +@@ -216,6 +216,34 @@ 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());