Class MobSpawnEvent.PositionCheck
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.MobSpawnEvent
net.neoforged.neoforge.event.entity.living.MobSpawnEvent.PositionCheck
- Enclosing class:
MobSpawnEvent
This event is fired when a mob checks for a valid spawn position, after
Conditions validated here include the following:
SpawnPlacements.checkSpawnRules(net.minecraft.world.entity.EntityType<T>, net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.entity.EntitySpawnReason, 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.
This event is only fired on the logical server.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.MobSpawnEvent
MobSpawnEvent.PositionCheck, MobSpawnEvent.SpawnPlacementCheck
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @Nullable net.minecraft.world.level.BaseSpawner
private final net.minecraft.world.entity.EntitySpawnReason
-
Constructor Summary
ConstructorsConstructorDescriptionPositionCheck
(net.minecraft.world.entity.Mob mob, net.minecraft.world.level.ServerLevelAccessor level, net.minecraft.world.entity.EntitySpawnReason spawnType, @Nullable net.minecraft.world.level.BaseSpawner spawner) -
Method Summary
Modifier and TypeMethodDescriptionReturns the result of this event, which controls if the position check will succeed.@Nullable net.minecraft.world.level.BaseSpawner
Retrieves the underlyingBaseSpawner
instance if this mob was created by a Mob Spawner of some form.net.minecraft.world.entity.EntitySpawnReason
Retrieves the type of mob spawn that is happening.void
Changes the result of this event.
-
Field Details
-
spawner
@Nullable private final @Nullable net.minecraft.world.level.BaseSpawner spawner -
spawnType
private final net.minecraft.world.entity.EntitySpawnReason spawnType -
result
-
-
Constructor Details
-
PositionCheck
public PositionCheck(net.minecraft.world.entity.Mob mob, net.minecraft.world.level.ServerLevelAccessor level, net.minecraft.world.entity.EntitySpawnReason spawnType, @Nullable @Nullable net.minecraft.world.level.BaseSpawner spawner)
-
-
Method Details
-
getSpawner
@Nullable public @Nullable net.minecraft.world.level.BaseSpawner getSpawner()Retrieves the underlyingBaseSpawner
instance if this mob was created by a Mob Spawner of some form. This is always null unlessgetSpawnType()
isEntitySpawnReason.SPAWNER
, and may still be null even then.- Returns:
- The BaseSpawner responsible for triggering the spawn, or null if none is available.
-
getSpawnType
public net.minecraft.world.entity.EntitySpawnReason getSpawnType()Retrieves the type of mob spawn that is happening.- Returns:
- The mob spawn type.
- See Also:
-
setResult
Changes the result of this event. -
getResult
Returns the result of this event, which controls if the position check will succeed.- Returns:
- the result of this event, which controls if the position check will succeed
-