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 --- mcmap/chunk.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'mcmap') 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