1 #include "client/client.h"
2 #include "client/client_node.h"
4 #include "environment.h"
8 #define TILES_SIMPLE(path) {.paths = {path, NULL, NULL, NULL, NULL, NULL}, .indices = {0, 0, 0, 0, 0, 0}, .textures = {NULL}}
9 #define TILES_NONE {.paths = {NULL}, .indices = {0}, .textures = {NULL}}
11 static void render_grass(NodeArgsRender *args)
13 args->vertex.color = hsl_to_rgb((v3f32) {f32_mix(
14 // hue values between .13 and .33 depending on humidity
18 get_humidity(args->pos)
20 // move towards .45 while temperature is between .3 and .0
23 0.3f - get_temperature(args->pos),
30 static void render_stone(NodeArgsRender *args)
32 args->vertex.cube.textureCoordinates.x += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_S);
33 args->vertex.cube.textureCoordinates.y += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_T);
36 static void render_color(NodeArgsRender *args)
38 args->vertex.color = ((ColorData *) args->node->data)->color;
41 ClientNodeDef client_node_defs[NODE_UNLOADED] = {
44 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/unknown.png"),
45 .visibility = VISIBILITY_SOLID,
49 .selection_color = {1.0f, 1.0f, 1.0f},
55 .visibility = VISIBILITY_NONE,
59 .selection_color = {1.0f, 1.0f, 1.0f},
64 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/grass.png"),
65 .visibility = VISIBILITY_SOLID,
67 .render = &render_grass,
69 .selection_color = {1.0f, 1.0f, 1.0f},
74 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/dirt.png"),
75 .visibility = VISIBILITY_SOLID,
79 .selection_color = {1.0f, 1.0f, 1.0f},
84 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/stone.png"),
85 .visibility = VISIBILITY_SOLID,
87 .render = &render_stone,
89 .selection_color = {1.0f, 1.0f, 1.0f},
94 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/snow.png"),
95 .visibility = VISIBILITY_SOLID,
99 .selection_color = {0.1f, 0.5f, 1.0f},
105 .paths = {RESSOURCE_PATH "textures/oak_wood.png", RESSOURCE_PATH "textures/oak_wood_top.png", NULL, NULL, NULL, NULL},
106 .indices = {0, 0, 0, 0, 1, 1},
109 .visibility = VISIBILITY_SOLID,
111 .render = &render_color,
113 .selection_color = {1.0f, 1.0f, 1.0f},
118 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/oak_leaves.png"),
119 .visibility = VISIBILITY_SOLID,
121 .render = &render_color,
123 .selection_color = {1.0f, 1.0f, 1.0f},
124 .name = "Oak Leaves",
129 .paths = {RESSOURCE_PATH "textures/pine_wood.png", RESSOURCE_PATH "textures/pine_wood_top.png", NULL, NULL, NULL, NULL},
130 .indices = {0, 0, 0, 0, 1, 1},
133 .visibility = VISIBILITY_SOLID,
135 .render = &render_color,
137 .selection_color = {1.0f, 1.0f, 1.0f},
142 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/pine_leaves.png"),
143 .visibility = VISIBILITY_CLIP,
145 .render = &render_color,
147 .selection_color = {1.0f, 1.0f, 1.0f},
148 .name = "Pine Leaves",
153 .paths = {RESSOURCE_PATH "textures/palm_wood.png", RESSOURCE_PATH "textures/palm_wood_top.png", NULL, NULL, NULL, NULL},
154 .indices = {0, 0, 0, 0, 1, 1},
157 .visibility = VISIBILITY_SOLID,
159 .render = &render_color,
161 .selection_color = {1.0f, 1.0f, 1.0f},
166 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/palm_leaves.png"),
167 .visibility = VISIBILITY_SOLID,
169 .render = &render_color,
171 .selection_color = {1.0f, 1.0f, 1.0f},
172 .name = "Palm Leaves",
176 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/sand.png"),
177 .visibility = VISIBILITY_SOLID,
181 .selection_color = {1.0f, 1.0f, 1.0f},
186 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/water.png"),
187 .visibility = VISIBILITY_BLEND,
191 .selection_color = {1.0f, 1.0f, 1.0f},
196 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/lava.png"),
197 .visibility = VISIBILITY_BLEND,
201 .selection_color = {1.0f, 1.0f, 1.0f},
206 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/vulcano_stone.png"),
207 .visibility = VISIBILITY_SOLID,
211 .selection_color = {1.0f, 1.0f, 1.0f},
212 .name = "Vulcano Stone",
216 void client_node_init()
218 for (NodeType node = 0; node < NODE_UNLOADED; node++) {
219 ClientNodeDef *def = &client_node_defs[node];
221 if (def->visibility != VISIBILITY_NONE) {
222 Texture *textures[6];
224 for (int i = 0; i < 6; i++) {
225 char *path = def->tiles.paths[i];
228 textures[i] = texture_load(path, def->mipmap);
233 for (int i = 0; i < 6; i++)
234 def->tiles.textures[i] = textures[def->tiles.indices[i]];