Skip to content

Commit

Permalink
Merge branch 'master' into double-chest
Browse files Browse the repository at this point in the history
  • Loading branch information
RestartFU authored May 26, 2024
2 parents 08852f1 + 99f2abb commit 25c4e59
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/session/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,20 @@ func (s *Session) subChunkEntry(offset protocol.SubChunkOffset, ind int16, col *
return entry
}

// dimensionID returns the dimension ID of the world that the session is in.
func (s *Session) dimensionID() int32 {
d, _ := world.DimensionID(s.c.World().Dimension())
return int32(d)
}

// sendBlobHashes sends chunk blob hashes of the data of the chunk and stores the data in a map of blobs. Only
// data that the client doesn't yet have will be sent over the network.
func (s *Session) sendBlobHashes(pos world.ChunkPos, c *chunk.Chunk, blockEntities map[cube.Pos]world.Block) {
if subChunkRequests {
biomes := chunk.EncodeBiomes(c, chunk.NetworkEncoding)
if hash := xxhash.Sum64(biomes); s.trackBlob(hash, biomes) {
s.writePacket(&packet.LevelChunk{
Dimension: s.dimensionID(),
SubChunkCount: protocol.SubChunkRequestModeLimited,
Position: protocol.ChunkPos(pos),
HighestSubChunk: c.HighestFilledSubChunk(),
Expand Down Expand Up @@ -181,6 +188,7 @@ func (s *Session) sendBlobHashes(pos world.ChunkPos, c *chunk.Chunk, blockEntiti
}

s.writePacket(&packet.LevelChunk{
Dimension: s.dimensionID(),
Position: protocol.ChunkPos{pos.X(), pos.Z()},
SubChunkCount: count,
CacheEnabled: true,
Expand All @@ -193,6 +201,7 @@ func (s *Session) sendBlobHashes(pos world.ChunkPos, c *chunk.Chunk, blockEntiti
func (s *Session) sendNetworkChunk(pos world.ChunkPos, c *chunk.Chunk, blockEntities map[cube.Pos]world.Block) {
if subChunkRequests {
s.writePacket(&packet.LevelChunk{
Dimension: s.dimensionID(),
SubChunkCount: protocol.SubChunkRequestModeLimited,
Position: protocol.ChunkPos(pos),
HighestSubChunk: c.HighestFilledSubChunk(),
Expand Down Expand Up @@ -221,6 +230,7 @@ func (s *Session) sendNetworkChunk(pos world.ChunkPos, c *chunk.Chunk, blockEnti
}

s.writePacket(&packet.LevelChunk{
Dimension: s.dimensionID(),
Position: protocol.ChunkPos{pos.X(), pos.Z()},
SubChunkCount: uint32(len(data.SubChunks)),
RawPayload: append([]byte(nil), chunkBuf.Bytes()...),
Expand Down

0 comments on commit 25c4e59

Please sign in to comment.