Skip to content

EnchantmentHelper ​

com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper

Since1.8.4

Represents an enchantment and an optional level. Helpers constructed without a level report zero;
helpers obtained from an item carry its enchantment level. Compatibility is independent of level;
an enchantment is incompatible with itself, so it appears in its conflicting list and not its compatible list.

js
// an enchantment on its own, from the registry
const sharpness = Client.getRegistryManager().getEnchantment("minecraft:sharpness");  
Chat.log(`${sharpness.getName()} ${sharpness.getMinLevel()} to ${sharpness.getMaxLevel()}`);  
Chat.log(`weight ${sharpness.getWeight()}, cursed ${sharpness.isCursed()}`);  

// and the same one at a level, which is what an item gives
const onSword = Client.getRegistryManager().getEnchantment("minecraft:sharpness", 3);  
Chat.log(`level ${onSword.getLevel()}: ${onSword.getRomanLevelName()}`);  

// compatibility is a property of the pair, and never true of one with itself
const looting = Client.getRegistryManager().getEnchantment("minecraft:looting");  
Chat.log(`sharpness with looting: ${sharpness.isCompatible(looting)}`);  
Chat.log(`sharpness with itself: ${sharpness.isCompatible(sharpness)}`);

Constructors ​

new EnchantmentHelper ​

new EnchantmentHelper(Holder<Enchantment> base)#
Wraps an enchantment holder and stores level zero.

Parameters:

  • base: the enchantment holder to wrap
new EnchantmentHelper(Holder<Enchantment> base, int level)#
Wraps an enchantment holder and stores the supplied level without validation or clamping.

Parameters:

  • base: the enchantment holder to wrap
  • level: the level stored by this helper
new EnchantmentHelper(String enchantment)#
Resolves an enchantment identifier through the current connection's enchantment registry. Requires a client connection and a matching registry entry; lookup failures propagate. The resulting helper stores level zero.

Parameters:

  • enchantment: the identifier to look up

Methods ​

canBeApplied ​

canBeApplied(ItemHelper item): booleanSince1.8.4#
Whether this enchantment supports the item's type. This checks the item type only; it does not check existing enchantments on a stack.

Parameters:

  • item: the item to check
Returns: true if the item's type is supported, false otherwise.
canBeApplied(ItemStackHelper item): booleanSince1.8.4#
Whether this enchantment supports the stack's item type and is compatible with every enchantment already on the stack.

Parameters:

  • item: the item to check
Returns: true if both checks pass, false otherwise.

conflictsWith ​

conflictsWith(String enchantment): booleanSince1.8.4#
Whether the enchantment identified by enchantment is incompatible with this one. An enchantment conflicts with itself. The id is resolved in the connected server's registry; an unknown id throws rather than returning false.

Parameters:

  • enchantment: the enchantment to check
Returns: true if this enchantment conflicts with the given enchantment, false otherwise.
conflictsWith(EnchantmentHelper enchantment): booleanSince1.8.4#
Whether the given enchantment is incompatible with this one. An enchantment conflicts with itself.

Parameters:

  • enchantment: the enchantment to check
Returns: true if this enchantment conflicts with the given enchantment, false otherwise.

equals ​

equals(Object o): boolean#
Compares this helper with another enchantment helper. The wrapped holders must compare equal; level zero on either helper matches any level, so equality is not transitive for distinct nonzero levels.

Parameters:

  • o: the object to compare
Returns: true for the same instance or a matching helper under the holder and level rules; false otherwise

getAcceptableItems ​

getAcceptableItems(): List<ItemHelper>Since1.8.4#
The item types supported by this enchantment. This is the item-type criterion used by canBeApplied(ItemHelper); it does not account for stack contents.
Returns: the supported item types

getCompatibleEnchantments ​

getCompatibleEnchantments(): List<EnchantmentHelper>Since1.8.4#
Enchantments from the registry compatible with this one. The list omits this enchantment itself, and returned helpers have level zero.
Returns: a list of all enchantments that can be combined with this one.
getCompatibleEnchantments(boolean ignoreType): List<EnchantmentHelper>Since1.8.4#
Returns the same compatible-enchantment list as getCompatibleEnchantments(). The parameter is unused; results are not filtered by target type. Returned helpers have level zero.

Parameters:

  • ignoreType: unused. The list is not narrowed by target type.
Returns: a list of all enchantments that can be combined with this one.

