Entity Events
dev.architectury.event.events.common.EntityEvent
Events about entities: dying, taking damage, spawning, being added to the world, moving between chunk sections, and being tamed.
Events
| Event | Listener method | Returns |
|---|---|---|
LIVING_DEATH | die(LivingEntity, DamageSource) | EventResult - interrupt to cancel the death. |
LIVING_HURT | hurt(LivingEntity, DamageSource, float amount) | EventResult - interrupt to cancel the damage. |
LIVING_CHECK_SPAWN | canSpawn(LivingEntity, LevelAccessor, double x, double y, double z, EntitySpawnReason, BaseSpawner) | EventResult - set an outcome to override whether it may spawn. |
ADD | add(Entity, Level) | EventResult - interrupt to prevent the entity being added. |
ENTER_SECTION | enterSection(Entity, int sectionX, sectionY, sectionZ, int prevX, prevY, prevZ) | void (notification). |
ANIMAL_TAME | tame(Animal, Player) | EventResult - interrupt to cancel the taming. |
note
LIVING_HURT lets you cancel damage, but you currently cannot change the damage amount.
LIVING_CHECK_SPAWN concerns natural/spawner spawning and worldgen; the spawner argument may
be null. ANIMAL_TAME only fires for vanilla tamable mobs.
Examples
Make a custom boss immune to drowning:
EntityEvent.LIVING_HURT.register((entity, source, amount) -> {
if (entity instanceof MyBossEntity && source.is(DamageTypes.DROWN)) {
return EventResult.interruptFalse(); // cancel the damage
}
return EventResult.pass();
});
Prevent zombies from spawning in a region:
EntityEvent.LIVING_CHECK_SPAWN.register((entity, world, x, y, z, type, spawner) -> {
if (entity instanceof Zombie && isProtected(x, z)) {
return EventResult.interruptFalse();
}
return EventResult.pass();
});