Class EntitySleepEvents
These events can be categorized into three groups:
- Simple listeners:
START_SLEEPING
andSTOP_SLEEPING
- Predicates:
ALLOW_BED
,ALLOW_SLEEP_TIME
,ALLOW_RESETTING_TIME
,ALLOW_NEARBY_MONSTERS
,ALLOW_SETTING_SPAWN
andALLOW_SLEEPING
Note: Only the
ALLOW_BED
event applies to non-player entities. - Modifiers:
MODIFY_SLEEPING_DIRECTION
,SET_BED_OCCUPATION_STATE
andMODIFY_WAKE_UP_POSITION
Sleep events are useful for making custom bed blocks that do not extend BedBlock
.
Custom beds generally only need a custom ALLOW_BED
checker and a MODIFY_SLEEPING_DIRECTION
callback,
but the other events might be useful as well.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Event
<EntitySleepEvents.AllowBed> An event that is called to check whether a block is valid for sleeping.static final Event
<EntitySleepEvents.AllowNearbyMonsters> An event that checks whether players can sleep when monsters are nearby.static final Event
<EntitySleepEvents.AllowResettingTime> An event that checks whether a sleeping player counts into skipping the current day and resetting the time to 0.static final Event
<EntitySleepEvents.AllowSettingSpawn> An event that checks whether a player's spawn can be set when sleeping.static final Event
<EntitySleepEvents.AllowSleepTime> An event that checks whether the current time of day is valid for sleeping.static final Event
<EntitySleepEvents.AllowSleeping> An event that checks whether a player can start to sleep in a bed-like block.static final Event
<EntitySleepEvents.ModifySleepingDirection> An event that can be used to provide the entity's sleep direction if missing.static final Event
<EntitySleepEvents.ModifyWakeUpPosition> An event that can be used to provide the entity's wake-up position if missing.static final Event
<EntitySleepEvents.SetBedOccupationState> An event that sets the occupation state of a bed.static final Event
<EntitySleepEvents.StartSleeping> An event that is called when an entity starts to sleep.static final Event
<EntitySleepEvents.StopSleeping> An event that is called when an entity stops sleeping and wakes up. -
Method Summary
-
Field Details
-
ALLOW_SLEEPING
An event that checks whether a player can start to sleep in a bed-like block. This event only applies to sleeping usingPlayerEntity.trySleep(BlockPos)
.Note: Please use the more detailed events
ALLOW_SLEEP_TIME
andALLOW_NEARBY_MONSTERS
if they match your use case! This helps with mod compatibility.If this event returns a
PlayerEntity.SleepFailureReason
, it is used as the return value ofPlayerEntity.trySleep(BlockPos)
and sleeping fails. Anull
return value means that the player will start sleeping.When this event is called, all vanilla sleeping checks have already succeeded, i.e. this event is used in addition to vanilla checks. The more detailed events
ALLOW_SLEEP_TIME
andALLOW_NEARBY_MONSTERS
are also checked before this event. -
START_SLEEPING
An event that is called when an entity starts to sleep. -
STOP_SLEEPING
An event that is called when an entity stops sleeping and wakes up. -
ALLOW_BED
An event that is called to check whether a block is valid for sleeping.Used for checking whether the block at the current sleeping position is a valid bed block. If
false
, the player wakes up.This event is only checked during sleeping, so an entity can start sleeping on any block, but will immediately wake up if this check fails.
- See Also:
-
ALLOW_SLEEP_TIME
An event that checks whether the current time of day is valid for sleeping.Note that if sleeping during day time is allowed, the game will still reset the time to 0 if the usual conditions are met, unless forbidden with
ALLOW_RESETTING_TIME
. -
ALLOW_NEARBY_MONSTERS
An event that checks whether players can sleep when monsters are nearby.This event can also be used to force a failing result, meaning it can do custom monster checks.
-
ALLOW_RESETTING_TIME
An event that checks whether a sleeping player counts into skipping the current day and resetting the time to 0.When this event is called, all vanilla time resetting checks have already succeeded, i.e. this event is used in addition to vanilla checks.
-
MODIFY_SLEEPING_DIRECTION
An event that can be used to provide the entity's sleep direction if missing.This is useful for custom bed blocks that need to determine the sleeping direction themselves. If the block is not a
BedBlock
, you need to provide the sleeping direction manually with this event. -
ALLOW_SETTING_SPAWN
An event that checks whether a player's spawn can be set when sleeping.Vanilla always allows this operation.
-
SET_BED_OCCUPATION_STATE
An event that sets the occupation state of a bed.Note that this is not needed for blocks using
BedBlock
, which are handled automatically. -
MODIFY_WAKE_UP_POSITION
An event that can be used to provide the entity's wake-up position if missing.This is useful for custom bed blocks that need to determine the wake-up position themselves. If the block is not a
BedBlock
, you need to provide the wake-up position manually with this event.
-