-
Notifications
You must be signed in to change notification settings - Fork 155
implement beds , respawn anchors #938
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
Open
FDUTCH
wants to merge
31
commits into
df-mc:master
Choose a base branch
from
FDUTCH:beds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
88f1a8f
implement beds , respawn anchors
FDUTCH 41e2831
run go generate
FDUTCH dea2dfd
remove hash methods in the files
FDUTCH 198ddfc
fix github Staticcheck
FDUTCH 0f9d7a2
remove useless comments
FDUTCH 20f6e1c
some fixes
FDUTCH 2c62bdb
fix int to int32 casting
FDUTCH ffc6f69
requested changes
FDUTCH 2ba7934
requested changes
FDUTCH 5342bc8
requested changes
FDUTCH c3ca7d0
requested changes
FDUTCH a29517f
Merge remote-tracking branch 'origin/master' into beds
FDUTCH 7c87c40
fix merge conflicts
FDUTCH 6716f5d
fix build
FDUTCH bce0754
fix formatting
FDUTCH 5d575de
Merge branch 'master' into beds
FDUTCH b0d783c
fix formatting
FDUTCH 3c06d62
requested changes
FDUTCH 0c1faf7
Merge branch 'master' into beds
FDUTCH 1adb42f
fix merge & update to use the translation changes
FDUTCH f884bfa
fix merge
FDUTCH ff3989d
Merge branch 'master' into beds
DaPigGuy 107d256
requested changes
FDUTCH 8df259d
use world.EntityHandle insted of world.Sleeper
FDUTCH ff6a673
requested changes
FDUTCH 456aeed
fix register.go
FDUTCH 737c961
fix names & Bed.Head trouble
FDUTCH 3cbaf46
Revert "fix names & Bed.Head trouble"
FDUTCH d6611c1
fix deadlocks
FDUTCH 726c857
Merge branch 'master' into beds
FDUTCH 9265cf0
Merge branch 'master' into beds
FDUTCH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
package block | ||
|
||
import ( | ||
"github.com/df-mc/dragonfly/server/block/cube" | ||
"github.com/df-mc/dragonfly/server/block/model" | ||
"github.com/df-mc/dragonfly/server/internal/nbtconv" | ||
"github.com/df-mc/dragonfly/server/item" | ||
"github.com/df-mc/dragonfly/server/world" | ||
"github.com/go-gl/mathgl/mgl64" | ||
"github.com/sandertv/gophertunnel/minecraft/text" | ||
) | ||
|
||
// Bed is a block, allowing players to sleep to set their spawns and skip the night. | ||
type Bed struct { | ||
transparent | ||
sourceWaterDisplacer | ||
|
||
// Colour is the colour of the bed. | ||
Colour item.Colour | ||
// Facing is the direction that the bed is Facing. | ||
Facing cube.Direction | ||
// Head is true if the bed is the head side. | ||
Head bool | ||
// User is the user that is using the bed. It is only set for the Head part of the bed. | ||
User item.User | ||
} | ||
|
||
// MaxCount always returns 1. | ||
func (Bed) MaxCount() int { | ||
return 1 | ||
} | ||
|
||
// Model ... | ||
func (Bed) Model() world.BlockModel { | ||
return model.Bed{} | ||
} | ||
|
||
// SideClosed ... | ||
func (Bed) SideClosed(cube.Pos, cube.Pos, *world.World) bool { | ||
FDUTCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false | ||
} | ||
|
||
// BreakInfo ... | ||
func (b Bed) BreakInfo() BreakInfo { | ||
return newBreakInfo(0.2, alwaysHarvestable, nothingEffective, oneOf(b)).withBreakHandler(func(pos cube.Pos, w *world.World, _ item.User) { | ||
headSide, _, ok := b.head(pos, w) | ||
if !ok { | ||
return | ||
} | ||
if s, ok := headSide.User.(world.Sleeper); ok { | ||
s.Wake() | ||
} | ||
}) | ||
} | ||
|
||
// UseOnBlock ... | ||
func (b Bed) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) { | ||
if pos, _, used = firstReplaceable(w, pos, face, b); !used { | ||
return | ||
} | ||
if _, ok := w.Block(pos.Side(cube.FaceDown)).Model().(model.Solid); !ok { | ||
FDUTCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
|
||
b.Facing = user.Rotation().Direction() | ||
|
||
side, sidePos := b, pos.Side(b.Facing.Face()) | ||
side.Head = true | ||
|
||
if !replaceableWith(w, sidePos, side) { | ||
return | ||
} | ||
if _, ok := w.Block(sidePos.Side(cube.FaceDown)).Model().(model.Solid); !ok { | ||
FDUTCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
|
||
ctx.IgnoreBBox = true | ||
place(w, sidePos, side, user, ctx) | ||
place(w, pos, b, user, ctx) | ||
return placed(ctx) | ||
} | ||
|
||
// Activate ... | ||
func (b Bed) Activate(pos cube.Pos, _ cube.Face, w *world.World, u item.User, _ *item.UseContext) bool { | ||
s, ok := u.(world.Sleeper) | ||
if !ok { | ||
return false | ||
} | ||
|
||
if w.Dimension() != world.Overworld { | ||
w.SetBlock(pos, nil, nil) | ||
ExplosionConfig{ | ||
Size: 5, | ||
SpawnFire: true, | ||
}.Explode(w, pos.Vec3Centre()) | ||
return true | ||
} | ||
|
||
_, sidePos, ok := b.side(pos, w) | ||
if !ok { | ||
return false | ||
} | ||
|
||
userPos := s.Position() | ||
if sidePos.Vec3Middle().Sub(userPos).Len() > 4 && pos.Vec3Middle().Sub(userPos).Len() > 4 { | ||
s.Messaget(text.Colourf("<grey>%%tile.bed.tooFar</grey>")) | ||
return true | ||
} | ||
|
||
headSide, headPos, ok := b.head(pos, w) | ||
if !ok { | ||
return false | ||
} | ||
if _, ok = w.Liquid(headPos); ok { | ||
return false | ||
} | ||
|
||
previousSpawn := w.PlayerSpawn(u.UUID()) | ||
if previousSpawn != pos { | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
w.SetPlayerSpawn(u.UUID(), pos) | ||
s.Messaget(text.Colourf("<grey>%%tile.bed.respawnSet</grey>")) | ||
} | ||
|
||
time := w.Time() % world.TimeFull | ||
if (time < world.TimeNight || time >= world.TimeSunrise) && !w.ThunderingAt(pos) { | ||
s.Messaget(text.Colourf("<grey>%%tile.bed.noSleep</grey>")) | ||
return true | ||
} | ||
if headSide.User != nil { | ||
s.Messaget(text.Colourf("<grey>%%tile.bed.occupied</grey>")) | ||
return true | ||
} | ||
|
||
s.Sleep(headPos) | ||
return true | ||
} | ||
|
||
// EntityLand ... | ||
func (b Bed) EntityLand(_ cube.Pos, _ *world.World, e world.Entity, distance *float64) { | ||
FDUTCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if s, ok := e.(sneakingEntity); ok && s.Sneaking() { | ||
// If the entity is sneaking, the fall distance and velocity stay the same. | ||
return | ||
} | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if _, ok := e.(fallDistanceEntity); ok { | ||
*distance *= 0.5 | ||
} | ||
if v, ok := e.(velocityEntity); ok { | ||
vel := v.Velocity() | ||
vel[1] = vel[1] * -3 / 4 | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
v.SetVelocity(vel) | ||
} | ||
} | ||
|
||
// sneakingEntity represents an entity that can sneak. | ||
type sneakingEntity interface { | ||
// Sneaking returns true if the entity is currently sneaking. | ||
Sneaking() bool | ||
} | ||
|
||
// velocityEntity represents an entity that can maintain a velocity. | ||
type velocityEntity interface { | ||
// Velocity returns the current velocity of the entity. | ||
Velocity() mgl64.Vec3 | ||
// SetVelocity sets the velocity of the entity. | ||
SetVelocity(mgl64.Vec3) | ||
} | ||
|
||
// NeighbourUpdateTick ... | ||
func (b Bed) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) { | ||
if _, _, ok := b.side(pos, w); !ok { | ||
w.SetBlock(pos, nil, nil) | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// EncodeItem ... | ||
func (b Bed) EncodeItem() (name string, meta int16) { | ||
return "minecraft:bed", int16(b.Colour.Uint8()) | ||
} | ||
|
||
// EncodeBlock ... | ||
func (b Bed) EncodeBlock() (name string, properties map[string]interface{}) { | ||
return "minecraft:bed", map[string]interface{}{ | ||
"facing_bit": int32(horizontalDirection(b.Facing)), | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"occupied_bit": boolByte(b.User != nil), | ||
"head_bit": boolByte(b.Head), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both the wiki and in-game commands call this "head_piece_bit" |
||
} | ||
} | ||
|
||
// EncodeNBT ... | ||
func (b Bed) EncodeNBT() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"id": "Bed", | ||
"color": b.Colour.Uint8(), | ||
} | ||
} | ||
|
||
// DecodeNBT ... | ||
func (b Bed) DecodeNBT(data map[string]interface{}) interface{} { | ||
b.Colour = item.Colours()[nbtconv.Uint8(data, "color")] | ||
return b | ||
} | ||
|
||
// 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, w *world.World) (Bed, cube.Pos, bool) { | ||
headSide, headPos, ok := b.side(pos, w) | ||
if !ok { | ||
return Bed{}, cube.Pos{}, false | ||
} | ||
if b.Head { | ||
headSide, headPos = b, pos | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return headSide, headPos, true | ||
} | ||
|
||
// 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, w *world.World) (Bed, cube.Pos, bool) { | ||
face := b.Facing.Face() | ||
if b.Head { | ||
face = face.Opposite() | ||
} | ||
|
||
sidePos := pos.Side(face) | ||
o, ok := w.Block(sidePos).(Bed) | ||
return o, sidePos, ok | ||
} | ||
|
||
// allBeds returns all possible beds. | ||
func allBeds() (beds []world.Block) { | ||
for _, d := range cube.Directions() { | ||
beds = append(beds, Bed{Facing: d}) | ||
beds = append(beds, Bed{Facing: d, Head: true}) | ||
} | ||
DaPigGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
|
||
func (Bed) CanSpawn() bool { | ||
return true | ||
} | ||
|
||
func (Bed) SpawnOn(pos cube.Pos, u item.User, w *world.World) {} | ||
|
||
// RespawnBlock represents a block using which player can set his spawn point. | ||
type RespawnBlock interface { | ||
// CanSpawn defines if player can use this block to respawn. | ||
CanSpawn() bool | ||
FDUTCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// SpawnOn is called when a player decides to respawn using this block. | ||
SpawnOn(pos cube.Pos, u item.User, w *world.World) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/df-mc/dragonfly/server/block/cube" | ||
"github.com/df-mc/dragonfly/server/world" | ||
) | ||
|
||
// Bed is a model used for beds. This model works for both parts of the bed. | ||
type Bed struct{} | ||
|
||
func (b Bed) BBox(cube.Pos, world.BlockSource) []cube.BBox { | ||
return []cube.BBox{cube.Box(0, 0, 0, 1, 0.5625, 1)} | ||
} | ||
|
||
// FaceSolid ... | ||
func (Bed) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { | ||
return false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.