Class MobSpawnEvent.SpawnPlacementCheck

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.living.MobSpawnEvent.SpawnPlacementCheck
Enclosing class:
MobSpawnEvent

public static class MobSpawnEvent.SpawnPlacementCheck extends net.neoforged.bus.api.Event
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.

This event is only fired on the logical server.

This event is not fired for mob spawners which utilize SpawnData.CustomSpawnRules, as they do not check spawn placements.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
     
    private final net.minecraft.world.entity.EntityType<?>
     
    private final net.minecraft.world.level.ServerLevelAccessor
     
    private final net.minecraft.core.BlockPos
     
    private final net.minecraft.util.RandomSource
     
     
    private final net.minecraft.world.entity.EntitySpawnReason
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpawnPlacementCheck(net.minecraft.world.entity.EntityType<?> entityType, net.minecraft.world.level.ServerLevelAccessor level, net.minecraft.world.entity.EntitySpawnReason spawnType, net.minecraft.core.BlockPos pos, net.minecraft.util.RandomSource random, boolean defaultResult)
    Internal.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    The default vanilla result is useful if an additional check wants to force
    invalid reference
    Result#ALLOW
    only if the vanilla check would succeed.
    net.minecraft.world.entity.EntityType<?>
     
    net.minecraft.world.level.ServerLevelAccessor
     
    boolean
    Returns If the placement check will succeed or not, based on the current event result.
    net.minecraft.core.BlockPos
     
    net.minecraft.util.RandomSource
    In all vanilla cases, this is equal to LevelAccessor.getRandom().
    Returns the result of this event, which controls if the placement check will succeed.
    net.minecraft.world.entity.EntitySpawnReason
    Retrieves the type of mob spawn that is happening.
    void
    Changes the result of this event.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • entityType

      private final net.minecraft.world.entity.EntityType<?> entityType
    • level

      private final net.minecraft.world.level.ServerLevelAccessor level
    • spawnType

      private final net.minecraft.world.entity.EntitySpawnReason spawnType
    • pos

      private final net.minecraft.core.BlockPos pos
    • random

      private final net.minecraft.util.RandomSource random
    • defaultResult

      private final boolean defaultResult
    • result

  • Constructor Details

    • SpawnPlacementCheck

      @Internal public SpawnPlacementCheck(net.minecraft.world.entity.EntityType<?> entityType, net.minecraft.world.level.ServerLevelAccessor level, net.minecraft.world.entity.EntitySpawnReason spawnType, net.minecraft.core.BlockPos pos, net.minecraft.util.RandomSource random, boolean defaultResult)
      Internal.
  • Method Details

    • getEntityType

      public net.minecraft.world.entity.EntityType<?> getEntityType()
      Returns:
      The type of entity that checks are being performed for.
    • getLevel

      public net.minecraft.world.level.ServerLevelAccessor getLevel()
      Returns:
      The level relating to the mob spawn action
    • 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
    • getPos

      public net.minecraft.core.BlockPos getPos()
      Returns:
      The position where checks are being evaluated.
    • getRandom

      public net.minecraft.util.RandomSource getRandom()
      In all vanilla cases, this is equal to LevelAccessor.getRandom().
      Returns:
      The random source being used.
    • getDefaultResult

      public boolean getDefaultResult()
      The default vanilla result is useful if an additional check wants to force
      invalid reference
      Result#ALLOW
      only if the vanilla check would succeed.
      Returns:
      The result of the vanilla spawn placement check.
    • setResult

      public void setResult(MobSpawnEvent.SpawnPlacementCheck.Result result)
      Changes the result of this event.
    • getResult

      Returns the result of this event, which controls if the placement check will succeed.
      Returns:
      the result of this event, which controls if the placement check will succeed
    • getPlacementCheckResult

      public boolean getPlacementCheckResult()
      Returns If the placement check will succeed or not, based on the current event result.
      Returns:
      If the placement check will succeed or not, based on the current event result