Skip to content

How to change a mob's health and speed in a Minecraft mod

Every living entity has attributes: max health, movement speed, attack damage. Forge and NeoForge change them for a whole type with EntityAttributeModificationEvent on the mod event bus (1.16.5 and newer). Fabric API has no such hook, and neither does 1.12.2, so you set the base value when the entity loads, and mark it with a tag so it runs once. Movement speed is in the game’s own unit, not blocks per second: a zombie has 0.23 and a pig 0.25. For your own mob, set the attributes in createAttributes.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Choose the mob and the numbers.
  2. On Forge and NeoForge, listen for EntityAttributeModificationEvent and call event.add.
  3. On Fabric and 1.12.2, set the base values when the entity loads (ServerEntityEvents.ENTITY_LOAD on Fabric, EntityJoinWorldEvent on 1.12.2).
  4. Spawn the mob and check its health bar or use /data get entity (on 1.13 and newer).

The example uses these values. Change them in the code.

Setting In the example What it does
mob ZOMBIE The vanilla mob to change.
health 40 Max health, in half hearts.
speed 0.3 Movement speed.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric 1.18 to 1.21.1, Fabric 1.21.2 to 1.21.11

Section titled “Fabric 1.18 to 1.21.1, Fabric 1.21.2 to 1.21.11”

Uses:

  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED
  • LivingEntity.getAttribute
  • AttributeInstance.setBaseValue

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
// Every ZOMBIE gets 40.0F max health and 0.3F speed. The tag keeps it from running twice on a reloaded mob.
public final class ToughMobAttributes {
private static final String TAG = "examplemod_tough_mob";
private ToughMobAttributes() {
}
// Called from the mod's onInitialize.
public static void register() {
ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity.getType() == EntityType.ZOMBIE && entity instanceof LivingEntity living && !living.getTags().contains(TAG)) {
living.addTag(TAG);
living.getAttribute(Attributes.MAX_HEALTH).setBaseValue(40.0F);
living.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.3F);
living.setHealth(living.getMaxHealth());
}
});
}
}

In your main mod class, inside onInitialize:

ToughMobAttributes.register();

NeoForge 1.20.2 to 1.21.1, NeoForge 1.21.2 to 26.1.2

Section titled “NeoForge 1.20.2 to 1.21.1, NeoForge 1.21.2 to 26.1.2”

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.event.entity.EntityAttributeModificationEvent;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (NeoForge: EntityAttributeModificationEvent on the mod bus).
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
// Called from the mod's constructor.
public static void register(IEventBus modBus) {
modBus.addListener(ToughMobAttributes::onModify);
}
private static void onModify(EntityAttributeModificationEvent event) {
event.add(EntityType.ZOMBIE, Attributes.MAX_HEALTH, 40.0F);
event.add(EntityType.ZOMBIE, Attributes.MOVEMENT_SPEED, 0.3F);
}
}

In your main mod class, inside <init>:

ToughMobAttributes.register(modEventBus);

Uses:

  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED
  • LivingEntity.getAttribute
  • AttributeInstance.setBaseValue

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
// Every ZOMBIE gets 40.0F max health and 0.3F speed. The tag keeps it from running twice on a reloaded mob.
public final class ToughMobAttributes {
private static final String TAG = "examplemod_tough_mob";
private ToughMobAttributes() {
}
// Called from the mod's onInitialize.
public static void register() {
ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity.getType() == EntityType.ZOMBIE && entity instanceof LivingEntity living && !living.entityTags().contains(TAG)) {
living.addTag(TAG);
living.getAttribute(Attributes.MAX_HEALTH).setBaseValue(40.0F);
living.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.3F);
living.setHealth(living.getMaxHealth());
}
});
}
}

In your main mod class, inside onInitialize:

ToughMobAttributes.register();

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.event.entity.EntityAttributeModificationEvent;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (NeoForge: EntityAttributeModificationEvent on the mod bus).
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
// Called from the mod's constructor.
public static void register(IEventBus modBus) {
modBus.addListener(ToughMobAttributes::onModify);
}
private static void onModify(EntityAttributeModificationEvent event) {
event.add(EntityTypes.ZOMBIE, Attributes.MAX_HEALTH, 40.0F);
event.add(EntityTypes.ZOMBIE, Attributes.MOVEMENT_SPEED, 0.3F);
}
}

In your main mod class, inside <init>:

ToughMobAttributes.register(modEventBus);

