Class MobSpawnEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.MobSpawnEvent
Direct Known Subclasses:
FinalizeSpawnEvent, MobDespawnEvent, MobSpawnEvent.PositionCheck

public abstract class MobSpawnEvent extends EntityEvent
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:

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,

invalid reference
FinalizeSpawn
is fired, which performs initialization on the newly-spawned entity.
Finally, if the spawn was not cancelled via
invalid reference
FinalizeSpawn#setSpawnCancelled
, then EntityJoinLevelEvent is fired as the entity enters the world.

invalid reference
AllowDespawn
is not related to the mob spawn event flow, as it fires when a despawn is attempted.
  • Field Details

    • level

      private final ServerLevelAccessor level
    • x

      private final double x
    • y

      private final double y
    • z

      private final double z
  • Constructor Details

    • MobSpawnEvent

      @Internal protected MobSpawnEvent(Mob mob, ServerLevelAccessor level, double x, double y, double z)
  • Method Details

    • getEntity

      public Mob getEntity()
      Overrides:
      getEntity in class EntityEvent
    • getLevel

      public ServerLevelAccessor 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