diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-12 21:40:02 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-12 21:40:02 +0200 |
commit | 2263d599391cce82735f16f43b7907e8846cbb2a (patch) | |
tree | 1b02d46fd8b4a2c2de83a959c96530d161728289 | |
parent | d9e1c3579e63cc0ab850ea3caa5324a0243150e2 (diff) | |
download | gomcmap-2263d599391cce82735f16f43b7907e8846cbb2a.tar.gz gomcmap-2263d599391cce82735f16f43b7907e8846cbb2a.tar.bz2 gomcmap-2263d599391cce82735f16f43b7907e8846cbb2a.zip |
Implemented height map recalculation
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | mcmap/chunk.go | 20 |
2 files changed, 19 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown index 3404f41..f343f81 100644 --- a/README.markdown +++ b/README.markdown @@ -22,6 +22,5 @@ Although I tested the library with some maps, I can't guarantee that everything * Adding / removing chunks. * Recalculating light data. -* Recalculating height map. * Reading and modifying level.dat and other files (currently only the region files are used). * Test compatibility with older versions of Minecraft. diff --git a/mcmap/chunk.go b/mcmap/chunk.go index 9cf2dc7..d11d24b 100644 --- a/mcmap/chunk.go +++ b/mcmap/chunk.go @@ -110,4 +110,22 @@ func (c *Chunk) SetBiome(x, z int, bio Biome) { c.biomes[x*ChunkSizeXZ+z] = bio // If the chunk was modified, call MarkModified BEFORE. func (c *Chunk) MarkUnused() error { return c.reg.unloadChunk(int(c.x), int(c.z)) } -// TODO: func (c *Chunk) RecalcHeightMap() +// RecalcHeightMap recalculates the internal height map. +// +// You should use this function before marking the chunk as unused, if you modified the chunk +// (unless you know, your changes wouldn't affect the height map). +func (c *Chunk) RecalcHeightMap() { + i := 0 + for z := 0; z < ChunkSizeXZ; z++ { + for x := 0; x < ChunkSizeXZ; x++ { + for y := ChunkSizeY; y >= 0; y-- { + blkid := c.blocks[calcBlockOffset(x, y, z)].ID + if (blkid != BlkAir) && (blkid != BlkGlass) && (blkid != BlkGlassPane) { + c.heightMap[i] = int32(y) + break + } + } + i++ + } + } +} |