Enchantment Builder

Link to enchantment-builder

Using this package you can create custom enchantments for tools, weapons and probably everything else.

It might be required for you to import the class if you encounter any issues (like casting an Array), so better be safe than sorry and add the import.
import mods.contenttweaker.enchantments.EnchantmentBuilder;

Creating an Enchant

Link to creating-an-enchant

First and foremost you will need to create a Material Builder.
This can be done using the static create method.

ZenScript
Copy
//mods.contenttweaker.enchantments.EnchantmentBuilder.create(String name);
val myChant = mods.contenttweaker.enchantments.EnchantmentBuilder.create("kindlich_chant");

Remember, that you will need to register the enchantment after you've done your changes.
This can be done with the register method which will return a IEnchantmentDefinition of the new enchantment.

ZenScript
Copy
myChant.register();

You can set and get these properties using myChant.name.

name(名称)类型
name(名称)
name(名称)
类型
string
name(名称)
allowedOnBooks
类型
bool
name(名称)
applicableSlots
类型
IEntityEquipmentSlot[] (default: empty)
name(名称)
curse
类型
bool
name(名称)
domain
类型
string (default: "contenttweaker")
name(名称)
maxLevel
类型
int (default: 1)
name(名称)
minLevel
类型
int (default: 1)
name(名称)
rarity
类型
string (use the custom methods below)
name(名称)
treasure
类型
bool
name(名称)
类型
类型
string (use the custom methods below)

Calculated Properties

Link to calculated-properties

You can set and get these properties functions.

name(名称)parameters返回值类型
name(名称)
canApply
parameters
IEnchantmentDefinition thisEnchantment, IItemStack item
返回值类型
bool
name(名称)
canApplyAtEnchantmentTable
parameters
IEnchantmentDefinition thisEnchantment, IItemStack item
返回值类型
bool
name(名称)
canApplyTogether
parameters
IEnchantmentDefinition thisEnchantment, IEnchantmentDefinition other
返回值类型
bool
name(名称)
calcDamageByCreature
parameters
IEnchantmentDefinition thisEnchantment, int level, String creatureType
返回值类型
float
name(名称)
calcEnchantabilityMin
parameters
IEnchantmentDefinition thisEnchantment, int level
返回值类型
int
name(名称)
calcEnchantabilityMax
parameters
IEnchantmentDefinition thisEnchantment, int level
返回值类型
int
name(名称)
calcModifierDamage
parameters
IEnchantmentDefinition thisEnchantment, int level, IDamageSource damageSource
返回值类型
int
name(名称)
calcTranslatedName
parameters
IEnchantmentDefinition thisEnchantment, int level
返回值类型
string
name(名称)
parameters
返回值类型
name(名称)
onEntityDamaged
parameters
IEnchantmentDefinition thisEnchantment, IEntityLivingBase user, IEntity target, int level
返回值类型
void
name(名称)
onUserHurt
parameters
IEnchantmentDefinition thisEnchantment, IEntityLivingBase user, IEntity attacker, int level
返回值类型
void

Use these methods to be instantly notified if you made a typo.

ZenScript
Copy
//Rarities
myChant.setRarityCommon()
myChant.setRarityUncommon()
myChant.setRarityRare()
myChant.setRarityVeryRare()

//Types
myChant.setTypeAll()
myChant.setTypeArmor()
myChant.setTypeFeed()
myChant.setTypeLegs()
myChant.setTypeChest()
myChant.setTypeHead()
myChant.setTypeWeapon()
myChant.setTypeDigger()
myChant.setTypeFishingRod()
myChant.setTypeBreakable()
myChant.setTypeBow()
myChant.setTypeWearable()
ZenScript
Copy
#loader contenttweaker
val builder = mods.contenttweaker.enchantments.EnchantmentBuilder.create("kindlich_chant");
builder.applicableSlots = [mainHand, offhand, feet, legs, chest, head];
builder.setTypeAll();
builder.setRarityVeryRare();
builder.calcModifierDamage = function(thisEnch, level, damageSource){
    return level;
};

builder.onUserHurt = function(thisEnch, entity, attacker, level) {
    entity.health = entity.maxHealth;
    if(entity instanceof crafttweaker.player.IPlayer) {
        val player as crafttweaker.player.IPlayer = entity;
        player.foodStats.addStats(100, 10.0f);
    }

};

builder.register();

builder.name = "other_chant";
builder.domain = "definitely_not_cot";
builder.calcModifierDamage = null;
builder.onUserHurt = function(thisEnch, player, attacker, level) {
    player.sendMessage("EARNED IT!");   
};
builder.register();