From 603e60bd0db6732466dc4d0ae72acb19592bfe91 Mon Sep 17 00:00:00 2001 From: joe-mojo Date: Fri, 23 Aug 2013 00:24:21 +0200 Subject: [PATCH 1/5] Fixed the way texture.py searched for foliage, grass and chests textures. This is a "quick-and-dirty fix", you may improve it as I'm novice in Python. Default files in data/textures have been renamed to reflect changes in new 1.6 texture packs (aka resource packs) --- .../textures/{enderchest.png => ender.png} | Bin .../{foliagecolor.png => foliage.png} | Bin .../textures/{grasscolor.png => grass.png} | Bin .../{largechest.png => normal_double.png} | Bin overviewer_core/textures.py | 25 +++++++++++++----- 5 files changed, 19 insertions(+), 6 deletions(-) rename overviewer_core/data/textures/{enderchest.png => ender.png} (100%) rename overviewer_core/data/textures/{foliagecolor.png => foliage.png} (100%) rename overviewer_core/data/textures/{grasscolor.png => grass.png} (100%) rename overviewer_core/data/textures/{largechest.png => normal_double.png} (100%) diff --git a/overviewer_core/data/textures/enderchest.png b/overviewer_core/data/textures/ender.png similarity index 100% rename from overviewer_core/data/textures/enderchest.png rename to overviewer_core/data/textures/ender.png diff --git a/overviewer_core/data/textures/foliagecolor.png b/overviewer_core/data/textures/foliage.png similarity index 100% rename from overviewer_core/data/textures/foliagecolor.png rename to overviewer_core/data/textures/foliage.png diff --git a/overviewer_core/data/textures/grasscolor.png b/overviewer_core/data/textures/grass.png similarity index 100% rename from overviewer_core/data/textures/grasscolor.png rename to overviewer_core/data/textures/grass.png diff --git a/overviewer_core/data/textures/largechest.png b/overviewer_core/data/textures/normal_double.png similarity index 100% rename from overviewer_core/data/textures/largechest.png rename to overviewer_core/data/textures/normal_double.png diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 88a8999..d8ee8f0 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -149,14 +149,17 @@ class Textures(object): # a list of subdirectories to search for a given file, # after the obvious '.' - search_dirs = ['anim', 'misc', 'environment', 'item'] + search_dirs = ['anim', 'misc', 'environment', 'item', 'entity', 'entity/chest'] search_zip_paths = [filename,] + [d + '/' + filename for d in search_dirs] def search_dir(base): """Search the given base dir for filename, in search_dirs.""" for path in [os.path.join(base, d, filename) for d in ['',] + search_dirs]: + if verbose: logging.info('filename: ' + filename + ' ; path: ' + path) if os.path.isfile(path): return path + return None + if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) # we've sucessfully loaded something from here before, so let's quickly try # this before searching again @@ -191,6 +194,15 @@ class Textures(object): return pack.open(packfilename) except (KeyError, IOError): pass + + try: + # 2nd try with completed path. + packfilename = 'assets/minecraft/textures/' + packfilename + pack.getinfo(packfilename) + if verbose: logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) + return pack.open(packfilename) + except (KeyError, IOError): + pass except (zipfile.BadZipfile, IOError): pass @@ -408,15 +420,16 @@ class Textures(object): def load_grass_color(self): """Helper function to load the grass color texture.""" if not hasattr(self, "grasscolor"): - self.grasscolor = list(self.load_image("grasscolor.png").getdata()) + self.grasscolor = list(self.load_image("grass.png").getdata()) return self.grasscolor def load_foliage_color(self): """Helper function to load the foliage color texture.""" if not hasattr(self, "foliagecolor"): - self.foliagecolor = list(self.load_image("foliagecolor.png").getdata()) + self.foliagecolor = list(self.load_image("foliage.png").getdata()) return self.foliagecolor + #I guess "watercolor" is wrong. But I can't correct as my texture pack don't define water color. def load_water_color(self): """Helper function to load the water color texture.""" if not hasattr(self, "watercolor"): @@ -1791,8 +1804,8 @@ def chests(self, blockid, data): # ancilData = 2,3,4,5 are used for this blockids if data & 24 == 0: - if blockid == 130: t = self.load_image("enderchest.png") - else: t = self.load_image("chest.png") + if blockid == 130: t = self.load_image("ender.png") + else: t = self.load_image("normal.png") # the textures is no longer in terrain.png, get it from # item/chest.png and get by cropping all the needed stuff @@ -1847,7 +1860,7 @@ def chests(self, blockid, data): # large chest # the textures is no longer in terrain.png, get it from # item/chest.png and get all the needed stuff - t = self.load_image("largechest.png") + t = self.load_image("normal_double.png") if t.size != (128,64): t = t.resize((128,64), Image.ANTIALIAS) # top top = t.crop((14,0,44,14)) From 37a45499a5907f5aa7176a067abae2631b6b2a13 Mon Sep 17 00:00:00 2001 From: joe-mojo Date: Fri, 11 Oct 2013 07:56:52 +0200 Subject: [PATCH 2/5] Tried a fix for normal.png being not found on Travis + added logs --- overviewer_core/textures.py | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index d8ee8f0..95932a1 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -145,21 +145,21 @@ class Textures(object): 'environment/'. """ - if verbose: logging.info("Starting search for {0}".format(filename)) + logging.info("Starting search for {0}".format(filename)) # a list of subdirectories to search for a given file, # after the obvious '.' - search_dirs = ['anim', 'misc', 'environment', 'item', 'entity', 'entity/chest'] + search_dirs = ['anim', 'misc', 'environment', 'item', 'item/chests', 'entity', 'entity/chest'] search_zip_paths = [filename,] + [d + '/' + filename for d in search_dirs] def search_dir(base): """Search the given base dir for filename, in search_dirs.""" for path in [os.path.join(base, d, filename) for d in ['',] + search_dirs]: - if verbose: logging.info('filename: ' + filename + ' ; path: ' + path) + logging.info('filename: ' + filename + ' ; path: ' + path) if os.path.isfile(path): return path return None - if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) + logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) # we've sucessfully loaded something from here before, so let's quickly try # this before searching again @@ -167,7 +167,7 @@ class Textures(object): for jarfilename in search_zip_paths: try: self.jar.getinfo(jarfilename) - if verbose: logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath) + logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath) return self.jar.open(jarfilename) except (KeyError, IOError), e: pass @@ -178,7 +178,7 @@ class Textures(object): if os.path.isdir(self.find_file_local_path): path = search_dir(self.find_file_local_path) if path: - if verbose: logging.info("Found %s in '%s'", filename, path) + logging.info("Found %s in '%s'", filename, path) return open(path, mode) elif os.path.isfile(self.find_file_local_path): # Must be a resource pack. Look for the requested file within @@ -190,7 +190,7 @@ class Textures(object): # pack.getinfo() will raise KeyError if the file is # not found. pack.getinfo(packfilename) - if verbose: logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) + logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) return pack.open(packfilename) except (KeyError, IOError): pass @@ -199,7 +199,7 @@ class Textures(object): # 2nd try with completed path. packfilename = 'assets/minecraft/textures/' + packfilename pack.getinfo(packfilename) - if verbose: logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) + logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) return pack.open(packfilename) except (KeyError, IOError): pass @@ -208,24 +208,24 @@ class Textures(object): # If we haven't returned at this point, then the requested file was NOT # found in the user-specified texture path or resource pack. - if verbose: logging.info("Did not find the file in specified texture path") + logging.info("Did not find the file in specified texture path") # Look in the location of the overviewer executable for the given path programdir = util.get_program_path() path = search_dir(programdir) if path: - if verbose: logging.info("Found %s in '%s'", filename, path) + logging.info("Found %s in '%s'", filename, path) return open(path, mode) if sys.platform.startswith("darwin"): path = search_dir("/Applications/Minecraft") if path: - if verbose: logging.info("Found %s in '%s'", filename, path) + logging.info("Found %s in '%s'", filename, path) return open(path, mode) - if verbose: logging.info("Did not find the file in overviewer executable directory") - if verbose: logging.info("Looking for installed minecraft jar files...") + logging.info("Did not find the file in overviewer executable directory") + logging.info("Looking for installed minecraft jar files...") # Find an installed minecraft client jar and look in it for the texture # file we need. @@ -242,7 +242,7 @@ class Textures(object): try: versions = os.listdir(versiondir) - if verbose: logging.info("Found these versions: {0}".format(versions)) + logging.info("Found these versions: {0}".format(versions)) except OSError: # Directory doesn't exist? Ignore it. It will find no versions and # fall through the checks below to the error at the bottom of the @@ -271,7 +271,7 @@ class Textures(object): most_recent_version = versionparts if most_recent_version != [0,0,0]: - if verbose: logging.info("Most recent version >=1.6.0: {0}. Searching it for the file...".format(most_recent_version)) + logging.info("Most recent version >=1.6.0: {0}. Searching it for the file...".format(most_recent_version)) jarname = ".".join(str(x) for x in most_recent_version) jarpath = os.path.join(versiondir, jarname, jarname + ".jar") @@ -281,15 +281,15 @@ class Textures(object): for jarfilename in search_zip_paths: try: jar.getinfo(jarfilename) - if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath) + logging.info("Found %s in '%s'", jarfilename, jarpath) self.jar, self.jarpath = jar, jarpath return jar.open(jarfilename) except (KeyError, IOError), e: pass - if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath)) + logging.info("Did not find file {0} in jar {1}".format(filename, jarpath)) else: - if verbose: logging.info("Did not find any non-snapshot minecraft jars >=1.6.0") + logging.info("Did not find any non-snapshot minecraft jars >=1.6.0") # Last ditch effort: look for the file is stored in with the overviewer # installation. We include a few files that aren't included with Minecraft @@ -297,16 +297,16 @@ class Textures(object): # they were generated by the game and not stored as images. Nowdays I # believe that's not true, but we still have a few files distributed # with overviewer. - if verbose: logging.info("Looking for texture in overviewer_core/data/textures") + logging.info("Looking for texture in overviewer_core/data/textures") path = search_dir(os.path.join(programdir, "overviewer_core", "data", "textures")) if path: - if verbose: logging.info("Found %s in '%s'", filename, path) + logging.info("Found %s in '%s'", filename, path) return open(path, mode) elif hasattr(sys, "frozen") or imp.is_frozen("__main__"): # windows special case, when the package dir doesn't exist path = search_dir(os.path.join(programdir, "textures")) if path: - if verbose: logging.info("Found %s in '%s'", filename, path) + logging.info("Found %s in '%s'", filename, path) return open(path, mode) raise TextureException("Could not find the textures while searching for '{0}'. Try specifying the 'texturepath' option in your config file.\nSet it to the path to a Minecraft Resource pack.\nAlternately, install the Minecraft client (which includes textures)\nAlso see \n(Remember, this version of Overviewer requires a 1.6-compatible resource pack)\n(Also note that I won't automatically use snapshots; you'll have to use the texturepath option to use a snapshot jar)".format(filename)) @@ -425,8 +425,11 @@ class Textures(object): def load_foliage_color(self): """Helper function to load the foliage color texture.""" + #logging.info("load_foliage_color start") if not hasattr(self, "foliagecolor"): self.foliagecolor = list(self.load_image("foliage.png").getdata()) + logging.debug("load_foliage_color loaded texture %s", self.foliagecolor) + #logging.info("load_foliage_color end") return self.foliagecolor #I guess "watercolor" is wrong. But I can't correct as my texture pack don't define water color. @@ -1805,9 +1808,13 @@ def chests(self, blockid, data): if data & 24 == 0: if blockid == 130: t = self.load_image("ender.png") - else: t = self.load_image("normal.png") + else: + try: + t = self.load_image("normal.png") + except (TextureException, IOError): + t = self.load_image("trap_small.png") - # the textures is no longer in terrain.png, get it from + # the textures is no longer in terrain.png, get it from # item/chest.png and get by cropping all the needed stuff if t.size != (64,64): t = t.resize((64,64), Image.ANTIALIAS) # top @@ -3175,7 +3182,7 @@ def comparator(self, blockid, data): # trapdoor -# TODO the trapdoor is looks like a sprite when opened, that's not good +# the trapdoor is looks like a sprite when opened, that's not good @material(blockid=96, data=range(16), transparent=True, nospawn=True) def trapdoor(self, blockid, data): From f28d6392985ead71dc0ddc369049c45c0b851593 Mon Sep 17 00:00:00 2001 From: joe-mojo Date: Mon, 14 Oct 2013 00:15:55 +0200 Subject: [PATCH 3/5] removed logs --- overviewer_core/textures.py | 43 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 95932a1..59b0453 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -145,7 +145,7 @@ class Textures(object): 'environment/'. """ - logging.info("Starting search for {0}".format(filename)) + if verbose: logging.info("Starting search for {0}".format(filename)) # a list of subdirectories to search for a given file, # after the obvious '.' @@ -154,12 +154,12 @@ class Textures(object): def search_dir(base): """Search the given base dir for filename, in search_dirs.""" for path in [os.path.join(base, d, filename) for d in ['',] + search_dirs]: - logging.info('filename: ' + filename + ' ; path: ' + path) + if verbose: logging.info('filename: ' + filename + ' ; path: ' + path) if os.path.isfile(path): return path return None - logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) + if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) # we've sucessfully loaded something from here before, so let's quickly try # this before searching again @@ -167,7 +167,7 @@ class Textures(object): for jarfilename in search_zip_paths: try: self.jar.getinfo(jarfilename) - logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath) + if verbose: logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath) return self.jar.open(jarfilename) except (KeyError, IOError), e: pass @@ -178,7 +178,7 @@ class Textures(object): if os.path.isdir(self.find_file_local_path): path = search_dir(self.find_file_local_path) if path: - logging.info("Found %s in '%s'", filename, path) + if verbose: logging.info("Found %s in '%s'", filename, path) return open(path, mode) elif os.path.isfile(self.find_file_local_path): # Must be a resource pack. Look for the requested file within @@ -190,7 +190,7 @@ class Textures(object): # pack.getinfo() will raise KeyError if the file is # not found. pack.getinfo(packfilename) - logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) + if verbose: logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) return pack.open(packfilename) except (KeyError, IOError): pass @@ -199,7 +199,7 @@ class Textures(object): # 2nd try with completed path. packfilename = 'assets/minecraft/textures/' + packfilename pack.getinfo(packfilename) - logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) + if verbose: logging.info("Found %s in '%s'", packfilename, self.find_file_local_path) return pack.open(packfilename) except (KeyError, IOError): pass @@ -208,24 +208,24 @@ class Textures(object): # If we haven't returned at this point, then the requested file was NOT # found in the user-specified texture path or resource pack. - logging.info("Did not find the file in specified texture path") + if verbose: logging.info("Did not find the file in specified texture path") # Look in the location of the overviewer executable for the given path programdir = util.get_program_path() path = search_dir(programdir) if path: - logging.info("Found %s in '%s'", filename, path) + if verbose: logging.info("Found %s in '%s'", filename, path) return open(path, mode) if sys.platform.startswith("darwin"): path = search_dir("/Applications/Minecraft") if path: - logging.info("Found %s in '%s'", filename, path) + if verbose: logging.info("Found %s in '%s'", filename, path) return open(path, mode) - logging.info("Did not find the file in overviewer executable directory") - logging.info("Looking for installed minecraft jar files...") + if verbose: logging.info("Did not find the file in overviewer executable directory") + if verbose: logging.info("Looking for installed minecraft jar files...") # Find an installed minecraft client jar and look in it for the texture # file we need. @@ -242,7 +242,7 @@ class Textures(object): try: versions = os.listdir(versiondir) - logging.info("Found these versions: {0}".format(versions)) + if verbose: logging.info("Found these versions: {0}".format(versions)) except OSError: # Directory doesn't exist? Ignore it. It will find no versions and # fall through the checks below to the error at the bottom of the @@ -271,7 +271,7 @@ class Textures(object): most_recent_version = versionparts if most_recent_version != [0,0,0]: - logging.info("Most recent version >=1.6.0: {0}. Searching it for the file...".format(most_recent_version)) + if verbose: logging.info("Most recent version >=1.6.0: {0}. Searching it for the file...".format(most_recent_version)) jarname = ".".join(str(x) for x in most_recent_version) jarpath = os.path.join(versiondir, jarname, jarname + ".jar") @@ -281,15 +281,15 @@ class Textures(object): for jarfilename in search_zip_paths: try: jar.getinfo(jarfilename) - logging.info("Found %s in '%s'", jarfilename, jarpath) + if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath) self.jar, self.jarpath = jar, jarpath return jar.open(jarfilename) except (KeyError, IOError), e: pass - logging.info("Did not find file {0} in jar {1}".format(filename, jarpath)) + if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath)) else: - logging.info("Did not find any non-snapshot minecraft jars >=1.6.0") + if verbose: logging.info("Did not find any non-snapshot minecraft jars >=1.6.0") # Last ditch effort: look for the file is stored in with the overviewer # installation. We include a few files that aren't included with Minecraft @@ -297,16 +297,16 @@ class Textures(object): # they were generated by the game and not stored as images. Nowdays I # believe that's not true, but we still have a few files distributed # with overviewer. - logging.info("Looking for texture in overviewer_core/data/textures") + if verbose: logging.info("Looking for texture in overviewer_core/data/textures") path = search_dir(os.path.join(programdir, "overviewer_core", "data", "textures")) if path: - logging.info("Found %s in '%s'", filename, path) + if verbose: logging.info("Found %s in '%s'", filename, path) return open(path, mode) elif hasattr(sys, "frozen") or imp.is_frozen("__main__"): # windows special case, when the package dir doesn't exist path = search_dir(os.path.join(programdir, "textures")) if path: - logging.info("Found %s in '%s'", filename, path) + if verbose: logging.info("Found %s in '%s'", filename, path) return open(path, mode) raise TextureException("Could not find the textures while searching for '{0}'. Try specifying the 'texturepath' option in your config file.\nSet it to the path to a Minecraft Resource pack.\nAlternately, install the Minecraft client (which includes textures)\nAlso see \n(Remember, this version of Overviewer requires a 1.6-compatible resource pack)\n(Also note that I won't automatically use snapshots; you'll have to use the texturepath option to use a snapshot jar)".format(filename)) @@ -425,11 +425,8 @@ class Textures(object): def load_foliage_color(self): """Helper function to load the foliage color texture.""" - #logging.info("load_foliage_color start") if not hasattr(self, "foliagecolor"): self.foliagecolor = list(self.load_image("foliage.png").getdata()) - logging.debug("load_foliage_color loaded texture %s", self.foliagecolor) - #logging.info("load_foliage_color end") return self.foliagecolor #I guess "watercolor" is wrong. But I can't correct as my texture pack don't define water color. From 026a2722da4af966b425d9ae41c120e9e6f0d4c7 Mon Sep 17 00:00:00 2001 From: joe-mojo Date: Mon, 14 Oct 2013 00:22:58 +0200 Subject: [PATCH 4/5] Removed dev logs --- overviewer_core/textures.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 59b0453..2557ca1 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -159,7 +159,7 @@ class Textures(object): return path return None - if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) + if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths)) # we've sucessfully loaded something from here before, so let's quickly try # this before searching again @@ -281,7 +281,7 @@ class Textures(object): for jarfilename in search_zip_paths: try: jar.getinfo(jarfilename) - if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath) + if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath) self.jar, self.jarpath = jar, jarpath return jar.open(jarfilename) except (KeyError, IOError), e: From b2e0d6da28ccfc37ce66dfd456069056649b3611 Mon Sep 17 00:00:00 2001 From: joe-mojo Date: Mon, 14 Oct 2013 00:49:24 +0200 Subject: [PATCH 5/5] trying to fix Travis build about chest texture not found. When normal.png from texture pack not found, fall back to chest.png --- overviewer_core/textures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 2557ca1..b8bfddc 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -1809,7 +1809,7 @@ def chests(self, blockid, data): try: t = self.load_image("normal.png") except (TextureException, IOError): - t = self.load_image("trap_small.png") + t = self.load_image("chest.png") # the textures is no longer in terrain.png, get it from # item/chest.png and get by cropping all the needed stuff