Class CanPlayerSleepEvent
Fired when a player initially attempts to sleep. This can be used by mods to supplement or replace the vanilla logic for whether a sleep attempt is valid.
Mods which provide a AbstractBedBlock without the FACING property will almost
always need to use this event to provide their own logic, because the vanilla logic is modified to assume success
for those blocks.
This event is not cancellable.
This event is fired on the game event bus, only on the logical server.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemSmeltedEvent, PlayerEvent.ItemSmithedEvent, PlayerEvent.LoadFromFile, PlayerEvent.NameFormat, PlayerEvent.PlayerChangedDimensionEvent, PlayerEvent.PlayerChangeGameModeEvent, PlayerEvent.PlayerLoggedInEvent, PlayerEvent.PlayerLoggedOutEvent, PlayerEvent.PlayerRespawnEvent, PlayerEvent.SaveToFile, PlayerEvent.StartTracking, PlayerEvent.StopTracking, PlayerEvent.TabListNameFormatNested classes/interfaces inherited from class LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEventNested classes/interfaces inherited from class EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockPosprivate @Nullable Player.BedSleepingProblemprivate final BlockStateprivate final @Nullable Player.BedSleepingProblem -
Constructor Summary
ConstructorsConstructorDescriptionCanPlayerSleepEvent(ServerPlayer player, BlockPos pos, @Nullable Player.BedSleepingProblem problem) -
Method Summary
Modifier and TypeMethodDescriptiongetLevel()getPos()Returns the position of the bed block.Returns the current sleeping problem, ornullif there isn't any problem.getState()Returns the bed block state.Returns the sleeping problem provided by the vanilla logic, ornullif there isn't any problem.voidsetProblem(@Nullable Player.BedSleepingProblem problem) Sets a new sleeping problem, if any.
-
Field Details
-
pos
-
state
-
vanillaProblem
-
problem
-
-
Constructor Details
-
CanPlayerSleepEvent
public CanPlayerSleepEvent(ServerPlayer player, BlockPos pos, @Nullable Player.BedSleepingProblem problem)
-
-
Method Details
-
getEntity
- Overrides:
getEntityin classPlayerEvent
-
getLevel
-
getPos
Returns the position of the bed block.- Returns:
- the position of the bed block
-
getState
-
getProblem
Returns the current sleeping problem, ornullif there isn't any problem.- Returns:
- the current sleeping problem, or
nullif there isn't any problem
-
setProblem
Sets a new sleeping problem, if any. A
nullvalue means there is no sleeping problem, and the player is allowed to sleep.Mods should use a custom
Player.BedSleepingProblemwith an appropriate message if possible. Otherwise, the genericPlayer.BedSleepingProblem.OTHER_PROBLEMcan be used.- Parameters:
problem- the new sleeping problem, ornull
-
getVanillaProblem
Returns the sleeping problem provided by the vanilla logic, ornullif there isn't any problem.- Returns:
- the sleeping problem provided by the vanilla logic, or
nullif there isn't any problem
-