Class MobSpawnEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.MobSpawnEvent
- Direct Known Subclasses:
FinalizeSpawnEvent
,MobDespawnEvent
,MobSpawnEvent.PositionCheck
This class holds all events relating to the entire flow of mob spawns.
Currently, the events have the following flow for any given mob spawn:
Currently, the events have the following flow for any given mob spawn:
Before the spawn is attempted MobSpawnEvent.SpawnPlacementCheck
is fired, to determine if the spawn may occur based on mob-specific rules.
After the entity is created MobSpawnEvent.PositionCheck
is fired, to determine if the selected position is legal for the entity.
If both checks succeeded,
is fired, which performs initialization on the newly-spawned entity.invalid reference
FinalizeSpawn
Finally, if the spawn was not cancelled via
, then invalid reference
FinalizeSpawn#setSpawnCancelled
EntityJoinLevelEvent
is fired as the entity enters the world.
is not related to the mob spawn event flow, as it fires when a despawn is attempted.invalid reference
AllowDespawn
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This event is fired when a mob checks for a valid spawn position, afterSpawnPlacements.checkSpawnRules(net.minecraft.world.entity.EntityType<T>, net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.entity.MobSpawnType, net.minecraft.core.BlockPos, net.minecraft.util.RandomSource)
has been evaluated.
Conditions validated here include the following: Obstruction - mobs inside blocks or fluids. Pathfinding - if the spawn block is valid for pathfinding. Sea Level - Ocelots check if the position is above sea level. Spawn Block - Ocelots check if the below block is grass or leaves.static class
This event is fired when Spawn Placements (aka Spawn Rules) are checked, before a mob attempts to spawn.
Spawn Placement checks include light levels, slime chunks, grass blocks for animals, and others in the same vein.
The purpose of this event is to permit runtime changes to any or all spawn placement logic without having to wrap the placement for each entity.Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ServerLevelAccessor
private final double
private final double
private final double
-
Constructor Summary
ModifierConstructorDescriptionprotected
MobSpawnEvent
(Mob mob, ServerLevelAccessor level, double x, double y, double z) -
Method Summary
-
Field Details
-
level
-
x
private final double x -
y
private final double y -
z
private final double z
-
-
Constructor Details
-
MobSpawnEvent
-
-
Method Details
-
getEntity
- Overrides:
getEntity
in classEntityEvent
-
getLevel
- Returns:
- The level relating to the mob spawn action
-
getX
public double getX()- Returns:
- The x-coordinate relating to the mob spawn action
-
getY
public double getY()- Returns:
- The y-coordinate relating to the mob spawn action
-
getZ
public double getZ()- Returns:
- The z-coordinate relating to the mob spawn action
-