Skip to content

Mob events

These events report what happens to mobs on the server: a hit that lands, a death and the gear it drops, a new attack target, a baby bred by a player, and a mob about to spawn naturally, which a listener can cancel. Use them to record state or to give MobControl orders; use reactions instead when a whole mob group should respond to the event.

Type Summary Status Since Side Thread
AnimalBredCallback Fired when a pair of animals that a player fed produces a baby. Experimental 1.2.0 server server
MobEquipmentDropsCallback Fired when a mob dies, before vanilla drops its hand and armor items. Experimental 2.6.0 server server
MobHurtCallback Fired after a mob takes damage. Experimental 1.2.0 server server
MobKilledCallback Fired after a mob dies. Experimental 1.2.0 server server
MobTargetChangedCallback Fired when a mob’s attack target changes through Mob#setTarget. Experimental 1.2.0 server server
NaturalSpawnCallback Asked before a natural spawn places a mob; a listener can cancel it. Experimental 2.6.0 server server

In your mod’s common initializer:

Drop an emerald when a player kills a raider
MobKilledCallback.EVENT.register((mob, source, killer) -> {
if (killer instanceof ServerPlayer && mob.getType().is(EntityTypeTags.RAIDERS)) {
mob.spawnAtLocation(new ItemStack(Items.EMERALD));
}
});

Experimental · Since 1.2.0 · Side: server · Thread: server

Make a goat ram the player who hurt it
MobHurtCallback.EVENT.register((mob, source, amount, attacker) -> {
if (mob instanceof Goat && attacker instanceof ServerPlayer player && !player.isCreative()) {
// 100 ticks (5 seconds) of rams; then the goat's own AI decides.
MobControl.attack(mob, player, 100);
}
});

A hit by a mob that holds a MobControl#attack order fires this event like any other hit. Reaction triggers skip such hits, as the reaction binding format describes, so a listener sees hits that reactions ignore.

Experimental · Since 2.6.0 · Side: server · Thread: server

A listener reads vanilla’s chance for a slot to decide whether to force it. This one forces every slot vanilla ever drops, with wear for the gear the mob spawned with, when a player made the kill:

Drop all of a mob's gear when a player kills it
MobEquipmentDropsCallback.EVENT.register((mob, drops) -> {
if (!drops.recentlyHit()) return;
for (EquipmentSlot slot : EquipmentSlot.values()) {
float chance = drops.dropChance(slot);
// A chance of 0 marks a slot vanilla never drops, such as a vex's sword.
if (chance > 0f) drops.forceDrop(slot, chance <= 1f);
}
});
  • Listeners run after the mob’s loot table dropped.
  • Forced slots drop as soon as the last listener returns; vanilla then drops the slots left alone by its own chance.
  • MobKilledCallback fires after both, once the mob’s equipment is on the ground.
  • On Forge, forced drops are part of the death’s drops, so LivingDropsEvent listeners see and can remove them like vanilla’s.
  • A mob whose own code drops its items (a piglin’s inventory, a fox’s mouth, an allay’s item, a llama’s chest) drops them as in vanilla.

Experimental · Since 2.6.0 · Side: server · Thread: server

Refuse half of the natural bat spawn attempts
NaturalSpawnCallback.EVENT.register((level, mob) ->
mob.getType() != EntityType.BAT || level.getRandom().nextInt(100) < 50);
  • On Forge, listeners run after MobSpawnEvent.PositionCheck, so a spawn another mod denied there never reaches them.
  • A refused mob leaves room under its category’s mob cap, and vanilla tries the same mob type again at the pack’s next position and on later ticks, so refusing a share of the attempts lowers that mob’s natural spawns by less than that share where the cap is reached.