Skip to content

Add data-value (optional) to StructureOverlay #1810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1213,23 +1213,24 @@ StructureOverlay
a MineralOverlay with alpha support.

This Overlay colors according to a patterns that are specified as
multiple tuples of the form ``(relx, rely, relz, blockid)``. So
multiple tuples of the form ``(relx, rely, relz, blockid)`` or ``(relx, rely, relz, blockid, data)``. So
by specifying ``(0, -1, 0, 4)`` the block below the current one has to
be a cobblestone.
be a cobblestone. By specifying ``(0, -1, 0, 35, 11)`` the block below has to be Blue wool.

One color is then specified as
``((relblockid1, relblockid2, ...), (r, g, b, a))`` where the
``relblockid*`` are relative coordinates and the blockid as specified
above. The ``relblockid*`` must match all at the same time for the
color to apply.
color to apply. The Alpha (a) is optional and is set to 255 by default.

Example::

StructureOverlay(structures=[(((0, 0, 0, 66), (0, -1, 0, 4)), (255, 0, 0, 255)),
(((0, 0, 0, 27), (0, -1, 0, 4)), (0, 255, 0, 255))])
(((0, 0, 0, 27), (0, -1, 0, 4)), (0, 255, 0, 255)),
(((0, 0, 0, 66), (0, -1, 0, 35, 11)), (0, 0, 255))])

In this example all rails(66) on top of cobblestone are rendered in
pure red. And all powerrails(27) are rendered in green.
pure red, all powerrails(27) are rendered in green and all rails(66) above blue wool are rendered blue.

If ``structures`` is not provided, a default rail coloring is used.

Expand Down
2 changes: 1 addition & 1 deletion overviewer_core/rendermodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class SlimeOverlay(Overlay):
class StructureOverlay(Overlay):
name = "overlay-structure"
options = {
'structures': ('a list of ((((relx, rely, relz), blockid), ...), (r, g, b, a)) tuples for coloring minerals',
'structures': ('a list of (((relx, rely, relz, blockid, data), ...), (r, g, b, a)) tuples for coloring minerals',
[(((0, 0, 0, 66), (0, -1, 0, 4)), (255, 0, 0, 255)),
(((0, 0, 0, 27), (0, -1, 0, 4)), (0, 255, 0, 255)),
(((0, 0, 0, 28), (0, -1, 0, 4)), (255, 255, 0, 255)),
Expand Down
15 changes: 11 additions & 4 deletions overviewer_core/src/primitives/overlay-structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
struct Condition {
int32_t relx, rely, relz;
mc_block_t block;
signed short data;
};

struct Color {
Expand Down Expand Up @@ -65,7 +66,10 @@ static void get_color(void* data,
all = true;
c = (struct Condition*)&structures[col].conditions[cond];
// check if the condition does apply and break from the conditions loop if not.
if (!(c->block == get_data(state, BLOCKS, x + c->relx, y + c->rely, z + c->relz))) {
if (!(
c->block == get_data(state, BLOCKS, x + c->relx, y + c->rely, z + c->relz) &&
(c->data == -1 || (uint32_t)c->data == get_data(state, DATA, x + c->relx, y + c->rely, z + c->relz))
)) {
all = false;
break;
}
Expand Down Expand Up @@ -147,8 +151,9 @@ static bool overlay_structure_start(void* data, RenderState* state, PyObject* su
return true;
}

structures[i].a = 255;
// Parse colorpy into a c-struct.
if (!PyArg_ParseTuple(colorpy, "bbbb",
if (!PyArg_ParseTuple(colorpy, "bbb|b",
&structures[i].r,
&structures[i].g,
&structures[i].b,
Expand Down Expand Up @@ -182,11 +187,13 @@ static bool overlay_structure_start(void* data, RenderState* state, PyObject* su
// iterate over all the conditions and read them.
for (n = 0; n < structures[i].numconds; n++) {
PyObject* ccond = PySequence_Fast_GET_ITEM(condspy, n);
if (!PyArg_ParseTuple(ccond, "iiib",
cond[n].data = -1; // If no data value is given the data value stays at -1
if (!PyArg_ParseTuple(ccond, "iiih|h",
&cond[n].relx,
&cond[n].rely,
&cond[n].relz,
&cond[n].block)) {
&cond[n].block,
&cond[n].data)) {
int32_t x = 0;
for (x = 0; x < structures_size; x++) {
free(structures[x].conditions);
Expand Down