Add question mark texture (and "model") for unknown blocks.

This commit is contained in:
David Vierra 2015-01-25 21:00:13 -10:00
parent e9f18b10dc
commit 673689fc7c
5 changed files with 48 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

View File

@ -14,6 +14,7 @@ from cpython cimport array
from array import array
from mceditlib import faces
from mceditlib.blocktypes import BlockType
from mceditlib.geometry import Vector
from mceditlib.selection import FloatBox
@ -33,6 +34,13 @@ cdef struct ModelQuadList:
cdef class BlockModels(object):
def _getBlockModel(self, modelName):
if modelName == "block/MCEDIT_UNKNOWN":
return {
"parent": "block/cube_all",
"textures": {
"all": "MCEDIT_UNKNOWN"
}
}
model = self.modelBlockJsons.get(modelName)
if model is None:
model = json.load(self.resourceLoader.openStream("models/%s.json" % modelName))
@ -40,6 +48,14 @@ cdef class BlockModels(object):
return model
def _getBlockState(self, stateName):
if stateName == "MCEDIT_UNKNOWN":
return {
"variants": {
"MCEDIT_UNKNOWN": {
"model": "MCEDIT_UNKNOWN",
}
}
}
state = self.modelStateJsons.get(stateName)
if state is None:
state = json.load(self.resourceLoader.openStream("blockstates/%s.json" % stateName))
@ -69,7 +85,15 @@ cdef class BlockModels(object):
memset(self.cookedModelsByID, 0, sizeof(self.cookedModelsByID))
self.cooked = False
for i, block in enumerate(blocktypes):
missingnoProxy = BlockType(-1, -1, blocktypes)
missingnoProxy.internalName = "MCEDIT_UNKNOWN"
missingnoProxy.blockState = ""
missingnoProxy.renderType = 3
missingnoProxy.resourcePath = "MCEDIT_UNKNOWN"
missingnoProxy.resourceVariant = "MCEDIT_UNKNOWN"
missingnoProxy.color = 0xFFFFFF
for i, block in enumerate(list(blocktypes) + [missingnoProxy]):
if i % 100 == 0:
log.info("Loading block models %s/%s", i, len(blocktypes))
@ -196,6 +220,7 @@ cdef class BlockModels(object):
allElements, textureVars)
raise
def buildBoxQuads(self, element, nameAndState, textureVars, variantXrot, variantYrot, variantZrot, blockColor):
quads = []
shade = element.get("shade", True)
@ -253,6 +278,7 @@ cdef class BlockModels(object):
cdef int u1, u2, v1, v2
cdef int uw, vh
cdef list cookedQuads
for nameAndState, allQuads in self.modelQuads.iteritems():
cookedQuads = []
for (box, face, texture, uv, cullface, shade, rotation, textureRotation,
@ -307,8 +333,18 @@ cdef class BlockModels(object):
cookedQuads.append((xyzuvc, cullface))
cookedModels[nameAndState] = cookedQuads
ID, meta = self.blocktypes.IDsByState[nameAndState]
self.storeQuads(cookedQuads, ID, meta)
try:
ID, meta = self.blocktypes.IDsByState[nameAndState]
except KeyError:
pass
else:
self.storeQuads(cookedQuads, ID, meta)
stoneModels = cookedModels['MCEDIT_UNKNOWN']
for ID in range(4096):
for meta in range(16):
if self.cookedModelsByID[ID][meta].count == 0:
self.storeQuads(stoneModels, ID, meta)
self.cookedModels = cookedModels
self.cooked = True

View File

@ -12,6 +12,7 @@ from mcedit2.util.load_png import loadPNGData
from mcedit2.rendering.lightmap import generateLightmap
from mcedit2.resourceloader import ResourceLoader
from mcedit2.util import glutils
from mcedit2.util.resources import resourcePath
from mceditlib import util
@ -87,22 +88,16 @@ class TextureAtlas(object):
self._terrainTexture = None
self._maxLOD = maxLOD
missingno = numpy.empty((16, 16, 4), 'uint8')
missingno[:] = [[[0xff, 0x00, 0xff, 0xff]]]
missingnoTexture = 16, 16, missingno
names = set()
self._rawTextures = rawTextures = []
assert "MCEDIT_UNKNOWN" in blockModels.getTextureNames()
for filename in blockModels.getTextureNames():
if filename in names:
continue
try:
if filename == "missingno":
rawTextures.append((filename,) + missingnoTexture)
else:
f = self._openImageStream(filename)
rawTextures.append((filename,) + loadPNGData(f.read()))
f = self._openImageStream(filename)
rawTextures.append((filename,) + loadPNGData(f.read()))
names.add(filename)
log.debug("Loaded texture %s", filename)
except KeyError as e:
@ -115,6 +110,7 @@ class TextureAtlas(object):
log.info("Preloaded %d textures for world %s (%i kB)",
len(self._rawTextures), util.displayName(self._filename), rawSize/1024)
def load(self):
if self._terrainTexture:
return
@ -211,8 +207,9 @@ class TextureAtlas(object):
#raise SystemExit
def _openImageStream(self, name):
if name == "missingno":
name = "stone"
if name == "MCEDIT_UNKNOWN":
block_unknown = resourcePath("mcedit2/assets/mcedit2/block_unknown.png")
return file(block_unknown, "rb")
return self._resourceLoader.openStream("textures/" + name + ".png")
def bindTerrain(self):

View File

@ -92,7 +92,7 @@ class BlockTypeSet(object):
'blockState': '[UNKNOWN_STATE]',
'unlocalizedName': 'name.unknown',
'opaqueCube': True,
'renderType': -1, #xxx unknowns
'renderType': 3, # Model block - defaults to stone(?)
}
self.aka = defaultdict(lambda: "")