Class MobSpawnEvent
java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.event.entity.EntityEvent
net.minecraftforge.event.entity.living.MobSpawnEvent
- Direct Known Subclasses:
MobSpawnEvent.AllowDespawn
,MobSpawnEvent.FinalizeSpawn
,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, MobSpawnEvent.FinalizeSpawn
is fired, which performs initialization on the newly-spawned entity.
Finally, if the spawn was not cancelled via MobSpawnEvent.FinalizeSpawn.setSpawnCancelled(boolean)
, then EntityJoinLevelEvent
is fired as the entity enters the world.
MobSpawnEvent.AllowDespawn
is not related to the mob spawn event flow, as it fires when a despawn is attempted.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This event is fired fromMob.checkDespawn()
.
It fires once per tick per mob that is attempting to despawn.
It is not fired if the mob is persistent (meaning it may not despawn).static class
This event is fired beforeMob.finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.MobSpawnType, net.minecraft.world.entity.SpawnGroupData, net.minecraft.nbt.CompoundTag)
is called.
This allows mods to control mob initialization.
In vanilla code, this event is injected by a transformer and not via patch, so calls cannot be traced via call hierarchy (it is not source-visible).static 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.minecraftforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.EyeHeight, EntityEvent.Size
Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event
net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
-
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
Methods inherited from class net.minecraftforge.eventbus.api.Event
getListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult
-
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
-