IEnchantmentDefinition

Link to ienchantmentdefinition

An IEnchantmentDefinition is the actual Enchantment, it does not posess a level, but you can use this to retrieve information on the Enchantment.

Импорт пакета

Link to импорт-пакета

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.
import crafttweaker.enchantments.IEnchantmentDefinition;

Retrieving such an object

Link to retrieving-such-an-object

You can retrieve such an object from the Enchantment Bracket handler or from an IEnchantment object.

Геттеры/сеттеры

Link to геттерысеттеры

ZenGetterZenSetterТип
ZenGetter
id
ZenSetter
Тип
int
ZenGetter
name
ZenSetter
name
Тип
string
ZenGetter
maxLevel
ZenSetter
Тип
int
ZenGetter
minLevel
ZenSetter
Тип
int
ZenGetter
isAllowedOnBooks
ZenSetter
Тип
boolean
ZenGetter
isTreasureEnchantment
ZenSetter
Тип
boolean
ZenGetter
isCurse
ZenSetter
Тип
boolean
ZenGetter
registryName
ZenSetter
Тип
string

Checks if the enchantment can be put on the item.
First method checks in general, second checks if the item can be enchanted to this enchantment using the enchantment Table.
Both return a bool and require an IItemStack as input parameter.

ZenScript
Copy
ench.canApply(IItemStack item);
ench.canApplyAtEnchantmentTable(IItemStack item);

getEnchantability

Link to getenchantability

Checks what enchantability the item must have for the Enchantment at the given level.
Both methods return an int and take the level of the enchantment as int parameter.

ZenScript
Copy
ench.getMinEnchantability(int level);
ench.getMaxEnchantability(int level);

getTranslatedName

Link to gettranslatedname

Returns the translated name (e.g. "smite IV").
Returns a string and requires the level of the enchantment as int parameter.
Does the same as IEnchantment's .displayName ZenGetter!

objectzenscriptivec
Copy
ench.getTranslatedName(int level);

By giving an EnchantmentDefinition a level you can make an IEnchantment out of it:

ZenScript
Copy
ench.makeEnchantment(int level);
ench * level;

Сравнение с другими объектами IEnchantmentDefinition

Link to сравнение-с-другими-объектами-ienchantmentdefinition

You can use the == operator to check if two enchantments are the same.
This means if they have the same id.

ZenScript
Copy
if(enchA == enchB)
    print("Same!");
ZenScript
Copy
import crafttweaker.enchantments.IEnchantmentDefinition;
import crafttweaker.data.IData;

val array as IEnchantmentDefinition[] = [<enchantment:minecraft:protection>,<enchantment:minecraft:fire_protection>,<enchantment:minecraft:feather_falling>,<enchantment:minecraft:blast_protection>,<enchantment:minecraft:projectile_protection>,<enchantment:minecraft:respiration>,<enchantment:minecraft:aqua_affinity>];

var map as IData = {};

for ench in array {
    map += ench.makeEnchantment(3).makeTag();
}

print(map.asString());


recipes.addShapeless("Supo", <minecraft:golden_sword>.withTag(map), [<minecraft:iron_sword>, <minecraft:golden_sword>]);