From 2ae88b10f49f328cdd996e6c16dc9bb7aafc198d Mon Sep 17 00:00:00 2001 From: Tnze Date: Thu, 21 May 2020 17:28:42 +0800 Subject: [PATCH] change API of Section from (x, y, z int) to (offset int) --- bot/world/chunk.go | 29 +++++++++++------------------ bot/world/chunk_test.go | 11 ++++------- bot/world/world.go | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 28 deletions(-) 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