diff --git a/infiniteworld.py b/infiniteworld.py index 00ce859..5af358d 100644 --- a/infiniteworld.py +++ b/infiniteworld.py @@ -758,7 +758,9 @@ class InfdevChunk(EntityLevel): def isCompressed(self): return self.isLoaded() and self.root_tag == None - + def generateHeightMap(self): + extractLightMap(self.materials, self.Blocks, self.HeightMap) + def chunkChanged(self, calcLighting=True): """ You are required to call this function after you are done modifying the chunk. Pass False for calcLighting if you know your changes will @@ -770,7 +772,7 @@ class InfdevChunk(EntityLevel): self.dirty = True; self.needsLighting = calcLighting or self.needsLighting; - generateHeightMap(self); + self.generateHeightMap(); if calcLighting: self.genFastLights() @@ -910,19 +912,6 @@ class InfdevChunk(EntityLevel): ores and vegetation on next load""" self.root_tag[Level]["TerrainPopulated"].value = val; -def generateHeightMap(self): - self.load(); - - blocks = self.Blocks - heightMap = self.HeightMap - heightMap[:] = 0; - - lightAbsorption = self.world.materials.lightAbsorption[blocks] - axes = lightAbsorption.nonzero() - heightMap[axes[1], axes[0]] = axes[2]; #assumes the y-indices come out in increasing order - heightMap += 1; - - class dequeset(object): def __init__(self): self.deque = deque(); diff --git a/level.py b/level.py index 6a55246..b3ca552 100644 --- a/level.py +++ b/level.py @@ -9,6 +9,21 @@ from mclevelbase import * import tempfile from collections import defaultdict +def extractLightMap(materials, blocks, heightMap = None): + """Computes the HeightMap array for a chunk, which stores the lowest + y-coordinate of each column where the sunlight is still at full strength.""" + + if heightMap is None: + heightMap = zeros((16, 16), 'uint8') + + heightMap[:] = 0; + + lightAbsorption = materials.lightAbsorption[blocks] + axes = lightAbsorption.nonzero() + heightMap[axes[1], axes[0]] = axes[2]; #assumes the y-indices come out in increasing order + heightMap += 1; + return heightMap + class MCLevel(object): """ MCLevel is an abstract class providing many routines to the different level types, including a common copyEntitiesFrom built on class-specific routines, and @@ -143,7 +158,13 @@ class MCLevel(object): def chunkChanged(self):pass @property def materials(self): return self.world.materials - + @property + def HeightMap(self): + if hasattr(self, "_heightMap"): + return self._heightMap + + self._heightMap = extractLightMap(self.materials, self.Blocks) + return self._heightMap f = FakeChunk() f.world = self; f.chunkPosition = (cx, cz) diff --git a/mclevelbase.py b/mclevelbase.py index 33eed9a..042f40e 100644 --- a/mclevelbase.py +++ b/mclevelbase.py @@ -102,4 +102,4 @@ else: saveFileDir = os.path.join(minecraftDir, u"saves") -from level import MCLevel, EntityLevel +from level import MCLevel, EntityLevel, extractLightMap