diff --git a/bot/world/chunk.go b/bot/world/chunk.go index 9e71d3e..43cfa8b 100644 --- a/bot/world/chunk.go +++ b/bot/world/chunk.go @@ -112,7 +112,7 @@ func (d *directSection) SetBlock(x, y, z int, s BlockStatus) { padding := offset % 64 const maxUint64 = 1<<64 - 1 mask := uint64(maxUint64<<(padding+d.bpb) | (1< 64-d.bpb { l := padding - (64 - d.bpb) d.data[offset/64+1] = d.data[offset/64+1]&(maxUint64<>(64-padding) diff --git a/bot/world/chunk_test.go b/bot/world/chunk_test.go new file mode 100644 index 0000000..2878501 --- /dev/null +++ b/bot/world/chunk_test.go @@ -0,0 +1,48 @@ +package world + +import ( + "github.com/Tnze/go-mc/data" + "math/rand" + "testing" +) + +func newDirectSection(bpb int) *directSection { + return &directSection{ + bpb: bpb, + data: make([]uint64, 16*16*16*bpb/64), + } +} + +func TestDirectSection(t *testing.T) { + for bpb := 3; bpb <= data.BitsPerBlock; bpb++ { + s := newDirectSection(bpb) + for _, dataset := range [][16 * 16 * 16]BlockStatus{secData(bpb), randData(bpb)} { + for i := 0; i < 16*16*16; i++ { + s.SetBlock(i%16, i/16%16, i/16/16, dataset[i]) + } + for i := 0; i < 16*16*16; i++ { + if s := s.GetBlock(i%16, i/16%16, i/16/16); dataset[i] != s { + t.Fatalf("direct section error: want: %v, get %v", dataset[i], s) + } + } + } + } +} + +func secData(bpb int) (data [16 * 16 * 16]BlockStatus) { + mask := 1<