Class EnchantmentLib

java.lang.Object
johnsmith.enchantingoverhauled.api.lib.EnchantmentLib

public class EnchantmentLib extends Object
Main library for enchantment-related logic in the common module.

Handles power calculation via EnchantmentTheme, enchantment generation filtering, and utilities for manipulating ItemEnchantments components across platforms.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    calculatePower(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, PowerProvider provider)
    Calculates the total enchanting power contributed by a single PowerProvider at the given position, evaluating all of its data-driven PowerBonus rules (such as block state multipliers, conditional property additions, and container inventory item counts).
    static boolean
    countsTowardCap(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    Determines whether the given enchantment contributes toward the configured Config.MAX_ENCHANTMENT_AMOUNT limit.
    static int
    getAgnosticEnchantingPower(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos providerPos)
    Calculates the highest enchanting power provided by a block at a given position, regardless of theme.
    static int
    getCapContributingEnchantmentCount(net.minecraft.world.item.ItemStack stack)
    Counts the number of enchantments on the given ItemStack that contribute toward Config.MAX_ENCHANTMENT_AMOUNT, respecting Config.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNT.
    static net.minecraft.world.item.enchantment.ItemEnchantments
    getEnchantments(net.minecraft.world.item.ItemStack stack)
    Retrieves the appropriate enchantment component (DataComponents.ENCHANTMENTS or DataComponents.STORED_ENCHANTMENTS) from the given ItemStack.
    static boolean
    isCurseConcealed(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment, boolean isStored)
    Evaluates whether a given enchantment should be visually concealed based on whether it is tagged with EnchantmentTags.CURSE, its storage context (applied vs.
    static net.minecraft.world.item.ItemStack
    removeCursesFrom(net.minecraft.world.item.ItemStack target)
    Creates a copy of the target stack with all cursed enchantments (those tagged with EnchantmentTags.CURSE) removed from its minecraft:enchantments or minecraft:stored_enchantments component.

    Methods inherited from class java.lang.Object

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

    • EnchantmentLib

      public EnchantmentLib()
  • Method Details

    • getEnchantments

      public static net.minecraft.world.item.enchantment.ItemEnchantments getEnchantments(net.minecraft.world.item.ItemStack stack)
      Retrieves the appropriate enchantment component (DataComponents.ENCHANTMENTS or DataComponents.STORED_ENCHANTMENTS) from the given ItemStack.
      Parameters:
      stack - The ItemStack to check.
      Returns:
      The ItemEnchantments container, or ItemEnchantments.EMPTY if none is found.
    • getAgnosticEnchantingPower

      public static int getAgnosticEnchantingPower(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos providerPos)
      Calculates the highest enchanting power provided by a block at a given position, regardless of theme.

      If the block at providerPos is a Blocks.STRUCTURE_VOID, it acts as a debug block and grants the maximum configured enchanting power (Config.MAX_ENCHANTING_POWER).

      Parameters:
      level - The Level to check.
      providerPos - The BlockPos of the potential power-providing block.
      Returns:
      The highest integer power level found across all registered themes (0 if none).
    • calculatePower

      public static int calculatePower(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, PowerProvider provider)
      Calculates the total enchanting power contributed by a single PowerProvider at the given position, evaluating all of its data-driven PowerBonus rules (such as block state multipliers, conditional property additions, and container inventory item counts).
      Parameters:
      level - The Level containing the block.
      pos - The BlockPos of the power-providing block.
      state - The BlockState at pos.
      provider - The PowerProvider rule definition to evaluate.
      Returns:
      The total computed integer enchanting power.
    • removeCursesFrom

      public static net.minecraft.world.item.ItemStack removeCursesFrom(net.minecraft.world.item.ItemStack target)
      Creates a copy of the target stack with all cursed enchantments (those tagged with EnchantmentTags.CURSE) removed from its minecraft:enchantments or minecraft:stored_enchantments component.
      Parameters:
      target - The original ItemStack.
      Returns:
      A copy of the ItemStack with all curses removed, or target if unenchanted.
    • countsTowardCap

      public static boolean countsTowardCap(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
      Determines whether the given enchantment contributes toward the configured Config.MAX_ENCHANTMENT_AMOUNT limit.

      Standard (non-cursed) enchantments always count toward the cap. Cursed enchantments (tagged with EnchantmentTags.CURSE) only count toward the cap when Config.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNT is enabled.

      Parameters:
      enchantment - The Holder of the enchantment to evaluate.
      Returns:
      true if the enchantment counts toward the maximum enchantment cap, false otherwise.
    • getCapContributingEnchantmentCount

      public static int getCapContributingEnchantmentCount(net.minecraft.world.item.ItemStack stack)
      Counts the number of enchantments on the given ItemStack that contribute toward Config.MAX_ENCHANTMENT_AMOUNT, respecting Config.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNT.
      Parameters:
      stack - The ItemStack to inspect.
      Returns:
      The number of cap-contributing enchantments present on the stack.
    • isCurseConcealed

      public static boolean isCurseConcealed(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment, boolean isStored)
      Evaluates whether a given enchantment should be visually concealed based on whether it is tagged with EnchantmentTags.CURSE, its storage context (applied vs. stored), and the active Config.CURSE_CONCEALMENT_MODE setting.
      Parameters:
      enchantment - The Holder of the enchantment to check.
      isStored - true if the enchantment resides on a stored enchantment catalyst (DataComponents.STORED_ENCHANTMENTS), false if applied to target equipment.
      Returns:
      true if the enchantment is a curse that should be concealed in the current context, false otherwise.