From 2263d599391cce82735f16f43b7907e8846cbb2a Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 12 Aug 2013 21:40:02 +0200 Subject: Implemented height map recalculation --- README.markdown | 1 - 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++ + } + } +} -- cgit v1.2.3-70-g09d2