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

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()) {
return color.RGBA{0, 0, 0, 0}
}
blockColor = color.RGBA{255, 0, 255, 255}
rid := c.Block(x, y, z, 0)
if rid == 0 && y == int16(c.Range().Min()) { // void
blockColor = color.RGBA{0, 0, 0, 255}
} else {
b, found := world.BlockByRuntimeID(rid)
if found {
if _, isWater := b.(block.Water); isWater {
// get the first non water block at the position
heightBlock := c.HeightMap().At(x, 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))
blockColor = utils.BlendColors(blockColor, waterColor)
blockColor.R -= uint8(depth * 2)
blockColor.G -= uint8(depth * 2)
blockColor.B -= uint8(depth * 2)
return blockColor
} else {
col := b.Color()
if col.A != 255 {
col = utils.BlendColors(blockColorAt(c, x, y-1, z), col)
}
return col
}
}
/*
if blockColor.R == 0 || blockColor.R == 255 && blockColor.B == 255 {
name, nbt := b.EncodeBlock()
fmt.Printf("unknown color %d %s %s %s\n", rid, reflect.TypeOf(b), name, nbt)
b.Color()
}
*/
return color.RGBA{0, 0, 0, 255}
}
blockColor = color.RGBA{255, 0, 255, 255}
b, found := world.BlockByRuntimeID(rid)
if found {
if _, isWater := b.(block.Water); isWater {
// get the first non water block at the position
heightBlock := c.HeightMap().At(x, 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))
blockColor = utils.BlendColors(blockColor, waterColor)
blockColor.R -= uint8(depth * 2)
blockColor.G -= uint8(depth * 2)
blockColor.B -= uint8(depth * 2)
return blockColor
} else {
col := b.Color()
if col.A != 255 {
col = utils.BlendColors(blockColorAt(c, x, y-1, z), col)
}
return col
}
} else {
/*
name, nbt := b.EncodeBlock()
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 {
@ -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)})
blockColor := blockColorAt(c, x, y, z)
if haveUp {
if haveUp && (x+z)%2 == 0 {
if blockColor.R > 10 {
blockColor.R -= 10
}

View File

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

View File

@ -67,6 +67,7 @@ type WorldState struct {
withPacks bool
saveImage bool
experimentInventory bool
blockUpdates bool
}
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{
Name: "setname",
Description: locale.Loc("setname_desc", nil),
Overloads: []protocol.CommandOverload{
{
Parameters: []protocol.CommandParameter{
{
Name: "name",
Type: protocol.CommandArgTypeString,
Optional: false,
},
},
},
},
Overloads: []protocol.CommandOverload{{
Parameters: []protocol.CommandParameter{{
Name: "name",
Type: protocol.CommandArgTypeString,
Optional: false,
}},
}},
},
})