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 SummaryNested ClassesModifier and TypeClassDescriptionstatic classThis 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 classThis 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 classThis 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 classThis 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.EntityEventEntityEvent.EnteringSection, EntityEvent.EntityConstructingNested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Eventnet.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final ServerLevelAccessorprivate final doubleprivate final doubleprivate final double
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedMobSpawnEvent(Mob mob, ServerLevelAccessor level, double x, double y, double z) 
- 
Method SummaryMethods inherited from class net.minecraftforge.eventbus.api.EventgetListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult
- 
Field Details- 
level
- 
xprivate final double x
- 
yprivate final double y
- 
zprivate final double z
 
- 
- 
Constructor Details- 
MobSpawnEvent
 
- 
- 
Method Details- 
getEntity- Overrides:
- getEntityin class- EntityEvent
 
- 
getLevel- Returns:
- The level relating to the mob spawn action
 
- 
getXpublic double getX()- Returns:
- The x-coordinate relating to the mob spawn action
 
- 
getYpublic double getY()- Returns:
- The y-coordinate relating to the mob spawn action
 
- 
getZpublic double getZ()- Returns:
- The z-coordinate relating to the mob spawn action
 
 
-