From cc40fd75d04a9ed085336eb6d1961b19caa26e51 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 9 Nov 2023 06:30:10 +1100 Subject: [PATCH] SPIGOT-7514, #929: Add "Enchantment Roll" API to enchant items according to Minecraft mechanics By: Miles Holder --- .../org/bukkit/inventory/ItemFactory.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/inventory/ItemFactory.java b/paper-api/src/main/java/org/bukkit/inventory/ItemFactory.java index 502a1fd398..e606f63a28 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemFactory.java +++ b/paper-api/src/main/java/org/bukkit/inventory/ItemFactory.java @@ -3,7 +3,9 @@ package org.bukkit.inventory; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -172,4 +174,47 @@ public interface ItemFactory { */ @Nullable Material getSpawnEgg(@NotNull EntityType type); + + /** + * Enchants the given item at the provided level. + *
+ * If an item that is air is passed through an error is thrown. + * + * @param entity the entity to use as a source of randomness + * @param item the item to enchant + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allows treasure enchants, e.g. mending, if true. + * @return the modified ItemStack, or a copy if the ItemStack cannot be enchanted directly + */ + @NotNull + ItemStack enchantItem(@NotNull final Entity entity, @NotNull final ItemStack item, final int level, final boolean allowTreasures); + + /** + * Enchants the given item at the provided level. + *
+ * If an item that is air is passed through an error is thrown. + * + * @param world the world to use as a source of randomness + * @param item the item to enchant + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allow the treasure enchants, e.g. mending, if true. + * @return the modified ItemStack, or a copy if the ItemStack cannot be + * enchanted directly + */ + @NotNull + ItemStack enchantItem(@NotNull final World world, @NotNull final ItemStack item, final int level, final boolean allowTreasures); + + /** + * Enchants the given item at the provided level. + *
+ * If an item that is air is passed through an error is thrown. + * + * @param item the item to enchant + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allow treasure enchantments, e.g. mending, if true. + * @return the modified ItemStack, or a copy if the ItemStack cannot be + * enchanted directly + */ + @NotNull + ItemStack enchantItem(@NotNull final ItemStack item, final int level, final boolean allowTreasures); }