getConflictingEnchantments ​

getConflictingEnchantments(): List<EnchantmentHelper>Since1.8.4#
Enchantments from the registry that are incompatible with this one, including this enchantment itself. Returned helpers have level zero. The self-entry follows from Enchantment.areCompatible(Holder, Holder) treating an enchantment as incompatible with itself; getCompatibleEnchantments() omits it.
Returns: a list of all enchantments that conflict with this one.
getConflictingEnchantments(boolean ignoreType): List<EnchantmentHelper>Since1.8.4#
Returns the same incompatible-enchantment list as getConflictingEnchantments(). The parameter is unused; results are not filtered by target type. Returned helpers have level zero.

Parameters:

  • ignoreType: unused. The list is not narrowed by target type.
Returns: a list of all enchantments that conflict with this one.

getId ​

getId(): StringSince1.8.4#
The full registry id of this enchantment.
Returns: the id of this enchantment.

getLevel ​

getLevel(): intSince1.8.4#
The level carried by this helper, or zero if it was constructed without one. Helpers from ItemStackHelper.getEnchantments() carry the item's level.
Returns: the level of this enchantment.

getLevelName ​

getLevelName(int level): StringSince1.8.4#
The translated full name at level, as a plain string without text styling. The level is supplied explicitly and need not be the helper's stored level.

Parameters:

  • level: the level for the name
Returns: the translated name and, when applicable, the translated level suffix

getMaxLevel ​

getMaxLevel(): intSince1.8.4#
The maximum level defined for this enchantment; this does not restrict levels passed to the name methods.
Returns: the maximum possible level of this enchantment that one can get in vanilla.

getMinLevel ​

getMinLevel(): intSince1.8.4#
The minimum level defined for this enchantment.
Returns: the minimum possible level of this enchantment that one can get in vanilla.

getName ​

getName(): StringSince1.8.4#
The translated description of this enchantment without a level suffix.
Returns: the name of this enchantment.

getRomanLevelName ​

getRomanLevelName(): TextHelperSince1.8.4#
The styled name at this helper's stored level. The level suffix uses Roman numerals for levels 1–3999 and decimal digits otherwise; level 1 is omitted only when the enchantment's maximum is 1. A helper constructed without a level therefore produces a level-zero suffix.
Returns: the translated name of this enchantment for the given level in roman numerals.
getRomanLevelName(int level): TextHelperSince1.8.4#
The styled name at level, with a Roman numeral suffix for levels 1–3999 and decimal digits otherwise. Level 1 is omitted only when the enchantment's maximum level is 1.

Parameters:

  • level: the level for the name
Returns: the translated name of this enchantment for the given level in roman numerals.

getWeight ​

getWeight(): intSince1.8.4#
The enchantment's configured weight, used by the game when selecting enchantments.
Returns: the configured weight.

hashCode ​

hashCode(): int#
Computes a hash from the wrapped holder and stored level. Because equality treats level zero as a wildcard, equal helpers can have different hash codes; this can affect hash-based collections.
Returns: the hash of the wrapped holder and stored level

isCompatible ​

isCompatible(String enchantment): booleanSince1.8.4#
Whether this enchantment is compatible with the enchantment identified by enchantment. An enchantment is not compatible with itself. The id is resolved in the connected server's registry; an unknown id throws rather than returning false.

Parameters:

  • enchantment: the enchantment to check
Returns: true if this enchantment is compatible with the given enchantment, false otherwise.
isCompatible(EnchantmentHelper enchantment): booleanSince1.8.4#
Whether this enchantment is compatible with the given enchantment. Levels do not affect compatibility, and an enchantment is not compatible with itself.

Parameters:

  • enchantment: the enchantment to check
Returns: true if this enchantment is compatible with the given enchantment, false otherwise.

isCursed ​

isCursed(): booleanSince1.8.4#
Whether this enchantment has the curse tag. Curses are styled red by getRomanLevelName(int).
Returns: true if this enchantment is a curse, false otherwise.

isTreasure ​

isTreasure(): booleanSince1.8.4#
Whether this enchantment has the treasure tag. This tag is independent of the curse tag checked by isCursed().
Returns: true if this enchantment is a treasure, false otherwise.

toString ​

toString(): String#
Returns a diagnostic string containing this helper's enchantment id and stored level; it is not a serialization format.
Returns: a diagnostic representation of this helper