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.
At a glance
Section titled “At a glance”| 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 |
Quick start
Section titled “Quick start”In your mod’s common initializer:
MobKilledCallback.EVENT.register((mob, source, killer) -> { if (killer instanceof ServerPlayer && mob.getType().is(EntityTypeTags.RAIDERS)) { mob.spawnAtLocation(new ItemStack(Items.EMERALD)); }});MobHurtCallback
Section titled “MobHurtCallback”Experimental · Since 1.2.0 · Side: server · Thread: server
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); }});Interaction with MobControl
Section titled “Interaction with MobControl”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.
MobEquipmentDropsCallback
Section titled “MobEquipmentDropsCallback”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:
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); }});Ordering and timing
Section titled “Ordering and timing”- 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.
MobKilledCallbackfires after both, once the mob’s equipment is on the ground.- On Forge, forced drops are part of the death’s drops, so
LivingDropsEventlisteners see and can remove them like vanilla’s.
Edge cases
Section titled “Edge cases”- 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.
NaturalSpawnCallback
Section titled “NaturalSpawnCallback”Experimental · Since 2.6.0 · Side: server · Thread: server
NaturalSpawnCallback.EVENT.register((level, mob) -> mob.getType() != EntityType.BAT || level.getRandom().nextInt(100) < 50);Ordering and timing
Section titled “Ordering and timing”- On Forge, listeners run after
MobSpawnEvent.PositionCheck, so a spawn another mod denied there never reaches them.
Edge cases
Section titled “Edge cases”- 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.
See also
Section titled “See also”- Mob groups: the groups a mob leaves when it dies.
- Reaction binding format: the triggers that turn these events into group reactions.