From 65db290d7ab3fa16ea64be52a9b1ac29fe1ccbd3 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Fri, 3 Jan 2025 17:40:53 +0100 Subject: [PATCH 1/3] session/session.go: sendChunks: Always handle world change before move. Resolves #981. --- server/session/session.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/session/session.go b/server/session/session.go index a57d8053e..c64867cef 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -372,6 +372,9 @@ func (s *Session) background() { // sendChunks sends the next up to 4 chunks to the connection. What chunks are loaded depends on the connection of // the chunk loader and the chunks that were previously loaded. func (s *Session) sendChunks(tx *world.Tx, c Controllable) { + if w := tx.World(); s.chunkLoader.World() != w && w != nil { + s.handleWorldSwitch(w, tx, c) + } pos := c.Position() s.chunkLoader.Move(tx, pos) s.writePacket(&packet.NetworkChunkPublisherUpdate{ @@ -379,10 +382,6 @@ func (s *Session) sendChunks(tx *world.Tx, c Controllable) { Radius: uint32(s.chunkRadius) << 4, }) - if w := tx.World(); s.chunkLoader.World() != w && w != nil { - s.handleWorldSwitch(w, tx, c) - } - s.blobMu.Lock() const maxChunkTransactions = 8 toLoad := maxChunkTransactions - len(s.openChunkTransactions) From 3fa095d504173c10a97d75a580877db74919e52e Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Fri, 3 Jan 2025 10:48:37 -0800 Subject: [PATCH 2/3] block/note.go: Fix block break drop including Pitch Closes #854 --- server/block/note.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/block/note.go b/server/block/note.go index 4f5d901d1..0d1c40bae 100644 --- a/server/block/note.go +++ b/server/block/note.go @@ -59,7 +59,7 @@ func (n Note) Activate(pos cube.Pos, _ cube.Face, tx *world.Tx, _ item.User, _ * // BreakInfo ... func (n Note) BreakInfo() BreakInfo { - return newBreakInfo(0.8, alwaysHarvestable, axeEffective, oneOf(n)) + return newBreakInfo(0.8, alwaysHarvestable, axeEffective, oneOf(Note{})) } // FuelInfo ... From 96fa5e0d19ecd6162607bf8685e500c943910b20 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Fri, 3 Jan 2025 22:39:00 +0100 Subject: [PATCH 3/3] block/explosion.go: Perform proper bbox ray traces for entity explosion exposure. Resolves #709. --- server/block/explosion.go | 24 +++++++++--------------- server/world/world.go | 17 +++++++---------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/server/block/explosion.go b/server/block/explosion.go index d2f6da3f6..de4495365 100644 --- a/server/block/explosion.go +++ b/server/block/explosion.go @@ -153,14 +153,9 @@ func (c ExplosionConfig) Explode(tx *world.Tx, explosionPos mgl64.Vec3) { tx.SetBlock(pairPos, pair, nil) } } - - for _, i := range cb.Inventory(tx, pos).Clear() { - dropItem(tx, i, pos.Vec3()) - } - } else { - for _, i := range container.Inventory(tx, pos).Clear() { - dropItem(tx, i, pos.Vec3()) - } + } + for _, i := range container.Inventory(tx, pos).Clear() { + dropItem(tx, i, pos.Vec3()) } } } @@ -195,7 +190,7 @@ func exposure(tx *world.Tx, origin mgl64.Vec3, e world.Entity) float64 { xOffset := (1.0 - math.Floor(diff[0])/diff[0]) / 2.0 zOffset := (1.0 - math.Floor(diff[2])/diff[2]) / 2.0 - var checks, misses int + var checks, misses float64 for x := 0.0; x <= 1.0; x += step[0] { for y := 0.0; y <= 1.0; y += step[1] { for z := 0.0; z <= 1.0; z += step[2] { @@ -204,13 +199,12 @@ func exposure(tx *world.Tx, origin mgl64.Vec3, e world.Entity) float64 { lerp(y, boxMin[1], boxMax[1]), lerp(z, boxMin[2], boxMax[2]) + zOffset, } - var collided bool - trace.TraverseBlocks(origin, point, func(pos cube.Pos) (con bool) { - _, air := tx.Block(pos).(Air) - collided = !air - return air + trace.TraverseBlocks(origin, point, func(pos cube.Pos) (cont bool) { + _, collided = trace.BlockIntercept(pos, tx, tx.Block(pos), origin, point) + return !collided }) + if !collided { misses++ } @@ -218,7 +212,7 @@ func exposure(tx *world.Tx, origin mgl64.Vec3, e world.Entity) float64 { } } } - return float64(misses) / float64(checks) + return misses / checks } // lerp returns the linear interpolation between a and b at t. diff --git a/server/world/world.go b/server/world/world.go index 6e398cf03..837048b60 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -4,23 +4,20 @@ import ( "encoding/binary" "errors" "fmt" - "iter" - "maps" - "math/rand/v2" - "sync" - "time" - - "github.com/df-mc/goleveldb/leveldb" - - "slices" - "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/internal/sliceutil" "github.com/df-mc/dragonfly/server/world/chunk" + "github.com/df-mc/goleveldb/leveldb" "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" + "iter" + "maps" + "math/rand/v2" + "slices" + "sync" "sync/atomic" + "time" ) // World implements a Minecraft world. It manages all aspects of what players