checkerboard chunk render

This commit is contained in:
olebeck 2023-03-27 14:11:40 +02:00
parent c5e7146f24
commit 94e02d677c
4 changed files with 82 additions and 82 deletions

View File

@ -135,40 +135,46 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
case *packet.SubChunk: case *packet.SubChunk:
w.processSubChunk(pk) w.processSubChunk(pk)
case *packet.BlockActorData: case *packet.BlockActorData:
sp := protocol.SubChunkPos{pk.Position.X() << 4, 0, pk.Position.Z() << 4} if w.blockUpdates {
b, ok := w.blockNBT[sp] sp := protocol.SubChunkPos{pk.Position.X() << 4, 0, pk.Position.Z() << 4}
if !ok { b, ok := w.blockNBT[sp]
w.blockNBT[sp] = []map[string]any{pk.NBTData} if !ok {
} else { w.blockNBT[sp] = []map[string]any{pk.NBTData}
for i, v := range b { } else {
x, y, z := v["x"].(int32), v["y"].(int32), v["z"].(int32) for i, v := range b {
if x == pk.Position.X() && y == pk.Position.Y() && z == pk.Position.Z() { x, y, z := v["x"].(int32), v["y"].(int32), v["z"].(int32)
b[i] = pk.NBTData if x == pk.Position.X() && y == pk.Position.Y() && z == pk.Position.Z() {
break b[i] = pk.NBTData
break
}
} }
} }
} }
case *packet.UpdateBlock: case *packet.UpdateBlock:
cp := protocol.ChunkPos{pk.Position.X() >> 4, pk.Position.Z() >> 4} if w.blockUpdates {
c, ok := w.chunks[cp] cp := protocol.ChunkPos{pk.Position.X() >> 4, pk.Position.Z() >> 4}
if ok { c, ok := w.chunks[cp]
x, y, z := blockPosInChunk(pk.Position) if ok {
c.SetBlock(x, y, z, uint8(pk.Layer), pk.NewBlockRuntimeID) x, y, z := blockPosInChunk(pk.Position)
w.mapUI.SetChunk(cp, w.chunks[cp], true) c.SetBlock(x, y, z, uint8(pk.Layer), pk.NewBlockRuntimeID)
w.mapUI.SetChunk(cp, w.chunks[cp], true)
}
} }
case *packet.UpdateSubChunkBlocks: case *packet.UpdateSubChunkBlocks:
cp := protocol.ChunkPos{pk.Position.X(), pk.Position.Z()} if w.blockUpdates {
c, ok := w.chunks[cp] cp := protocol.ChunkPos{pk.Position.X(), pk.Position.Z()}
if ok { c, ok := w.chunks[cp]
for _, bce := range pk.Blocks { if ok {
x, y, z := blockPosInChunk(bce.BlockPos) for _, bce := range pk.Blocks {
if bce.SyncedUpdateType == packet.EntityToBlockTransition { x, y, z := blockPosInChunk(bce.BlockPos)
c.SetBlock(x, y, z, 0, world.AirRID()) if bce.SyncedUpdateType == packet.BlockToEntityTransition {
} else { c.SetBlock(x, y, z, 0, world.AirRID())
c.SetBlock(x, y, z, 0, bce.BlockRuntimeID) } else {
c.SetBlock(x, y, z, 0, bce.BlockRuntimeID)
}
} }
w.mapUI.SetChunk(cp, w.chunks[cp], true)
} }
w.mapUI.SetChunk(cp, w.chunks[cp], true)
} }
} }
return pk return pk

View File

