0

overviewer no longer trusts ancillary data from blocks that should have none

This commit is contained in:
Aaron Griffith
2011-12-18 04:51:53 -05:00
parent 3bdf380b6f
commit debb14c48b
3 changed files with 44 additions and 28 deletions

View File

@@ -30,6 +30,7 @@ static PyObject *transparent_blocks = NULL;
static PyObject *solid_blocks = NULL;
static PyObject *fluid_blocks = NULL;
static PyObject *nospawn_blocks = NULL;
static PyObject *nodata_blocks = NULL;
PyObject *init_chunk_render(PyObject *self, PyObject *args) {
@@ -86,6 +87,9 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
nospawn_blocks = PyObject_GetAttrString(textures, "nospawn_blocks");
if (!nospawn_blocks)
return NULL;
nodata_blocks = PyObject_GetAttrString(textures, "nodata_blocks");
if (!nodata_blocks)
return NULL;
block_properties = calloc(max_blockid, sizeof(unsigned char));
for (i = 0; i < max_blockid; i++) {
@@ -101,6 +105,8 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
block_properties[i] |= 1 << FLUID;
if (PySequence_Contains(nospawn_blocks, block))
block_properties[i] |= 1 << NOSPAWN;
if (PySequence_Contains(nodata_blocks, block))
block_properties[i] |= 1 << NODATA;
Py_DECREF(block);
}
@@ -444,6 +450,13 @@ chunk_render(PyObject *self, PyObject *args) {
/* everything stored here will be a borrowed ref */
if (block_has_property(state.block, NODATA)) {
/* block shouldn't have data associated with it, set it to 0 */
ancilData = 0;
state.block_data = 0;
state.block_pdata = 0;
} else {
/* block has associated data, use it */
ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
state.block_data = ancilData;
/* block that need pseudo ancildata:
@@ -460,6 +473,7 @@ chunk_render(PyObject *self, PyObject *args) {
} else {
state.block_pdata = 0;
}
}
/* make sure our block info is in-bounds */
if (state.block >= max_blockid || ancilData >= max_data)

View File

@@ -26,7 +26,7 @@
// increment this value if you've made a change to the c extesion
// and want to force users to rebuild
#define OVERVIEWER_EXTENSION_VERSION 13
#define OVERVIEWER_EXTENSION_VERSION 14
/* Python PIL, and numpy headers */
#include <Python.h>
@@ -102,6 +102,7 @@ typedef enum
SOLID,
FLUID,
NOSPAWN,
NODATA,
} BlockProperty;
/* globals set in init_chunk_render, here because they're used
in block_has_property */

View File

@@ -611,11 +611,12 @@ transparent_blocks = set()
solid_blocks = set()
fluid_blocks = set()
nospawn_blocks = set()
nodata_blocks = set()
# the material registration decorator
def material(blockid=[], data=[0], **kwargs):
# mapping from property name to the set to store them in
properties = {"transparent" : transparent_blocks, "solid" : solid_blocks, "fluid" : fluid_blocks, "nospawn" : nospawn_blocks}
properties = {"transparent" : transparent_blocks, "solid" : solid_blocks, "fluid" : fluid_blocks, "nospawn" : nospawn_blocks, "nodata" : nodata_blocks}
# make sure blockid and data are iterable
try:
@@ -657,9 +658,9 @@ def material(blockid=[], data=[0], **kwargs):
return func_wrapper
return inner_material
# shortcut function for pure blocks, default to solid
# shortcut function for pure blocks, default to solid, nodata
def block(blockid=[], top_index=None, side_index=None, **kwargs):
new_kwargs = {'solid' : True}
new_kwargs = {'solid' : True, 'nodata' : True}
new_kwargs.update(kwargs)
if top_index is None:
@@ -673,9 +674,9 @@ def block(blockid=[], top_index=None, side_index=None, **kwargs):
return build_block(terrain_images[top_index], terrain_images[side_index])
return inner_block
# shortcut function for sprite blocks, defaults to transparent
# shortcut function for sprite blocks, defaults to transparent, nodata
def sprite(blockid=[], index=None, **kwargs):
new_kwargs = {'transparent' : True}
new_kwargs = {'transparent' : True, 'nodata' : True}
new_kwargs.update(kwargs)
if index is None:
@@ -686,9 +687,9 @@ def sprite(blockid=[], index=None, **kwargs):
return build_sprite(terrain_images[index])
return inner_sprite
# shortcut function for billboard blocks, defaults to transparent
# shortcut function for billboard blocks, defaults to transparent, nodata
def billboard(blockid=[], index=None, **kwargs):
new_kwargs = {'transparent' : True}
new_kwargs = {'transparent' : True, 'nodata' : True}
new_kwargs.update(kwargs)
if index is None:
@@ -1685,7 +1686,7 @@ block(blockid=57, top_index=24)
# crafting table
# needs two different sides
@material(blockid=58, solid=True)
@material(blockid=58, solid=True, nodata=True)
def crafting_table(blockid, data):
top = terrain_images[43]
side3 = terrain_images[43+16]
@@ -2187,7 +2188,7 @@ def buttons(blockid, data, north):
return img
# snow
@material(blockid=78, data=range(8), transparent=True, solid=True)
@material(blockid=78, data=range(16), transparent=True, solid=True)
def snow(blockid, data):
# still not rendered correctly: data other than 0
@@ -2982,7 +2983,7 @@ def nether_wart(blockid, data):
# enchantment table
# TODO there's no book at the moment
@material(blockid=116, transparent=True)
@material(blockid=116, transparent=True, nodata=True)
def enchantment_table(blockid, data):
# no book at the moment
top = terrain_images[166]
@@ -3027,7 +3028,7 @@ def cauldron(blockid, data):
return img
# end portal
@material(blockid=119, transparent=True)
@material(blockid=119, transparent=True, nodata=True)
def end_portal(blockid, data):
img = Image.new("RGBA", (24,24), bgcolor)
# generate a black texure with white, blue and grey dots resembling stars