Class PlayerSpawnPhantomsEvent


public class PlayerSpawnPhantomsEvent extends PlayerEvent
This event is fired from PhantomSpawner.tick(net.minecraft.server.level.ServerLevel, boolean, boolean) when phantoms would attempt to be spawned, with one event fired per player. It allows controlling if a spawn attempt will be made for the particular player, but cannot guarantee that a Phantom will be spawned.

This event is only fired on the logical server.

  • Field Details

  • Constructor Details

    • PlayerSpawnPhantomsEvent

      public PlayerSpawnPhantomsEvent(Player player, int phantomsToSpawn)
  • Method Details

    • getPhantomsToSpawn

      public int getPhantomsToSpawn()
      Returns:
      How many phantoms will be spawned, if spawning is successful. The default value is randomly generated.
    • setPhantomsToSpawn

      public void setPhantomsToSpawn(int phantomsToSpawn)
      Sets the number of phantoms to be spawned.
      Parameters:
      phantomsToSpawn - How many phantoms should spawn, given checks are passed.
    • setResult

      public void setResult(PlayerSpawnPhantomsEvent.Result result)
      Changes the result of this event, which controls if a spawn attempt will be made.
      See Also:
    • getResult

      public PlayerSpawnPhantomsEvent.Result getResult()
      Returns the result of this event, which controls if a spawn attempt will be made.
      See Also:
    • shouldSpawnPhantoms

      public boolean shouldSpawnPhantoms(ServerLevel level, BlockPos pos)
      Checks if a spawn attempt should be made by checking the current result and evaluating the vanilla conditions if necessary.

      Does not check DifficultyInstance.isHarderThan(float) or the player's Stats.TIME_SINCE_REST, as these are checked later.

      Parameters:
      level - The level that phantoms are being spawned in (the same level as the player)
      pos - The block position of the player
      Returns:
      true if a spawn attempt should be made