mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 12:42:05 -07:00
Add Enchantment cost API (#9856)
Cost is a property of individual enchantments, and is used by vanilla in combination with environmental aspects like tool enchantability and bookshelf count to determine the final cost of an enchantment as shown in an enchanting table. Having access to the base cost of an enchantment using these vanilla methods can allow plugin developers to determine the "value" of an enchantment, and use it in custom logic where needed. I came across this recently when trying to assign an economic value to enchantments during tool repairing, and noticed these values don't seem to be obtainable under the current API.
This commit is contained in:
@@ -6,6 +6,8 @@ Subject: [PATCH] More Enchantment API
|
||||
== AT ==
|
||||
public net.minecraft.world.item.enchantment.Enchantment slots
|
||||
|
||||
Co-authored-by: Luis <luisc99@icloud.com>
|
||||
|
||||
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
|
||||
@@ -35,6 +37,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMinModifiedCost(int level) {
|
||||
+ return target.getMinCost(level);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMaxModifiedCost(int level) {
|
||||
+ return target.getMaxCost(level);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.enchantments.EnchantmentRarity getRarity() {
|
||||
+ return fromNMSRarity(target.getRarity());
|
||||
+ }
|
||||
|
Reference in New Issue
Block a user