@@ -42,8 +42,8 @@ func (Bed) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool {
42
42
43
43
// BreakInfo ...
44
44
func (b Bed ) BreakInfo () BreakInfo {
45
- return newBreakInfo (0.2 , alwaysHarvestable , nothingEffective , oneOf (b )).withBreakHandler (func (pos cube.Pos , w * world.Tx , _ item.User ) {
46
- headSide , _ , ok := b .head (pos , w )
45
+ return newBreakInfo (0.2 , alwaysHarvestable , nothingEffective , oneOf (b )).withBreakHandler (func (pos cube.Pos , tx * world.Tx , _ item.User ) {
46
+ headSide , _ , ok := b .head (pos , tx )
47
47
if ! ok {
48
48
return
49
49
}
@@ -201,8 +201,8 @@ func (b Bed) DecodeNBT(data map[string]interface{}) interface{} {
201
201
}
202
202
203
203
// head returns the head side of the bed. If neither side is a head side, the third return value is false.
204
- func (b Bed ) head (pos cube.Pos , w * world.Tx ) (Bed , cube.Pos , bool ) {
205
- headSide , headPos , ok := b .side (pos , w )
204
+ func (b Bed ) head (pos cube.Pos , tx * world.Tx ) (Bed , cube.Pos , bool ) {
205
+ headSide , headPos , ok := b .side (pos , tx )
206
206
if ! ok {
207
207
return Bed {}, cube.Pos {}, false
208
208
}
@@ -213,14 +213,14 @@ func (b Bed) head(pos cube.Pos, w *world.Tx) (Bed, cube.Pos, bool) {
213
213
}
214
214
215
215
// side returns the other side of the bed. If the other side is not a bed, the third return value is false.
216
- func (b Bed ) side (pos cube.Pos , w * world.Tx ) (Bed , cube.Pos , bool ) {
216
+ func (b Bed ) side (pos cube.Pos , tx * world.Tx ) (Bed , cube.Pos , bool ) {
217
217
face := b .Facing .Face ()
218
218
if b .Head {
219
219
face = face .Opposite ()
220
220
}
221
221
222
222
sidePos := pos .Side (face )
223
- o , ok := w .Block (sidePos ).(Bed )
223
+ o , ok := tx .Block (sidePos ).(Bed )
224
224
return o , sidePos , ok
225
225
}
226
226
@@ -237,7 +237,19 @@ func (Bed) CanRespawnOn() bool {
237
237
return true
238
238
}
239
239
240
- func (Bed ) RespawnOn (pos cube.Pos , u item.User , w * world.Tx ) {}
240
+ func (Bed ) RespawnOn (pos cube.Pos , u item.User , tx * world.Tx ) {}
241
+
242
+ // SleepOn called to set Bed.Head if succeed startSleeping called.
243
+ func (b Bed ) SleepOn (pos cube.Pos , sleeper world.Sleeper , tx * world.Tx , startSleeping func () bool ) {
244
+ head , headPos , ok := b .head (pos , tx )
245
+ if ! ok {
246
+ return
247
+ }
248
+ if startSleeping () {
249
+ head .Sleeper = sleeper .H ()
250
+ tx .SetBlock (headPos , head , nil )
251
+ }
252
+ }
241
253
242
254
// RespawnBlock represents a block using which player can set his spawn point.
243
255
type RespawnBlock interface {
@@ -248,7 +260,7 @@ type RespawnBlock interface {
248
260
}
249
261
250
262
// supportedFromBelow ...
251
- func supportedFromBelow (pos cube.Pos , w * world.Tx ) bool {
263
+ func supportedFromBelow (pos cube.Pos , tx * world.Tx ) bool {
252
264
below := pos .Side (cube .FaceDown )
253
- return w .Block (below ).Model ().FaceSolid (below , cube .FaceUp , w )
265
+ return tx .Block (below ).Model ().FaceSolid (below , cube .FaceUp , tx )
254
266
}
0 commit comments