0

Merge branch 'texture-packs'

This commit is contained in:
Aaron Griffith
2011-11-09 13:59:11 -05:00
4 changed files with 79 additions and 24 deletions

View File

@@ -57,6 +57,7 @@ feature.
* Ryan McCue <ryanmccue@cubegames.net> * Ryan McCue <ryanmccue@cubegames.net>
* Morlok8k <otis.spankmeyer@gmail.com> * Morlok8k <otis.spankmeyer@gmail.com>
* Ryan Rector <rmrector@gmail.com> * Ryan Rector <rmrector@gmail.com>
* Jason Scheirer <jason.scheirer@gmail.com>
* Gregory Short <gshort2@gmail.com> * Gregory Short <gshort2@gmail.com>
* Sam Steele <sam@sigbox.c99.org> * Sam Steele <sam@sigbox.c99.org>
* timwolla <timwolla@mail.develfusion.com> * timwolla <timwolla@mail.develfusion.com>

View File

@@ -318,9 +318,11 @@ Less Useful Options
.. cmdoption:: --textures-path <path> .. cmdoption:: --textures-path <path>
Use this option to specify an alternate terrain.png to use for textures when Use this option to specify an alternate terrain.png (and other
rendering a world. ``path`` specifies the **containing directory** of textures) to when rendering a world. ``path`` specifies the
terrain.png. **containing directory** of terrain.png. Alternately, ``path`` can
specify a zip file containing the textures, such as a texture
pack.
The Overviewer will look for terrain.png in the following places in this The Overviewer will look for terrain.png in the following places in this
order: path specified by this option, the program's directory, the order: path specified by this option, the program's directory, the

View File

@@ -90,9 +90,13 @@ You have several options:
file in the same directory as overviewer.py or overviewer.exe. For file in the same directory as overviewer.py or overviewer.exe. For
installations, you will need to specify the path... see the next bullet. installations, you will need to specify the path... see the next bullet.
* You can put a terrain.png file anywhere you want and point to its location * You can put a terrain.png file anywhere you want and point to its
with the :option:`--textures-path` option. This should point to the directory containing location with the :option:`--textures-path` option. This should
the terrain.png, not to the file itself. point to the directory containing the terrain.png, not to the file
itself.
* Alternately, you can download any texture pack ZIP you like and
point to this directly with :option:`--textures-path`.
Note: the :option:`--check-terrain` option is useful for debugging terrain.png issues. Note: the :option:`--check-terrain` option is useful for debugging terrain.png issues.
For example:: For example::

View File

