From 354888c09998631ac8cbc2ff83dc5768e418a07e Mon Sep 17 00:00:00 2001 From: David Vierra Date: Mon, 27 Mar 2017 16:08:40 -1000 Subject: [PATCH] Fix #309 - Unbounded texture variable lookup --- src/mcedit2/rendering/blockmodels.pyx | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/mcedit2/rendering/blockmodels.pyx b/src/mcedit2/rendering/blockmodels.pyx index 411c58d..ab62672 100644 --- a/src/mcedit2/rendering/blockmodels.pyx +++ b/src/mcedit2/rendering/blockmodels.pyx @@ -309,16 +309,25 @@ cdef class BlockModels(object): # grab textures and elements from this model, then get parent and merge its textures and elements # continue until no parent is found - rawTextureVars = {} + textureVars = {} allElements = [] for i in range(MAX_TEXTURE_RECURSIONS): textures = modelDict.get("textures") if textures is not None: - rawTextureVars.update(textures) + # Resolve texture variables in parent to values in child + for k, v in textures.iteritems(): + if k in textureVars: + # Child always overrides parent + continue + if v.startswith("#"): + v = textureVars.get(v[1:], v) + textureVars[k] = v + elements = modelDict.get("elements") if elements is not None: allElements.extend(elements) + parentName = modelDict.get("parent") if parentName is None: break @@ -333,17 +342,7 @@ cdef class BlockModels(object): if block.forcedModelTextures: # user-configured model textures for var, tex in block.forcedModelTextures.iteritems(): - rawTextureVars[var[1:]] = tex - - # pre-resolve texture vars - - textureVars = {} - for k, v in rawTextureVars.iteritems(): - while v is not None and v.startswith("#"): - v = rawTextureVars.get(v[1:]) - if v: - textureVars[k] = v - + textureVars[var[1:]] = tex if block.biomeTintType == "grass": biomeTintType = BIOME_GRASS @@ -382,8 +381,8 @@ cdef class BlockModels(object): except Exception as e: - log.error("Failed to parse variant of block %s\nelements:\n%s\ntextures:\n%s", - block.nameAndState, allElements, rawTextureVars) + log.exception("Failed to parse variant of block %s\nelements:\n%s\ntextures:\n%s", + block.nameAndState, allElements, textureVars) return allQuads