diff --git a/bot/world/chunk.go b/bot/world/chunk.go index 5d339df..36fc3a1 100644 --- a/bot/world/chunk.go +++ b/bot/world/chunk.go @@ -103,11 +103,8 @@ type directSection struct { data []uint64 } -func (d *directSection) GetBlock(x, y, z int) BlockStatus { - // According to wiki.vg: Data Array is given for each block with increasing x coordinates, - // within rows of increasing z coordinates, within layers of increasing y coordinates. - // So offset equals to ( x*16^0 + z*16^1 + y*16^2 )*(bits per block). - offset := (x + z*16 + y*16*16) * d.bpb +func (d *directSection) GetBlock(offset int) BlockStatus { + offset *= d.bpb padding := offset % 64 block := uint32(d.data[offset/64] >> padding) if padding > 64-d.bpb { @@ -117,8 +114,8 @@ func (d *directSection) GetBlock(x, y, z int) BlockStatus { return BlockStatus(block & (1<>4]; sec != nil { - return sec.GetBlock(x&15, y&15, z&15) + return sec.GetBlock(SectionOffset(x&15, y&15, z&15)) } } return 0