Table of Contents

Adding Status Effects

To add status effects to your mod, you'll need to:

Creating Status Effect Class

We will add a new status effect that gives you EXP every tick.

public class ExpStatusEffect extends StatusEffect {
  public ExpStatusEffect() {
    super(
      StatusEffectCategory.BENEFICIAL, // whether beneficial or harmful for entities
      0x98D982); // color in RGB
  }
 
  // This method is called every tick to check whether it should apply the status effect or not
  @Override
  public boolean canApplyUpdateEffect(int duration, int amplifier) {
    // In our case, we just make it return true so that it applies the status effect every tick.
    return true;
  }
 
  // This method is called when it applies the status effect. We implement custom functionality here.
  @Override
  public void applyUpdateEffect(LivingEntity entity, int amplifier) {
    if (entity instanceof PlayerEntity) {
      ((PlayerEntity) entity).addExperience(1 << amplifier); // Higher amplifier gives you EXP faster
    }
  }
}

Registering Status Effect

This registers our status effect.

public class ExampleMod implements ModInitializer {
  public static final StatusEffect EXP = new ExpStatusEffect();
 
  @Override
  public void onInitialize() {
    Registry.register(Registries.STATUS_EFFECT, new Identifier("tutorial", "exp"), EXP);
  }
}

Adding Translations & Textures

You'll need to add a translation to your status effect. Head over to your mod lang file and add a new entry:

{
  "effect.tutorial.exp": "Experience"
}

You'll need to add a texture as well. The direct path is:

.../resources/assets/tutorial/textures/mob_effect/exp.png

Testing

You can run a command /effect give @p tutorial:exp in game to test your status effect.