From debb14c48b8daf16ea62199e82e57ae5a80422a1 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sun, 18 Dec 2011 04:51:53 -0500 Subject: [PATCH] overviewer no longer trusts ancillary data from blocks that should have none --- overviewer_core/src/iterate.c | 44 +++++++++++++++++++++----------- overviewer_core/src/overviewer.h | 3 ++- overviewer_core/textures.py | 25 +++++++++--------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/overviewer_core/src/iterate.c b/overviewer_core/src/iterate.c index adc790d..d794277 100644 --- a/overviewer_core/src/iterate.c +++ b/overviewer_core/src/iterate.c @@ -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); } @@ -443,22 +449,30 @@ chunk_render(PyObject *self, PyObject *args) { } /* everything stored here will be a borrowed ref */ - - ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z); - state.block_data = ancilData; - /* block that need pseudo ancildata: - * grass, water, glass, chest, restone wire, - * ice, fence, portal, iron bars, glass panes */ - if ((state.block == 2) || (state.block == 9) || - (state.block == 20) || (state.block == 54) || - (state.block == 55) || (state.block == 79) || - (state.block == 85) || (state.block == 90) || - (state.block == 101) || (state.block == 102) || - (state.block == 113)) { - ancilData = generate_pseudo_data(&state, ancilData); - state.block_pdata = ancilData; - } else { + + 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: + * grass, water, glass, chest, restone wire, + * ice, fence, portal, iron bars, glass panes */ + if ((state.block == 2) || (state.block == 9) || + (state.block == 20) || (state.block == 54) || + (state.block == 55) || (state.block == 79) || + (state.block == 85) || (state.block == 90) || + (state.block == 101) || (state.block == 102) || + (state.block == 113)) { + ancilData = generate_pseudo_data(&state, ancilData); + state.block_pdata = ancilData; + } else { + state.block_pdata = 0; + } } /* make sure our block info is in-bounds */ diff --git a/overviewer_core/src/overviewer.h b/overviewer_core/src/overviewer.h index 0e45a2f..425d33e 100644 --- a/overviewer_core/src/overviewer.h +++ b/overviewer_core/src/overviewer.h @@ -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 @@ -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 */ diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 3bd2841..043fe44 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -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 @@ -2319,7 +2320,7 @@ def fence(blockid, data): fence_small_side = ImageEnhance.Brightness(fence_small_side).enhance(0.9) fence_small_side.putalpha(sidealpha) - # Create img to compose the fence + # Create img to compose the fence img = Image.new("RGBA", (24,24), bgcolor) # Position of fence small sticks in img. @@ -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