Add enchantWithLevels with enchantment registry set

This commit is contained in:
masmc05 2024-09-25 16:26:04 +03:00
parent 4fb38d1c36
commit 4a86a6e4ee
2 changed files with 34 additions and 0 deletions

View File

@ -338,4 +338,21 @@ public interface ItemFactory {
*/ */
@NotNull ItemStack enchantWithLevels(@NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, boolean allowTreasure, @NotNull java.util.Random random); @NotNull ItemStack enchantWithLevels(@NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, boolean allowTreasure, @NotNull java.util.Random random);
// Paper end - enchantWithLevels API // Paper end - enchantWithLevels API
// Paper start - enchantWithLevels with tag specification
/**
* Randomly enchants a copy of the provided {@link ItemStack} using the given experience levels.
*
* <p>If the provided ItemStack is already enchanted, the existing enchants will be removed before enchanting.</p>
*
* <p>Levels must be in range {@code [1, 30]}.</p>
*
* @param itemStack ItemStack to enchant
* @param levels levels to use for enchanting
* @param keySet registry key set defining the set of possible enchantments, e.g. {@link io.papermc.paper.registry.keys.tags.EnchantmentTagKeys#IN_ENCHANTING_TABLE}.
* @param random {@link java.util.Random} instance to use for enchanting
* @return enchanted copy of the provided ItemStack
* @throws IllegalArgumentException on bad arguments
*/
@NotNull ItemStack enchantWithLevels(@NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, @NotNull io.papermc.paper.registry.set.RegistryKeySet<@NotNull Enchantment> keySet, @NotNull java.util.Random random);
// Paper end - enchantWithLevels with tag specification
} }

View File

@ -678,6 +678,23 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
return Bukkit.getServer().getItemFactory().enchantWithLevels(this, levels, allowTreasure, random); return Bukkit.getServer().getItemFactory().enchantWithLevels(this, levels, allowTreasure, random);
} }
/**
* Randomly enchants a copy of this {@link ItemStack} using the given experience levels.
*
* <p>If the provided ItemStack is already enchanted, the existing enchants will be removed before enchanting.</p>
*
* <p>Levels must be in range {@code [1, 30]}.</p>
*
* @param levels levels to use for enchanting
* @param keySet registry key set defining the set of possible enchantments, e.g. {@link io.papermc.paper.registry.keys.tags.EnchantmentTagKeys#IN_ENCHANTING_TABLE}.
* @param random {@link java.util.Random} instance to use for enchanting
* @return enchanted copy of the provided ItemStack
* @throws IllegalArgumentException on bad arguments
*/
public @NotNull ItemStack enchantWithLevels(final @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, final @NotNull io.papermc.paper.registry.set.RegistryKeySet<@NotNull Enchantment> keySet, final @NotNull java.util.Random random) {
return Bukkit.getItemFactory().enchantWithLevels(this, levels, keySet, random);
}
@NotNull @NotNull
@Override @Override
public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final @NotNull java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) { public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final @NotNull java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {