CodeEffect
For Players
This modification doesn't provide any new gameplay features on its own. CodeEffect is a technical library that enables other mods to execute program code through the data-driven enchantment system.
For Developers
Registering your code:
CodeEffect.register(HOOK_ID, (world, level, context, user, pos) -> {
// Your code here
});
or alternative option:
CodeEffect.register(HOOK_ID, this::stuff);
// ...
public void stuff(ServerWorld world, int level, EnchantmentEffectContext context, Entity user, Vec3d pos) {
// Your code here
}
Using in data:
"effect": {
"type": "code_effect:run_code",
"hook": "HOOK_ID"
}
Complete enchantment example:
Modified sharpness that executes code every game tick
{
"anvil_cost": 1,
"description": {
"translate": "enchantment.minecraft.sharpness"
},
"effects": {
"minecraft:tick": [
{
"effect": {
"type": "code_effect:run_code",
"hook": "HOOK_ID"
}
}
]
},
"exclusive_set": "#minecraft:exclusive_set/damage",
"max_cost": {
"base": 21,
"per_level_above_first": 11
},
"max_level": 5,
"min_cost": {
"base": 1,
"per_level_above_first": 11
},
"primary_items": "#minecraft:enchantable/sword",
"slots": [
"mainhand"
],
"supported_items": "#minecraft:enchantable/weapon",
"weight": 10
}