From e96bb91b82189d6bef0e4c188da7b9ef38ad6032 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Sun, 5 Dec 2010 01:35:12 -0500 Subject: [PATCH] Better handling of the biome tinting images. If they're not found with _find_file, then look in the EXTRACTEDBIOME folder in the worlddir. --- chunk.py | 2 +- textures.py | 34 ++++++++++++++++++++++------------ world.py | 4 ++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/chunk.py b/chunk.py index 8a22dff..bdfd062 100644 --- a/chunk.py +++ b/chunk.py @@ -503,7 +503,7 @@ class ChunkRenderer(object): tileEntities = get_tileentity_data(self.level) if self.world.useBiomeData: - biomeColorData = textures.prepareBiomeData(self.world.worlddir, + biomeColorData = textures.getBiomeData(self.world.worlddir, self.chunkX, self.chunkY) # in the 8x8 block of biome data, what chunk is this?l startX = (self.chunkX - int(math.floor(self.chunkX/8)*8)) diff --git a/textures.py b/textures.py index 5631dda..2356d6c 100644 --- a/textures.py +++ b/textures.py @@ -556,27 +556,37 @@ def prepareLeafTexture(color): img.paste(top, (0,0), top) return (img.convert("RGB"), img.split()[3]) -#useBiomeData = os.path.exists(os.path.join(self.world, EXTRACTEDBIOMES)) -#if not useBiomeData: -# logging.info("Notice: Not using biome data for tinting") -try: - grasscolor = list(Image.open(_find_file("grasscolor.png")).getdata()) - foliagecolor = list(Image.open(_find_file("foliagecolor.png")).getdata()) -except: - grasscolor = None - foliagecolor = None currentBiomeFile = None currentBiomeData = None -def prepareBiomeData(worlddir, chunkX, chunkY): + +def prepareBiomeData(worlddir): + biomeDir = os.path.join(worlddir, "EXTRACTEDBIOMES") + if not os.path.exists(biomeDir): + raise Exception("EXTRACTEDBIOMES not found") + + t = sys.modules[__name__] + + # try to find the biome color images. If _find_file can't locate them + # then try looking in the EXTRACTEDBIOMES folder + try: + t.grasscolor = list(Image.open(_find_file("grasscolor.png")).getdata()) + t.foliagecolor = list(Image.open(_find_file("foliagecolor.png")).getdata()) + except IOError: + try: + t.grasscolor = list(Image.open(os.path.join(biomeDir,"grasscolor.png")).getdata()) + t.foliagecolor = list(Image.open(os.path.join(biomeDir,"foliagecolor.png")).getdata()) + except: + t.grasscolor = None + t.foliagecolor = None + +def getBiomeData(worlddir, chunkX, chunkY): '''Opens the worlddir and reads in the biome color information from the .biome files. See also: http://www.minecraftforum.net/viewtopic.php?f=25&t=80902 ''' t = sys.modules[__name__] - if not os.path.exists(os.path.join(worlddir, "EXTRACTEDBIOMES")): - raise Exception("EXTRACTEDBIOMES not found") biomeFile = "%d.%d.biome" % ( int(math.floor(chunkX/8)*8), diff --git a/world.py b/world.py index 770c5ef..1165053 100644 --- a/world.py +++ b/world.py @@ -26,6 +26,7 @@ import numpy import chunk import nbt +import textures """ This module has routines related to generating all the chunks for a world @@ -102,6 +103,9 @@ class WorldRenderer(object): self.cachedir = cachedir self.useBiomeData = useBiomeData + if self.useBiomeData: + textures.prepareBiomeData(worlddir) + self.chunklist = chunklist # stores Points Of Interest to be mapped with markers