Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented beds #606

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open

Implemented beds #606

wants to merge 63 commits into from

Conversation

JustTalDevelops
Copy link
Member

@JustTalDevelops JustTalDevelops commented Jul 27, 2022

No description provided.

T14Raptor and others added 30 commits July 12, 2022 11:05
…/explosions

# Conflicts:
#	server/block/block.go
#	server/block/explosion.go
# Conflicts:
#	server/block/block.go
#	server/block/stone_bricks.go
@JustTalDevelops JustTalDevelops removed the awaiting response More information is required to resolve and/or close the issue label Jul 31, 2022
server/block/bed.go Outdated Show resolved Hide resolved
server/block/bed.go Outdated Show resolved Hide resolved
@DaPigGuy DaPigGuy requested a review from Sandertv August 2, 2022 01:24
# Conflicts:
#	server/block/register.go
#	server/player/player.go
#	server/session/entity_metadata.go
Copy link
Member

@Sandertv Sandertv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a couple of comments, some of which we already discussed in the VC.

server/block/bed.go Outdated Show resolved Hide resolved
server/block/bed.go Outdated Show resolved Hide resolved
server/block/bed.go Outdated Show resolved Hide resolved
server/block/bed.go Show resolved Hide resolved
server/player/handler.go Outdated Show resolved Hide resolved
server/session/entity_metadata.go Outdated Show resolved Hide resolved
w.SetBlock(pos, b, nil)
}

w.SetRequiredSleepDuration(time.Second * 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I fully understand why Player.Sleep() sets this to 5 seconds and Player.Wake() sets this to 0 seconds. Can this not just be something internal in World?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "something internal"? You must be sleeping in a bed for at least 5 seconds before the day progresses, and that cool down gets reset back to 5 every time someone else starts to sleep.

Copy link
Member

@Sandertv Sandertv Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean having only a (constant) required sleep duration in world's settings and updating/tracking how much longer must be slept inside of World automatically using an additional field, instead of having a SetRequiredSleepDuration.

Copy link
Member Author

@JustTalDevelops JustTalDevelops Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work though. The sleep duration is reset in vanilla if another player starts sleeping, or if a player stops and then starts sleeping. If you're suggesting we should make the default required sleep duration configurable via world settings, maybe, but that doesn't entirely make sense since vanilla doesn't support it anyway.

Comment on lines +56 to +59
if t.w.set.RequiredSleepTicks > 0 {
t.w.set.RequiredSleepTicks--
if t.w.set.RequiredSleepTicks-1 <= 0 {
sleep = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably keep t.w.set.RequiredSleepTicks static and just have a separate unexported field in World that you change. That way Player doesn't have to set the required sleep ticks to 5 seconds on sleep and 0 on wake, that can just be world internal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above conversation.

server/world/world.go Show resolved Hide resolved
server/world/world.go Outdated Show resolved Hide resolved
JustTalDevelops and others added 8 commits August 19, 2022 17:22
# Conflicts:
#	server/player/player.go
#	server/session/entity_metadata.go
#	server/session/handler_player_action.go
#	server/session/session.go
#	server/session/world.go
# Conflicts:
#	server/player/player.go
#	server/session/entity_metadata.go
#	server/session/handler_player_action.go
@DaPigGuy DaPigGuy self-requested a review December 16, 2022 20:35

sidePos := pos.Side(face)
o, ok := w.Block(sidePos).(Bed)
return o, sidePos, ok
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably check that only one side is the head

Suggested change
return o, sidePos, ok
return o, sidePos, ok && b.Head != o.Head


w := p.World()
if b, ok := w.Block(pos).(block.Bed); ok {
if b.User != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if b.User != nil {
if b.User != nil || !b.Head {

if sl, ok := e.(sleeper); ok {
if pos, ok := sl.Sleeping(); ok {
m[protocol.EntityDataKeyBedPosition] = blockPosToProtocol(pos)
m.SetFlag(protocol.EntityDataKeyPlayerFlags, protocol.EntityDataFlagSleeping)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protocol.EntityDataFlagSleeping was wrongly used here when merging changes from master branch

@@ -733,6 +743,8 @@ func (w *World) RemoveEntity(e Entity) {
viewers := slices.Clone(c.v)
c.Unlock()

w.tryAdvanceDay()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would bypass the 5 second timer if any entity were to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants