mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Add even more Enchantment API (#11115)
This commit is contained in:
parent
0a041c951d
commit
0df31bdeb3
5 changed files with 154 additions and 26 deletions
69
patches/api/Add-even-more-Enchantment-API.patch
Normal file
69
patches/api/Add-even-more-Enchantment-API.patch
Normal file
|
@ -0,0 +1,69 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
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<org.bukkit.inventory.EquipmentSlotGroup> 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<org.bukkit.inventory.ItemType> getSupportedItems();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides the registry key set referencing the item types this enchantment can be applied to when
|
||||
+ * enchanting in an enchantment table.
|
||||
+ * <p>
|
||||
+ * 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<org.bukkit.inventory.ItemType> getPrimaryItems();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides the weight of this enchantment used by the weighted random when selecting enchantments.
|
||||
+ *
|
||||
+ * @return the weight value.
|
||||
+ * @see <a href="https://minecraft.wiki/w/Enchanting">https://minecraft.wiki/w/Enchanting</a> for examplary weights.
|
||||
+ */
|
||||
+ public abstract int getWeight();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides the registry key set of enchantments that this enchantment is exclusive with.
|
||||
+ * <p>
|
||||
+ * 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<Enchantment> getExclusiveWith();
|
||||
+ // Paper end - even more Enchantment API
|
||||
+
|
||||
// Paper start - mark translation key as deprecated
|
||||
/**
|
||||
* @deprecated this method assumes that the enchantments description
|
|
@ -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<org.bukkit.inventory.EquipmentSlotGroup> 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
|
||||
|
|
47
patches/server/Add-even-more-Enchantment-API.patch
Normal file
47
patches/server/Add-even-more-Enchantment-API.patch
Normal file
|
@ -0,0 +1,47 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
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<net.mine
|
||||
}
|
||||
// Paper end - more Enchantment API
|
||||
|
||||
+ // Paper start - even more Enchantment API
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.Component description() {
|
||||
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.value().description());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.registry.set.RegistryKeySet<org.bukkit.inventory.ItemType> 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<org.bukkit.inventory.ItemType> getPrimaryItems() {
|
||||
+ final java.util.Optional<net.minecraft.core.HolderSet<net.minecraft.world.item.Item>> 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<org.bukkit.enchantments.Enchantment> 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());
|
|
@ -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<net.mine
|
||||
public net.kyori.adventure.text.Component displayName(int level) {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public String translationKey() {
|
||||
+ return this.handle.getDescriptionId();
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
+ // Paper start - add translationKey methods
|
||||
+ @Override
|
||||
+ public String translationKey() {
|
||||
+ if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
|
||||
+ throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
+ }
|
||||
+ return translatableContents.getKey();
|
||||
+
|
||||
+ }
|
||||
+ // Paper end - add translationKey methods
|
||||
+
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location());
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
||||
|
|
|
@ -37,16 +37,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
- return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
|
||||
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(net.minecraft.world.item.enchantment.Enchantment.getFullname(this.handle, level));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String translationKey() {
|
||||
- return this.handle.getDescriptionId();
|
||||
+ if (!(this.getHandle().description().getContents() instanceof final TranslatableContents translatableContents)) {
|
||||
+ throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
+ }
|
||||
+ return translatableContents.getKey();
|
||||
+ }
|
||||
+
|
||||
@@ -0,0 +0,0 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
||||
throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
}
|
||||
return translatableContents.getKey();
|
||||
-
|
||||
}
|
||||
// Paper end - add translationKey methods
|
||||
|
||||
+ // Paper start - more Enchantment API
|
||||
+ @Override
|
||||
+ public boolean isTradeable() {
|
||||
+ return this.handle.is(EnchantmentTags.TRADEABLE);
|
||||
|
@ -96,6 +97,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ return this.getHandle().definition().slots().stream()
|
||||
+ .map(org.bukkit.craftbukkit.CraftEquipmentSlot::getSlot)
|
||||
+ .collect(java.util.stream.Collectors.toSet());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ }
|
||||
+ // Paper end - more Enchantment API
|
||||
+
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location());
|
||||
|
|
Loading…
Reference in a new issue