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,6 +135,7 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
case *packet.SubChunk:
w.processSubChunk(pk)
case *packet.BlockActorData:
if w.blockUpdates {
sp := protocol.SubChunkPos{pk.Position.X() << 4, 0, pk.Position.Z() << 4}
b, ok := w.blockNBT[sp]
if !ok {
@ -148,7 +149,9 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
}
}
}
}
case *packet.UpdateBlock:
if w.blockUpdates {
cp := protocol.ChunkPos{pk.Position.X() >> 4, pk.Position.Z() >> 4}
c, ok := w.chunks[cp]
if ok {
@ -156,13 +159,15 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
c.SetBlock(x, y, z, uint8(pk.Layer), pk.NewBlockRuntimeID)
w.mapUI.SetChunk(cp, w.chunks[cp], true)
}
}
case *packet.UpdateSubChunkBlocks:
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.EntityToBlockTransition {
if bce.SyncedUpdateType == packet.BlockToEntityTransition {
c.SetBlock(x, y, z, 0, world.AirRID())
} else {
c.SetBlock(x, y, z, 0, bce.BlockRuntimeID)
@ -171,5 +176,6 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
w.mapUI.SetChunk(cp, w.chunks[cp], true)
}
}
}
return pk
}

View File

@ -22,11 +22,12 @@ 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 {
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 {
@ -52,17 +53,14 @@ func blockColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) (blockColor color.R
}
return col
}
}
} else {
/*
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 blockColor
}
}
func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
haveUp := false
@ -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{
{
Overloads: []protocol.CommandOverload{{
Parameters: []protocol.CommandParameter{{
Name: "name",
Type: protocol.CommandArgTypeString,
Optional: false,
},
},
},
},
}},
}},
},
})