@@ -34,6 +34,7 @@ def _find_file(filename, mode="rb", verbose=False):
This searches the following locations in this order: This searches the following locations in this order:
* the textures_path given in the config file (if present) * the textures_path given in the config file (if present)
this can be either a directory or a zip file (texture pack)
* The program dir (same dir as overviewer.py) * The program dir (same dir as overviewer.py)
* The overviewer_core/data/textures dir * The overviewer_core/data/textures dir
* On Darwin, in /Applications/Minecraft * On Darwin, in /Applications/Minecraft
@@ -43,33 +44,60 @@ def _find_file(filename, mode="rb", verbose=False):
* On Darwin, at $HOME/Library/Application Support/minecraft/bin/minecraft.jar * On Darwin, at $HOME/Library/Application Support/minecraft/bin/minecraft.jar
* at $HOME/.minecraft/bin/minecraft.jar * at $HOME/.minecraft/bin/minecraft.jar
In all of these, files are searched for in '.', 'misc/', and 'environment/'.
""" """
# a list of subdirectories to search for a given file,
# after the obvious '.'
search_dirs = ['misc', 'environment']
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 os.path.isfile(path):
return path
return None
if _find_file_local_path: if _find_file_local_path:
path = os.path.join(_find_file_local_path, filename) if os.path.isdir(_find_file_local_path):
if os.path.exists(path): path = search_dir(_find_file_local_path)
if path:
if verbose: logging.info("Found %s in '%s'", filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
elif os.path.isfile(_find_file_local_path):
try:
pack = zipfile.ZipFile(_find_file_local_path)
for packfilename in search_zip_paths:
try:
pack.getinfo(packfilename)
if verbose: logging.info("Found %s in '%s'", packfilename, _find_file_local_path)
return pack.open(packfilename)
except (KeyError, IOError):
pass
except (zipfile.BadZipfile, IOError):
pass
programdir = util.get_program_path() programdir = util.get_program_path()
path = os.path.join(programdir, filename) path = search_dir(programdir)
if os.path.exists(path): if path:
if verbose: logging.info("Found %s in '%s'", filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
path = os.path.join(programdir, "overviewer_core", "data", "textures", filename) path = search_dir(os.path.join(programdir, "overviewer_core", "data", "textures"))
if os.path.exists(path): if path:
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
elif hasattr(sys, "frozen") or imp.is_frozen("__main__"): elif hasattr(sys, "frozen") or imp.is_frozen("__main__"):
# windows special case, when the package dir doesn't exist # windows special case, when the package dir doesn't exist
path = os.path.join(programdir, "textures", filename) path = search_dir(os.path.join(programdir, "textures"))
if os.path.exists(path): if path:
if verbose: logging.info("Found %s in '%s'", filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
if sys.platform == "darwin": if sys.platform == "darwin":
path = os.path.join("/Applications/Minecraft", filename) path = search_dir("/Applications/Minecraft")
if os.path.exists(path): if path:
if verbose: logging.info("Found %s in '%s'", filename, path) if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode) return open(path, mode)
@@ -89,14 +117,20 @@ def _find_file(filename, mode="rb", verbose=False):
jarpaths.append(os.path.join(_find_file_local_path, "minecraft.jar")) jarpaths.append(os.path.join(_find_file_local_path, "minecraft.jar"))
for jarpath in jarpaths: for jarpath in jarpaths:
if os.path.exists(jarpath): if os.path.isfile(jarpath):
jar = zipfile.ZipFile(jarpath) jar = zipfile.ZipFile(jarpath)
for jarfilename in [filename, 'misc/' + filename, 'environment/' + filename]: for jarfilename in search_zip_paths:
try: try:
jar.getinfo(jarfilename)
if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath) if verbose: logging.info("Found %s in '%s'", jarfilename, jarpath)
return jar.open(jarfilename) return jar.open(jarfilename)
except (KeyError, IOError), e: except (KeyError, IOError), e:
pass pass
elif os.path.isdir(jarpath):
path = search_dir(jarpath)
if path:
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, 'rb')
raise IOError("Could not find the file `{0}'. You can either place it in the same place as overviewer.py, use --textures-path, or install the Minecraft client.".format(filename)) raise IOError("Could not find the file `{0}'. You can either place it in the same place as overviewer.py, use --textures-path, or install the Minecraft client.".format(filename))
@@ -495,12 +529,22 @@ def load_water():
Block 9, standing water, is given a block with only the top face showing. Block 9, standing water, is given a block with only the top face showing.
Block 8, flowing water, is given a full 3 sided cube.""" Block 8, flowing water, is given a full 3 sided cube."""
try:
# try the MCPatcher water first, in case it's present
watertexture = _load_image("custom_water_still.png")
watertexture = watertexture.crop((0, 0, watertexture.size[0], watertexture.size[0]))
except IOError:
watertexture = _load_image("water.png") watertexture = _load_image("water.png")
w1 = _build_block(watertexture, None) w1 = _build_block(watertexture, None)
blockmap[9] = generate_texture_tuple(w1,9) blockmap[9] = generate_texture_tuple(w1,9)
w2 = _build_block(watertexture, watertexture) w2 = _build_block(watertexture, watertexture)
blockmap[8] = generate_texture_tuple(w2,8) blockmap[8] = generate_texture_tuple(w2,8)
try:
# try the MCPatcher lava first, in case it's present
lavatexture = _load_image("custom_lava_still.png")
lavatexture = lavatexture.crop((0, 0, lavatexture.size[0], lavatexture.size[0]))
except IOError:
lavatexture = _load_image("lava.png") lavatexture = _load_image("lava.png")
lavablock = _build_block(lavatexture, lavatexture) lavablock = _build_block(lavatexture, lavatexture)
blockmap[10] = generate_texture_tuple(lavablock,10) blockmap[10] = generate_texture_tuple(lavablock,10)
@@ -565,6 +609,10 @@ def generate_special_texture(blockID, data):
if blockID == 9 or blockID == 20 or blockID == 79: # spring water, flowing water and waterfall water, AND glass, AND ice if blockID == 9 or blockID == 20 or blockID == 79: # spring water, flowing water and waterfall water, AND glass, AND ice
# water,glass and ice share the way to be rendered # water,glass and ice share the way to be rendered
if blockID == 9: if blockID == 9:
try:
texture = _load_image("custom_water_still.png")
texture = texture.crop((0, 0, texture.size[0], texture.size[0]))
except IOError:
texture = _load_image("water.png") texture = _load_image("water.png")
elif blockID == 20: elif blockID == 20:
texture = terrain_images[49] texture = terrain_images[49]