Class EnchantmentLib
java.lang.Object
johnsmith.enchantingoverhauled.api.lib.EnchantmentLib
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculatePower(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 singlePowerProviderat the given position, evaluating all of its data-drivenPowerBonusrules (such as block state multipliers, conditional property additions, and container inventory item counts).static booleancountsTowardCap(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment) Determines whether the given enchantment contributes toward the configuredConfig.MAX_ENCHANTMENT_AMOUNTlimit.static intgetAgnosticEnchantingPower(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 intgetCapContributingEnchantmentCount(net.minecraft.world.item.ItemStack stack) Counts the number of enchantments on the givenItemStackthat contribute towardConfig.MAX_ENCHANTMENT_AMOUNT, respectingConfig.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNT.static net.minecraft.world.item.enchantment.ItemEnchantmentsgetEnchantments(net.minecraft.world.item.ItemStack stack) Retrieves the appropriate enchantment component (DataComponents.ENCHANTMENTSorDataComponents.STORED_ENCHANTMENTS) from the givenItemStack.static booleanisCurseConcealed(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 withEnchantmentTags.CURSE, its storage context (applied vs.static net.minecraft.world.item.ItemStackremoveCursesFrom(net.minecraft.world.item.ItemStack target) Creates a copy of the target stack with all cursed enchantments (those tagged withEnchantmentTags.CURSE) removed from itsminecraft:enchantmentsorminecraft:stored_enchantmentscomponent.
-
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.ENCHANTMENTSorDataComponents.STORED_ENCHANTMENTS) from the givenItemStack.- Parameters:
stack- TheItemStackto check.- Returns:
- The
ItemEnchantmentscontainer, orItemEnchantments.EMPTYif 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
providerPosis aBlocks.STRUCTURE_VOID, it acts as a debug block and grants the maximum configured enchanting power (Config.MAX_ENCHANTING_POWER).- Parameters:
level- TheLevelto check.providerPos- TheBlockPosof the potential power-providing block.- Returns:
- The highest integer power level found across all registered themes (
0if 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 singlePowerProviderat the given position, evaluating all of its data-drivenPowerBonusrules (such as block state multipliers, conditional property additions, and container inventory item counts).- Parameters:
level- TheLevelcontaining the block.pos- TheBlockPosof the power-providing block.state- TheBlockStateatpos.provider- ThePowerProviderrule 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 withEnchantmentTags.CURSE) removed from itsminecraft:enchantmentsorminecraft:stored_enchantmentscomponent.- Parameters:
target- The originalItemStack.- Returns:
- A copy of the
ItemStackwith all curses removed, ortargetif 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 configuredConfig.MAX_ENCHANTMENT_AMOUNTlimit.Standard (non-cursed) enchantments always count toward the cap. Cursed enchantments (tagged with
EnchantmentTags.CURSE) only count toward the cap whenConfig.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNTis enabled.- Parameters:
enchantment- TheHolderof the enchantment to evaluate.- Returns:
trueif the enchantment counts toward the maximum enchantment cap,falseotherwise.
-
getCapContributingEnchantmentCount
public static int getCapContributingEnchantmentCount(net.minecraft.world.item.ItemStack stack) Counts the number of enchantments on the givenItemStackthat contribute towardConfig.MAX_ENCHANTMENT_AMOUNT, respectingConfig.CURSES_COUNT_TOWARD_MAX_ENCHANTMENT_AMOUNT.- Parameters:
stack- TheItemStackto 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 withEnchantmentTags.CURSE, its storage context (applied vs. stored), and the activeConfig.CURSE_CONCEALMENT_MODEsetting.- Parameters:
enchantment- TheHolderof the enchantment to check.isStored-trueif the enchantment resides on a stored enchantment catalyst (DataComponents.STORED_ENCHANTMENTS),falseif applied to target equipment.- Returns:
trueif the enchantment is a curse that should be concealed in the current context,falseotherwise.
-