diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-12 12:50:57 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-12 12:50:57 +0200 |
commit | a44c4ad107a197a92e9ffdde38593fd7012a309e (patch) | |
tree | 8b9f1652f1fa516dd1cfed47c4f03187fbf00117 /mcmap/chunk.go | |
parent | b9be995232e8299d504e7898a9d6c5384664b8ee (diff) | |
download | gomcmap-a44c4ad107a197a92e9ffdde38593fd7012a309e.tar.gz gomcmap-a44c4ad107a197a92e9ffdde38593fd7012a309e.tar.bz2 gomcmap-a44c4ad107a197a92e9ffdde38593fd7012a309e.zip |
Writing maps implemented
Diffstat (limited to 'mcmap/chunk.go')
-rw-r--r-- | mcmap/chunk.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/mcmap/chunk.go b/mcmap/chunk.go index 22f9dfa..c504ae5 100644 --- a/mcmap/chunk.go +++ b/mcmap/chunk.go @@ -8,10 +8,17 @@ import ( func calcBlockOffset(x, y, z int) int { if (x < 0) || (y < 0) || (z < 0) || (x >= 16) || (y >= 256) || (z >= 16) { - panic(errors.New("Can't calculate Block offset, coordinates out of range.")) + return -1 } - return x + (z * 16) + (y * 256) + return x | (z << 4) | (y << 8) +} + +func offsetToPos(off int) (x, y, z int) { + x = off & 0xf + z = (off >> 4) & 0xf + y = (off >> 8) & 0xff + return } // BlockToChunk calculates the chunk (cx, cz) and the block position in this chunk(rbx, rbz) of a block position given global coordinates. @@ -36,17 +43,16 @@ type Chunk struct { x, z int32 - lastUpdate int64 - populated bool - inhabitatedTime int64 - ts time.Time + lastUpdate int64 + populated bool + inhabitedTime int64 + ts time.Time - heightMap []int32 // Note: Ordered ZX - blockLight, skyLight []byte // Note: Ordered YZX, only half-bytes + heightMap []int32 // Ordered ZX modified bool - blocks []Block // NOTE: Ordered YZX - biomes []Biome // NOTE: Orderes XZ + blocks []Block // Ordered YZX + biomes []Biome // Ordered XZ } // MarkModified needs to be called, if some data of the chunk was modified. |