rename generateHeightMap to extractLightMap and move it to level.py. call it from the new HeightMap property on FakeChunk (xxx flesh out FakeChunk)
This commit is contained in:
parent
d350d65f90
commit
fa88a3d83c
@ -758,6 +758,8 @@ 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
|
||||
@ -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();
|
||||
|
21
level.py
21
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)
|
||||
|
@ -102,4 +102,4 @@ else:
|
||||
|
||||
saveFileDir = os.path.join(minecraftDir, u"saves")
|
||||
|
||||
from level import MCLevel, EntityLevel
|
||||
from level import MCLevel, EntityLevel, extractLightMap
|
||||
|
Reference in New Issue
Block a user