Class PlayerRespawnPositionEvent


public class PlayerRespawnPositionEvent extends PlayerEvent
Fired by PlayerList.respawn(ServerPlayer, boolean) before the server respawns a player. This may be used to change the ServerLevel the player respawns in, as well as their respawn position. This event is fired after
invalid reference
BlockState#getRespawnPosition(EntityType, LevelReader, BlockPos, float, LivingEntity)
is called.

This event is only fired on the logical server.

  • Field Details

    • respawnLevel

      private ServerLevel respawnLevel
    • respawnPosition

      @Nullable private @Nullable Vec3 respawnPosition
    • respawnAngle

      private float respawnAngle
    • originalRespawnLevel

      private final ServerLevel originalRespawnLevel
    • originalRespawnPosition

      @Nullable private final @Nullable Vec3 originalRespawnPosition
    • originalRespawnAngle

      private final float originalRespawnAngle
    • fromEndFight

      private final boolean fromEndFight
    • changePlayerSpawnPosition

      private boolean changePlayerSpawnPosition
  • Constructor Details

    • PlayerRespawnPositionEvent

      public PlayerRespawnPositionEvent(ServerPlayer player, ServerLevel respawnLevel, float respawnAngle, @Nullable @Nullable Vec3 respawnPosition, boolean fromEndFight)
  • Method Details

    • getRespawnLevel

      public ServerLevel getRespawnLevel()
      Returns:
      The level the player will respawn into.
    • setRespawnLevel

      public void setRespawnLevel(ServerLevel respawnLevel)
      Set the level the player will respawn into.
      Parameters:
      respawnLevel - The new level.
    • setRespawnLevel

      public void setRespawnLevel(ResourceKey<Level> respawnLevelResourceKey)
      Set the level the player will respawn into using a ResourceKey.
      Parameters:
      respawnLevelResourceKey - The ResourceKey of the level to respawn into.
    • getOriginalRespawnLevel

      public ServerLevel getOriginalRespawnLevel()
      Returns:
      The level the server originally intended to respawn the player into.
    • getRespawnPosition

      @Nullable public @Nullable Vec3 getRespawnPosition()
      Returns:
      The position in the target level where the player will respawn, before any adjustments by the server.
    • setRespawnPosition

      public void setRespawnPosition(@Nullable @Nullable Vec3 respawnPosition)
      Set the player's respawn position within the respawn level. The server automatically adjusts this position to not be inside blocks. If null, the server will use the default spawn position for the level.
      Parameters:
      respawnPosition -
    • getOriginalRespawnPosition

      @Nullable public @Nullable Vec3 getOriginalRespawnPosition()
      Returns:
      The original position the server intended to respawn the player at.
    • getRespawnAngle

      public float getRespawnAngle()
      Returns:
      The angle the player will face when they respawn, before any modifications made by the server.
    • setRespawnAngle

      public void setRespawnAngle(float respawnAngle)
      Set the angle the player will face when they respawn. The server may adjust the angle, for example to face a bed if the player respawns there.
      Parameters:
      respawnAngle - The angle the player will face when they respawn.
    • getOriginalRespawnAngle

      public float getOriginalRespawnAngle()
      Returns:
      The original angle the server intended for the player to face when they respawn.
    • changePlayerSpawnPosition

      public boolean changePlayerSpawnPosition()
      Returns:
      Whether the respawn position will be used as the player's spawn position from then on. Defaults to true. PlayerSetSpawnEvent will be fired if this is true.
    • setChangePlayerSpawnPosition

      public void setChangePlayerSpawnPosition(boolean changePlayerSpawnPosition)
      Set whether the respawn position will be used as the player's spawn position from then on. Defaults to true. PlayerSetSpawnEvent will be fired if this is true.
      Parameters:
      changePlayerSpawnPosition - Whether to set the player's spawn position.
    • isFromEndFight

      public boolean isFromEndFight()
      Returns:
      Whether the respawn was triggered by the player jumping into the End return portal.
      See Also: