Skip to content

Commit

Permalink
Revert "fix names & Bed.Head trouble"
Browse files Browse the repository at this point in the history
This reverts commit 737c961.

I'm stupid
  • Loading branch information
FDUTCH committed Jan 13, 2025
1 parent 737c961 commit 3cbaf46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
30 changes: 9 additions & 21 deletions server/block/bed.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (Bed) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool {

// BreakInfo ...
func (b Bed) BreakInfo() BreakInfo {
return newBreakInfo(0.2, alwaysHarvestable, nothingEffective, oneOf(b)).withBreakHandler(func(pos cube.Pos, tx *world.Tx, _ item.User) {
headSide, _, ok := b.head(pos, tx)
return newBreakInfo(0.2, alwaysHarvestable, nothingEffective, oneOf(b)).withBreakHandler(func(pos cube.Pos, w *world.Tx, _ item.User) {
headSide, _, ok := b.head(pos, w)
if !ok {
return
}
Expand Down Expand Up @@ -201,8 +201,8 @@ func (b Bed) DecodeNBT(data map[string]interface{}) interface{} {
}

// head returns the head side of the bed. If neither side is a head side, the third return value is false.
func (b Bed) head(pos cube.Pos, tx *world.Tx) (Bed, cube.Pos, bool) {
headSide, headPos, ok := b.side(pos, tx)
func (b Bed) head(pos cube.Pos, w *world.Tx) (Bed, cube.Pos, bool) {
headSide, headPos, ok := b.side(pos, w)
if !ok {
return Bed{}, cube.Pos{}, false
}
Expand All @@ -213,14 +213,14 @@ func (b Bed) head(pos cube.Pos, tx *world.Tx) (Bed, cube.Pos, bool) {
}

// side returns the other side of the bed. If the other side is not a bed, the third return value is false.
func (b Bed) side(pos cube.Pos, tx *world.Tx) (Bed, cube.Pos, bool) {
func (b Bed) side(pos cube.Pos, w *world.Tx) (Bed, cube.Pos, bool) {
face := b.Facing.Face()
if b.Head {
face = face.Opposite()
}

sidePos := pos.Side(face)
o, ok := tx.Block(sidePos).(Bed)
o, ok := w.Block(sidePos).(Bed)
return o, sidePos, ok
}

Expand All @@ -237,19 +237,7 @@ func (Bed) CanRespawnOn() bool {
return true
}

func (Bed) RespawnOn(pos cube.Pos, u item.User, tx *world.Tx) {}

// SleepOn called to set Bed.Head if succeed startSleeping called.
func (b Bed) SleepOn(pos cube.Pos, sleeper world.Sleeper, tx *world.Tx, startSleeping func() bool) {
head, headPos, ok := b.head(pos, tx)
if !ok {
return
}
if startSleeping() {
head.Sleeper = sleeper.H()
tx.SetBlock(headPos, head, nil)
}
}
func (Bed) RespawnOn(pos cube.Pos, u item.User, w *world.Tx) {}

// RespawnBlock represents a block using which player can set his spawn point.
type RespawnBlock interface {
Expand All @@ -260,7 +248,7 @@ type RespawnBlock interface {
}

// supportedFromBelow ...
func supportedFromBelow(pos cube.Pos, tx *world.Tx) bool {
func supportedFromBelow(pos cube.Pos, w *world.Tx) bool {
below := pos.Side(cube.FaceDown)
return tx.Block(below).Model().FaceSolid(below, cube.FaceUp, tx)
return w.Block(below).Model().FaceSolid(below, cube.FaceUp, w)
}
31 changes: 14 additions & 17 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,28 +1205,25 @@ func (p *Player) Sleep(pos cube.Pos) {
}

ctx, sendReminder := event.C(p), true
if p.Handler().HandleSleep(ctx, &sendReminder); ctx.Cancelled() {
return
}

b.SleepOn(pos, p, p.tx, func() bool {
if p.Handler().HandleSleep(ctx, &sendReminder); ctx.Cancelled() {
return false
}

p.sleeping = true

tx.World().SetRequiredSleepDuration(time.Second * 5)
b.Sleeper = p.H()
tx.SetBlock(pos, b, nil)

p.data.Pos = pos.Vec3Middle().Add(mgl64.Vec3{0, 0.5625})
p.sleepPos = pos
tx.World().SetRequiredSleepDuration(time.Second * 5)

if sendReminder {
tx.BroadcastSleepingReminder(p)
}
p.data.Pos = pos.Vec3Middle().Add(mgl64.Vec3{0, 0.5625})
p.sleeping = true
p.sleepPos = pos

tx.BroadcastSleepingIndicator()
p.updateState()
return true
})
if sendReminder {
tx.BroadcastSleepingReminder(p)
}

tx.BroadcastSleepingIndicator()
p.updateState()
}

// Wake forces the player out of bed if they are sleeping.
Expand Down

0 comments on commit 3cbaf46

Please sign in to comment.