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

public static class MobSpawnEvent.PositionCheck extends MobSpawnEvent
This event is fired when a mob checks for a valid spawn position, after 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.

  • 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 underlying BaseSpawner instance if this mob was created by a Mob Spawner of some form. This is always null unless getSpawnType() is EntitySpawnReason.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:
      • EntitySpawnReason
    • setResult

      public void setResult(MobSpawnEvent.PositionCheck.Result result)
      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