# EnchantmentHelper

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

**Since:** 1.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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_constructor-Holder-}

```js
new EnchantmentHelper(Holder<Enchantment> base)
```

Wraps an enchantment holder and stores level zero.

**Parameters:**
- `base`: the enchantment holder to wrap

### new EnchantmentHelper {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_constructor-Holder-int-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_constructor-String-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_canBeApplied-ItemHelper-}

```js
canBeApplied(ItemHelper item): boolean
```

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.

**Since:** 1.8.4

### canBeApplied {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_canBeApplied-ItemStackHelper-}

```js
canBeApplied(ItemStackHelper item): boolean
```

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.

**Since:** 1.8.4

### conflictsWith {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_conflictsWith-String-}

```js
conflictsWith(String enchantment): boolean
```

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.

**Since:** 1.8.4

### conflictsWith {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_conflictsWith-EnchantmentHelper-}

```js
conflictsWith(EnchantmentHelper enchantment): boolean
```

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.

**Since:** 1.8.4

### equals {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_equals-Object-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getAcceptableItems-}

```js
getAcceptableItems(): List<ItemHelper>
```

The item types supported by this enchantment. This is the item-type criterion used by
[canBeApplied(ItemHelper)](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_canBeApplied-ItemHelper-); it does not account for stack contents.

**Returns:** the supported item types

**Since:** 1.8.4

### getCompatibleEnchantments {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getCompatibleEnchantments-}

```js
getCompatibleEnchantments(): List<EnchantmentHelper>
```

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.

**Since:** 1.8.4

### getCompatibleEnchantments {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getCompatibleEnchantments-boolean-}

```js
getCompatibleEnchantments(boolean ignoreType): List<EnchantmentHelper>
```

Returns the same compatible-enchantment list as [getCompatibleEnchantments()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_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.

**Since:** 1.8.4

### getConflictingEnchantments {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getConflictingEnchantments-}

```js
getConflictingEnchantments(): List<EnchantmentHelper>
```

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)](https://mcsrc.dev/2/26.2/net/minecraft/world/item/enchantment/Enchantment) treating an enchantment as incompatible
with itself; [getCompatibleEnchantments()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getCompatibleEnchantments-) omits it.

**Returns:** a list of all enchantments that conflict with this one.

**Since:** 1.8.4

### getConflictingEnchantments {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getConflictingEnchantments-boolean-}

```js
getConflictingEnchantments(boolean ignoreType): List<EnchantmentHelper>
```

Returns the same incompatible-enchantment list as [getConflictingEnchantments()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_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.

**Since:** 1.8.4

### getId {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getId-}

```js
getId(): String
```

The full registry id of this enchantment.

**Returns:** the id of this enchantment.

**Since:** 1.8.4

### getLevel {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getLevel-}

```js
getLevel(): int
```

The level carried by this helper, or zero if it was constructed without one. Helpers from
[ItemStackHelper.getEnchantments()](ItemStackHelper.md#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackHelper_getEnchantments-) carry the item's level.

**Returns:** the level of this enchantment.

**Since:** 1.8.4

### getLevelName {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getLevelName-int-}

```js
getLevelName(int level): String
```

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

**Since:** 1.8.4

### getMaxLevel {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getMaxLevel-}

```js
getMaxLevel(): int
```

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.

**Since:** 1.8.4

### getMinLevel {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getMinLevel-}

```js
getMinLevel(): int
```

The minimum level defined for this enchantment.

**Returns:** the minimum possible level of this enchantment that one can get in vanilla.

**Since:** 1.8.4

### getName {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getName-}

```js
getName(): String
```

The translated description of this enchantment without a level suffix.

**Returns:** the name of this enchantment.

**Since:** 1.8.4

### getRomanLevelName {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getRomanLevelName-}

```js
getRomanLevelName(): TextHelper
```

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.

**Since:** 1.8.4

### getRomanLevelName {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getRomanLevelName-int-}

```js
getRomanLevelName(int level): TextHelper
```

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.

**Since:** 1.8.4

### getWeight {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getWeight-}

```js
getWeight(): int
```

The enchantment's configured weight, used by the game when selecting enchantments.

**Returns:** the configured weight.

**Since:** 1.8.4

### hashCode {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_hashCode-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_isCompatible-String-}

```js
isCompatible(String enchantment): boolean
```

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.

**Since:** 1.8.4

### isCompatible {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_isCompatible-EnchantmentHelper-}

```js
isCompatible(EnchantmentHelper enchantment): boolean
```

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.

**Since:** 1.8.4

### isCursed {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_isCursed-}

```js
isCursed(): boolean
```

Whether this enchantment has the curse tag. Curses are styled red by
[getRomanLevelName(int)](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_getRomanLevelName-int-).

**Returns:** `true` if this enchantment is a curse, `false` otherwise.

**Since:** 1.8.4

### isTreasure {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_isTreasure-}

```js
isTreasure(): boolean
```

Whether this enchantment has the treasure tag. This tag is independent of the curse tag
checked by [isCursed()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_isCursed-).

**Returns:** `true` if this enchantment is a treasure, `false` otherwise.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.inventory.EnchantmentHelper_toString-}

```js
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