@ -22,46 +22,44 @@ func blockColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) (blockColor color.R
if y <= int16(c.Range().Min()) { if y <= int16(c.Range().Min()) {
return color.RGBA{0, 0, 0, 0} return color.RGBA{0, 0, 0, 0}
} }
blockColor = color.RGBA{255, 0, 255, 255}
rid := c.Block(x, y, z, 0) rid := c.Block(x, y, z, 0)
if rid == 0 && y == int16(c.Range().Min()) { // void if rid == 0 && y == int16(c.Range().Min()) { // void
blockColor = color.RGBA{0, 0, 0, 255} return color.RGBA{0, 0, 0, 255}
} else { }
b, found := world.BlockByRuntimeID(rid)
if found { blockColor = color.RGBA{255, 0, 255, 255}
if _, isWater := b.(block.Water); isWater { b, found := world.BlockByRuntimeID(rid)
// get the first non water block at the position if found {
heightBlock := c.HeightMap().At(x, z) if _, isWater := b.(block.Water); isWater {
depth := y - heightBlock // get the first non water block at the position
if depth > 0 { heightBlock := c.HeightMap().At(x, z)
blockColor = blockColorAt(c, x, heightBlock, z) depth := y - heightBlock
} if depth > 0 {
blockColor = blockColorAt(c, x, heightBlock, z)
// blend that blocks color with water depending on depth }
waterColor := (&block.Water{}).Color()
waterColor.A = uint8(utils.Clamp(int(150+depth*7), 255)) // blend that blocks color with water depending on depth
blockColor = utils.BlendColors(blockColor, waterColor) waterColor := (&block.Water{}).Color()
blockColor.R -= uint8(depth * 2) waterColor.A = uint8(utils.Clamp(int(150+depth*7), 255))
blockColor.G -= uint8(depth * 2) blockColor = utils.BlendColors(blockColor, waterColor)
blockColor.B -= uint8(depth * 2) blockColor.R -= uint8(depth * 2)
return blockColor blockColor.G -= uint8(depth * 2)
} else { blockColor.B -= uint8(depth * 2)
col := b.Color() return blockColor
if col.A != 255 { } else {
col = utils.BlendColors(blockColorAt(c, x, y-1, z), col) col := b.Color()
} if col.A != 255 {
return col col = utils.BlendColors(blockColorAt(c, x, y-1, z), col)
} }
} return col
/* }
if blockColor.R == 0 || blockColor.R == 255 && blockColor.B == 255 { } else {
name, nbt := b.EncodeBlock() /*
fmt.Printf("unknown color %d %s %s %s\n", rid, reflect.TypeOf(b), name, nbt) name, nbt := b.EncodeBlock()
b.Color() fmt.Printf("unknown color %d %s %s %s\n", rid, reflect.TypeOf(b), name, nbt)
} */
*/ return blockColor
} }
return blockColor
} }
func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA { func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
@ -84,7 +82,7 @@ func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
}, cube.Range{int(y + 1), int(y + 1)}) }, cube.Range{int(y + 1), int(y + 1)})
blockColor := blockColorAt(c, x, y, z) blockColor := blockColorAt(c, x, y, z)
if haveUp { if haveUp && (x+z)%2 == 0 {
if blockColor.R > 10 { if blockColor.R > 10 {
blockColor.R -= 10 blockColor.R -= 10
} }

View File

@ -201,14 +201,13 @@ func (s *entityState) ToServerEntity() serverEntity {
entityMetadataToNBT(s.Metadata, e.EntityType.NBT) entityMetadataToNBT(s.Metadata, e.EntityType.NBT)
if s.Helmet != nil || s.Chestplate != nil || s.Leggings != nil || s.Boots != nil { if s.Helmet != nil || s.Chestplate != nil || s.Leggings != nil || s.Boots != nil {
armor := make([]map[string]any, 0, 4) e.EntityType.NBT["Armor"] = []map[string]any{
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Helmet.Stack), true)) nbtconv.WriteItem(stackToItem(s.Helmet.Stack), true),
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Chestplate.Stack), true)) nbtconv.WriteItem(stackToItem(s.Chestplate.Stack), true),
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Leggings.Stack), true)) nbtconv.WriteItem(stackToItem(s.Leggings.Stack), true),
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Boots.Stack), true)) nbtconv.WriteItem(stackToItem(s.Boots.Stack), true),
e.EntityType.NBT["Armor"] = armor }
} }
return e return e
} }

View File

@ -67,6 +67,7 @@ type WorldState struct {
withPacks bool withPacks bool
saveImage bool saveImage bool
experimentInventory bool experimentInventory bool
blockUpdates bool
} }
func NewWorldState(ctx context.Context, proxy *utils.ProxyContext, ServerName string, ui utils.UI) *WorldState { func NewWorldState(ctx context.Context, proxy *utils.ProxyContext, ServerName string, ui utils.UI) *WorldState {
@ -596,17 +597,13 @@ func (w *WorldState) OnConnect(err error) bool {
Cmd: protocol.Command{ Cmd: protocol.Command{
Name: "setname", Name: "setname",
Description: locale.Loc("setname_desc", nil), Description: locale.Loc("setname_desc", nil),
Overloads: []protocol.CommandOverload{ Overloads: []protocol.CommandOverload{{
{ Parameters: []protocol.CommandParameter{{
Parameters: []protocol.CommandParameter{ Name: "name",
{ Type: protocol.CommandArgTypeString,
Name: "name", Optional: false,
Type: protocol.CommandArgTypeString, }},
Optional: false, }},
},
},
},
},
}, },
}) })