Class PlayerRespawnPositionEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.player.PlayerEvent
net.neoforged.neoforge.event.entity.player.PlayerRespawnPositionEvent
Fired by
is called.
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)
This event is only fired on the logical server.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemSmeltedEvent, PlayerEvent.LoadFromFile, PlayerEvent.NameFormat, PlayerEvent.PlayerChangedDimensionEvent, PlayerEvent.PlayerChangeGameModeEvent, PlayerEvent.PlayerLoggedInEvent, PlayerEvent.PlayerLoggedOutEvent, PlayerEvent.PlayerRespawnEvent, PlayerEvent.SaveToFile, PlayerEvent.StartTracking, PlayerEvent.StopTracking, PlayerEvent.TabListNameFormat
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
private final boolean
private final float
private final ServerLevel
private final @Nullable Vec3
private float
private ServerLevel
private @Nullable Vec3
-
Constructor Summary
ConstructorDescriptionPlayerRespawnPositionEvent
(ServerPlayer player, ServerLevel respawnLevel, float respawnAngle, @Nullable Vec3 respawnPosition, boolean fromEndFight) -
Method Summary
Modifier and TypeMethodDescriptionboolean
float
@Nullable Vec3
float
@Nullable Vec3
boolean
void
setChangePlayerSpawnPosition
(boolean changePlayerSpawnPosition) Set whether the respawn position will be used as the player's spawn position from then on.void
setRespawnAngle
(float respawnAngle) Set the angle the player will face when they respawn.void
setRespawnLevel
(ResourceKey<Level> respawnLevelResourceKey) Set the level the player will respawn into using aResourceKey
.void
setRespawnLevel
(ServerLevel respawnLevel) Set the level the player will respawn into.void
setRespawnPosition
(@Nullable Vec3 respawnPosition) Set the player's respawn position within the respawn level.Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
getEntity
-
Field Details
-
respawnLevel
-
respawnPosition
-
respawnAngle
private float respawnAngle -
originalRespawnLevel
-
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
- Returns:
- The level the player will respawn into.
-
setRespawnLevel
Set the level the player will respawn into.- Parameters:
respawnLevel
- The new level.
-
setRespawnLevel
Set the level the player will respawn into using aResourceKey
.- Parameters:
respawnLevelResourceKey
- TheResourceKey
of the level to respawn into.
-
getOriginalRespawnLevel
- Returns:
- The level the server originally intended to respawn the player into.
-
getRespawnPosition
- Returns:
- The position in the target level where the player will respawn, before any adjustments by the server.
-
setRespawnPosition
Set the player's respawn position within the respawn level. The server automatically adjusts this position to not be inside blocks. Ifnull
, the server will use the default spawn position for the level.- Parameters:
respawnPosition
-
-
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 istrue
.
-
setChangePlayerSpawnPosition
public void setChangePlayerSpawnPosition(boolean changePlayerSpawnPosition) Set whether the respawn position will be used as the player's spawn position from then on. Defaults totrue
.PlayerSetSpawnEvent
will be fired if this istrue
.- 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:
-