Home Migration Guide Getting Started With Scripts Commands Examples
BracketHandlers

MCEnchantment

Importing the class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

script.zs
import crafttweaker.api.enchantment.MCEnchantment;

Methods

Checks if this Enchantment can be applied to the given IItemStack.

Returns: True if this Enchantment can apply to the given IItemStack. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.canApply(stack as IItemStack) as boolean
<enchantment:minecraft:protection>.canApply(<item:minecraft:diamond_sword>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to check if this enchantment can be applied to.

Checks if this Enchantment can be applied to the given IItemStack at an enchanting table..

Returns: True if this Enchantment can be applied. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.canApplyAtEnchantingTable(stack as ItemStack) as boolean
<enchantment:minecraft:protection>.canApplyAtEnchantingTable(<item:minecraft:stone_sword>);
ParameterTypeDescription
Parameter
stack
Type
ItemStack
Description
The IItemStack to check against.

Checks if this Enchantment can generate in loot.

Returns: True if this Enchantment can generate in loot.
Return Type: boolean

script.zs
// MCEnchantment.canGenerateInLoot() as boolean
<enchantment:minecraft:protection>.canGenerateInLoot();

Checks if a villager can sell this Enchantment.

Returns: True if a villager can sell this Enchantment. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.canVillagerTrade() as boolean
<enchantment:minecraft:protection>.canVillagerTrade();

Gets the display name of this Enchantment at the given level.

Returns: The display name of this Enchantment at the level.
Return Type: MCTextComponent

script.zs
// MCEnchantment.getDisplayName(level as int) as MCTextComponent
<enchantment:minecraft:protection>.getDisplayName(2);
ParameterTypeDescription
Parameter
level
Type
int
Description
The level of this enchantment

Gets a map of all equipment that the entity is currently holding that this Enchantment can be applied to.

Returns: A map of EquipmentSlotType to IItemStack
Return Type: IItemStack[MCEquipmentSlotType]

script.zs
// MCEnchantment.getEntityEquipment(livingEntity as MCLivingEntity) as IItemStack[MCEquipmentSlotType]
<enchantment:minecraft:protection>.getEntityEquipment(entity);
ParameterTypeDescription
Parameter
livingEntity
Type
MCLivingEntity
Description
The entity to check.

Gets the maximum enchantability required to enchant this Enchantment at the given enchantment level.

For example, to enchant an item with Fire Aspect at level 1, you need an enchantability that is less than 60..

Returns: The enchantability of the Enchantment at the given level.
Return Type: int

script.zs
// MCEnchantment.getMaxEnchantability(enchantmentLevel as int) as int
<enchantment:minecraft:protection>.getMaxEnchantability(1);
ParameterTypeDescription
Parameter
enchantmentLevel
Type
int
Description
The enchantment level to get the enchantability for.

Gets the maximum level for this Enchantment.

Returns: The maximum level for this Enchantment.
Return Type: int

script.zs
// MCEnchantment.getMaxLevel() as int
<enchantment:minecraft:protection>.getMaxLevel();

Gets the minimum enchantability required to enchant this Enchantment at the given enchantment level.

For example, to enchant an item with Fire Aspect at level 1, you need an enchantability of at-least 10.

Returns: The enchantability of the Enchantment at the given level.
Return Type: int

script.zs
// MCEnchantment.getMinEnchantability(enchantmentLevel as int) as int
<enchantment:minecraft:protection>.getMinEnchantability(1);
ParameterTypeDescription
Parameter
enchantmentLevel
Type
int
Description
The enchantment level to get the enchantability for.

Gets the minimum level for this Enchantment.

Returns: The minimum level for this Enchantment.
Return Type: int

script.zs
// MCEnchantment.getMinLevel() as int
<enchantment:minecraft:protection>.getMinLevel();

Gets the name of this Enchantment

Returns: The name of this Enchantment
Return Type: string

script.zs
// MCEnchantment.getName() as string
<enchantment:minecraft:protection>.getName();

Gets the Rarity of this Enchantment

Returns: The Rarity of this Enchantment
Return Type: EnchantmentRarity

script.zs
// MCEnchantment.getRarity() as EnchantmentRarity
<enchantment:minecraft:protection>.getRarity();

Gets the EnchantmentType of this Enchantment.

Returns: The EnchantmentType of this Enchantment.
Return Type: EnchantmentType

script.zs
// MCEnchantment.getType() as EnchantmentType
<enchantment:minecraft:protection>.getType();

Check if this Enchantment is allowed on books.

Returns: True if this Enchantment can be applied on books. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.isAllowedOnBooks() as boolean
<enchantment:minecraft:protection>.isAllowedOnBooks();

Checks if this Enchantment is compatible with the other given Enchantment.

Returns: True if the Enchantments are compatible. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.isCompatibleWith(other as MCEnchantment) as boolean
<enchantment:minecraft:protection>.isCompatibleWith(<enchantment:minecraft:efficiency>);
ParameterTypeDescription
Parameter
other
Type
MCEnchantment
Description
The other Enchantment to check if it is compatible with this Enchantment

Checks if this Enchantment is a curse Enchantment.

Returns: True if this Enchantment is a curse enchantment. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.isCurse() as boolean
<enchantment:minecraft:protection>.isCurse();

Checks if this Enchantment is a treasure Enchantment.

Returns: True if this Enchantment is a treasure enchantment. False otherwise.
Return Type: boolean

script.zs
// MCEnchantment.isTreasureEnchantment() as boolean
<enchantment:minecraft:protection>.isTreasureEnchantment();

Properties

NameTypeHas GetterHas SetterDescription
Name
allowedOnBook
Type
boolean
Has Getter
true
Has Setter
false
Description
Check if this Enchantment is allowed on books.
Name
canGenerateInLoot
Type
boolean
Has Getter
true
Has Setter
false
Description
Checks if this Enchantment can generate in loot.
Name
canVillagerTrade
Type
boolean
Has Getter
true
Has Setter
false
Description
Checks if a villager can sell this Enchantment.
Name
curse
Type
boolean
Has Getter
true
Has Setter
false
Description
Checks if this Enchantment is a curse Enchantment.
Name
maxLevel
Type
int
Has Getter
true
Has Setter
false
Description
Gets the maximum level for this Enchantment.
Name
minLevel
Type
int
Has Getter
true
Has Setter
false
Description
Gets the minimum level for this Enchantment.
Name
name
Type
string
Has Getter
true
Has Setter
false
Description
Gets the name of this Enchantment
Name
rarity
Type
EnchantmentRarity
Has Getter
true
Has Setter
false
Description
Gets the Rarity of this Enchantment
Name
treasure
Type
boolean
Has Getter
true
Has Setter
false
Description
Checks if this Enchantment is a treasure Enchantment.
Name
type
Type
EnchantmentType
Has Getter
true
Has Setter
false
Description
Gets the EnchantmentType of this Enchantment.