Uses:

  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED
  • LivingEntity.getAttribute
  • AttributeInstance.setBaseValue

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
// Every ZOMBIE gets 40.0F max health and 0.3F speed. The tag keeps it from running twice on a reloaded mob.
public final class ToughMobAttributes {
private static final String TAG = "examplemod_tough_mob";
private ToughMobAttributes() {
}
// Called from the mod's onInitialize.
public static void register() {
ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity.getType() == EntityTypes.ZOMBIE && entity instanceof LivingEntity living && !living.entityTags().contains(TAG)) {
living.addTag(TAG);
living.getAttribute(Attributes.MAX_HEALTH).setBaseValue(40.0F);
living.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.3F);
living.setHealth(living.getMaxHealth());
}
});
}
}

In your main mod class, inside onInitialize:

ToughMobAttributes.register();

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (Forge: EntityAttributeModificationEvent on the mod bus).
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
// Called from the mod's constructor.
public static void register(IEventBus modBus) {
modBus.addListener(ToughMobAttributes::onModify);
}
private static void onModify(EntityAttributeModificationEvent event) {
event.add(EntityType.ZOMBIE, Attributes.MAX_HEALTH, 40.0F);
event.add(EntityType.ZOMBIE, Attributes.MOVEMENT_SPEED, 0.3F);
}
}

In your main mod class, inside <init>:

ToughMobAttributes.register(modEventBus);

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (NeoForge: EntityAttributeModificationEvent on the mod bus).
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
// Called from the mod's constructor.
public static void register(IEventBus modBus) {
modBus.addListener(ToughMobAttributes::onModify);
}
private static void onModify(EntityAttributeModificationEvent event) {
event.add(EntityType.ZOMBIE, Attributes.MAX_HEALTH, 40.0F);
event.add(EntityType.ZOMBIE, Attributes.MOVEMENT_SPEED, 0.3F);
}
}

In your main mod class, inside <init>:

ToughMobAttributes.register(modEventBus);

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (Forge: EntityAttributeModificationEvent on the mod bus).
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
// Called from the mod's constructor.
public static void register(IEventBus modBus) {
modBus.addListener(ToughMobAttributes::onModify);
}
private static void onModify(EntityAttributeModificationEvent event) {
event.add(EntityType.ZOMBIE, Attributes.MAX_HEALTH, 40.0F);
event.add(EntityType.ZOMBIE, Attributes.MOVEMENT_SPEED, 0.3F);
}
}

In your main mod class, inside <init>:

ToughMobAttributes.register(modEventBus);

Uses:

  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED
  • LivingEntity.getAttribute
  • AttributeInstance.setBaseValue

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
// Every ZOMBIE gets 40.0F max health and 0.3F speed. The tag keeps it from running twice on a reloaded mob.
public final class ToughMobAttributes {
private static final String TAG = "examplemod_tough_mob";
private ToughMobAttributes() {
}
// Called from the mod's onInitialize.
public static void register() {
ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity.getType() == EntityType.ZOMBIE && entity instanceof LivingEntity && !entity.getTags().contains(TAG)) {
LivingEntity living = (LivingEntity) entity;
living.addTag(TAG);
living.getAttribute(Attributes.MAX_HEALTH).setBaseValue(40.0F);
living.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.3F);
living.setHealth(living.getMaxHealth());
}
});
}
}

In your main mod class, inside onInitialize:

ToughMobAttributes.register();

Uses:

  • EntityAttributeModificationEvent.add
  • Attributes.MAX_HEALTH
  • Attributes.MOVEMENT_SPEED

In 1.12.2 there is no attribute modification event: set the base values in an EntityJoinWorldEvent handler through mob.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).

src/main/java/com/example/examplemod/event/ToughMobAttributes.java

package com.example.examplemod.event;
import com.example.examplemod.ExampleMod;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
// Every ZOMBIE gets 40.0F max health and 0.3F speed (Forge 1.12.2: set the attributes when the entity joins a world).
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID)
public final class ToughMobAttributes {
private ToughMobAttributes() {
}
@SubscribeEvent
public static void onJoin(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityLivingBase
&& new ResourceLocation("minecraft", "ZOMBIE".toLowerCase()).equals(EntityList.getKey(event.getEntity()))) {
EntityLivingBase mob = (EntityLivingBase) event.getEntity();
mob.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0F);
mob.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3F);
}
}
}

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.