0
This repository has been archived on 2025-04-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Minecraft-Overviewer/overviewer_core/src/primitives/overlay-spawn.c
Richard Pastrick 28099deaf6 Add customizable overlay colors, works for base overlay, spawn, and slime.
I left minerals as it is so you have to still define the minerals option to get that to work.
2012-06-08 12:07:21 -07:00

91 lines
2.6 KiB
C

/*
* This file is part of the Minecraft Overviewer.
*
* Minecraft Overviewer is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Minecraft Overviewer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include <math.h>
typedef struct {
/* inherits from overlay */
RenderPrimitiveOverlay parent;
} RenderPrimitiveSpawn;
static OverlayColor default_color[] = { 229, 36, 38, 0 };
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
RenderPrimitiveSpawn* self = (RenderPrimitiveSpawn *)data;
int x = state->x, y = state->y, z = state->z;
int y_light = y + 1;
unsigned char blocklight, skylight;
/* set a nice, pretty red color */
*r = self->parent.color->r;
*g = self->parent.color->g;
*b = self->parent.color->b;
/* default to no overlay, until told otherwise */
*a = 0;
if (block_has_property(state->block, NOSPAWN)) {
/* nothing can spawn on this */
return;
}
blocklight = get_data(state, BLOCKLIGHT, x, y_light, z);
skylight = get_data(state, SKYLIGHT, x, y_light, z);
if (MAX(blocklight, skylight) <= 7) {
/* hostile mobs spawn in daylight */
*a = 240;
} else if (MAX(blocklight, skylight - 11) <= 7) {
/* hostile mobs spawn at night */
*a = 150;
}
}
static int
overlay_spawn_start(void *data, RenderState *state, PyObject *support) {
RenderPrimitiveSpawn* self;
/* first, chain up */
int ret = primitive_overlay.start(data, state, support);
if (ret != 0)
return ret;
/* now do custom initializations */
self = (RenderPrimitiveSpawn *)data;
self->parent.get_color = get_color;
return 0;
}
static void
overlay_spawn_finish(void *data, RenderState *state) {
/* chain up */
primitive_overlay.finish(data, state);
}
RenderPrimitiveInterface primitive_overlay_spawn = {
"overlay-spawn",
sizeof(RenderPrimitiveSpawn),
overlay_spawn_start,
overlay_spawn_finish,
NULL,
NULL,
overlay_draw,
};