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

Add even more Enchantment API (#11115)

Dieser Commit ist enthalten in:
Jake Potrebic 2024-08-17 13:58:36 -07:00 committet von GitHub
Ursprung 66a97cc929
Commit 2e82fd2d2c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
5 geänderte Dateien mit 160 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -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<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 ac0371285370594d4de1554871b19bbcd2311730..da5d153a3e55a38b767359564001ad8663f9730b 100644
--- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java

Datei anzeigen

@ -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 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<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

Datei anzeigen

@ -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<net.mine
public net.kyori.adventure.text.Component displayName(int level) {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
@@ -152,6 +152,17 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
}
+
+ @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 d20fdd4f06faa09c7d9f9e04f379cf0fa68db9bb..66d773cadb74f9176e6cf68a565568034f52ec63 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java

Datei anzeigen

@ -10,7 +10,7 @@ Co-authored-by: Luis <luisc99@icloud.com>
Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
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<net.mine
@@ -148,7 +149,7 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
// Paper start
@Override
public net.kyori.adventure.text.Component displayName(int level) {
- 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();
+ }
+
@@ -159,10 +160,62 @@ 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 fc6606e1bf2e2c35cb6c84af78859c3441775907..edf4df4d13dc814e98b897a3f8a5fd47
+ 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());

Datei anzeigen

@ -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 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<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());