Mob Effects
Mob effects, also known as status effects or simply effects, are a condition that can affect an entity. They can be positive, negative or neutral in nature. The base game applies these effects in various ways such as food, potions etc.
The /effect command can be used to apply effects on an entity.
Custom Mob Effects
In this tutorial we'll add a new custom effect called Tater which gives you one experience point every game tick.
Extend MobEffect
Let's create a custom effect class by extending MobEffect, which is the base class for all effects.
java
public class TaterEffect extends MobEffect {
protected TaterEffect() {
// category: StatusEffectCategory - describes if the effect is helpful (BENEFICIAL), harmful (HARMFUL) or useless (NEUTRAL)
// color: int - Color is the color assigned to the effect (in RGB)
super(MobEffectCategory.BENEFICIAL, 0xe9b8b3);
}
// Called every tick to check if the effect can be applied or not
@Override
public boolean shouldApplyEffectTickThisTick(int duration, int amplifier) {
// In our case, we just make it return true so that it applies the effect every tick
return true;
}
// Called when the effect is applied
@Override
public void applyEffectTick(LivingEntity entity, int amplifier) {
if (entity instanceof Player) {
((Player) entity).giveExperiencePoints(1 << amplifier); // Higher amplifier gives you experience faster
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Registering Your Custom Effect
Similar to block and item registration, we use Registry.register to register our custom effect into the MOB_EFFECT registry. This can be done in our initializer.
java
public class ExampleModEffects implements ModInitializer {
public static final MobEffect TATER_EFFECT = new TaterEffect();
@Override
public void onInitialize() {
Registry.register(BuiltInRegistries.MOB_EFFECT, new ResourceLocation("example-mod", "tater"), TATER_EFFECT);
}
}1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Texture
The status effect icon is a 18x18 PNG which will appear in the player's inventory screen. Place your custom icon in:
resources/assets/example-mod/textures/mob_effect/tater.pngTranslations
Like any other translation, you can add an entry with ID format "effect.example-mod.<effect-identifier>": "Value" to the language file.
json
{
"effect.example-mod.tater": "Tater"
}1
2
3
2
3
Testing
Use the command /effect give @p example-mod:tater to give the player our Tater effect. Use /effect clear @p example-mod:tater to remove the effect.
INFO
To create a potion that uses this effect, please see the Potions guide.






