Class EnchantHelper

java.lang.Object
com.teampotato.potacore.item.EnchantHelper

public class EnchantHelper extends Object
Provides utility methods for manipulating enchantments on items and enchanted books.

This class supports removing specific enchantments from both regular items and enchanted books. It handles both Enchantment instances and enchantments identified by ResourceLocation.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    removeEnchantment(@NotNull net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.enchantment.Enchantment enchantment)
    Removes a specific enchantment from an item stack or enchanted book.
    static boolean
    removeEnchantment(net.minecraft.world.item.ItemStack stack, net.minecraft.resources.ResourceLocation enchantment)
    Removes a specific enchantment from an item stack using its registry name.
    static int
    removeEnchantments(net.minecraft.world.item.ItemStack stack, @NotNull Iterable<net.minecraft.world.item.enchantment.Enchantment> enchantments)
    Removes multiple enchantments from an item stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EnchantHelper

      public EnchantHelper()
  • Method Details

    • removeEnchantments

      public static int removeEnchantments(net.minecraft.world.item.ItemStack stack, @NotNull @NotNull Iterable<net.minecraft.world.item.enchantment.Enchantment> enchantments)
      Removes multiple enchantments from an item stack.
      Parameters:
      stack - The item stack to modify
      enchantments - Iterable collection of enchantments to remove
      Returns:
      Number of enchantments successfully removed from the item
      See Also:
    • removeEnchantment

      public static boolean removeEnchantment(net.minecraft.world.item.ItemStack stack, net.minecraft.resources.ResourceLocation enchantment)
      Removes a specific enchantment from an item stack using its registry name.
      Parameters:
      stack - The item stack to modify
      enchantment - Registry name (ResourceLocation) of the enchantment to remove
      Returns:
      true if the enchantment was found and removed, false otherwise
      See Also:
    • removeEnchantment

      public static boolean removeEnchantment(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.enchantment.Enchantment enchantment)
      Removes a specific enchantment from an item stack or enchanted book.

      Handles both regular items (using "Enchantments" tag) and enchanted books (using "StoredEnchantments" tag). If the resulting NBT becomes empty after removal, the entire NBT tag is cleared.

      Parameters:
      stack - The item stack to modify. Must not be empty.
      enchantment - Enchantment to remove. Must not be null.
      Returns:
      true if the enchantment was found and removed, false otherwise