Skip to content

custom item effects

Mikael E. Wikner edited this page Jun 20, 2021 · 2 revisions

Custom item effects

New item effects can be added and used by other mods.

This example would cause any mainhand item with the hilt/wind_blessing improvement to give the wielder a 10% chance to avoid incoming attacks

public class TetraCompat {
    private ItemEffect dodge = ItemEffect.get("mymod.dodge");

    @SubscribeEvent
    public void onLivingAttackEvent(LivingAttackEvent event) {
        LivingEntity attackedEntity = event.getEntityLiving();
        ItemStack heldStack = attackedEntity.getHeldItemMainhand();
        if (heldStack.getItem() instanceof ModularItem) {
            ModularItem item = (ModularItem) itemStack.getItem();

            int level = item.getEffectLevel(heldStack, dodge);
            if (level > attackedEntity.nextFloat() * 100) {
                event.setCanceled(true);
                attackedEntity.applyKnockback(5, 0, 0);
            }
        }
    }
}
{
    "key": "hilt/wind_blessing",
    "level": 1,
    "effects": {
        "mymod.dodge": 10
    }
}