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 ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
44 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/unknown.png"),
45 .visibility = VISIBILITY_SOLID,
49 .selection_color = {1.0f, 1.0f, 1.0f},
54 .visibility = VISIBILITY_NONE,
58 .selection_color = {1.0f, 1.0f, 1.0f},
62 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/grass.png"),
63 .visibility = VISIBILITY_SOLID,
65 .render = &render_grass,
67 .selection_color = {1.0f, 1.0f, 1.0f},
71 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/dirt.png"),
72 .visibility = VISIBILITY_SOLID,
76 .selection_color = {1.0f, 1.0f, 1.0f},
80 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/stone.png"),
81 .visibility = VISIBILITY_SOLID,
83 .render = &render_stone,
85 .selection_color = {1.0f, 1.0f, 1.0f},
89 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/snow.png"),
90 .visibility = VISIBILITY_SOLID,
94 .selection_color = {0.1f, 0.5f, 1.0f},
99 .paths = {RESSOURCE_PATH "textures/oak_wood.png", RESSOURCE_PATH "textures/oak_wood_top.png", NULL, NULL, NULL, NULL},
100 .indices = {0, 0, 0, 0, 1, 1},
103 .visibility = VISIBILITY_SOLID,
105 .render = &render_color,
107 .selection_color = {1.0f, 1.0f, 1.0f},
111 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/oak_leaves.png"),
112 .visibility = VISIBILITY_SOLID,
114 .render = &render_color,
116 .selection_color = {1.0f, 1.0f, 1.0f},
121 .paths = {RESSOURCE_PATH "textures/pine_wood.png", RESSOURCE_PATH "textures/pine_wood_top.png", NULL, NULL, NULL, NULL},
122 .indices = {0, 0, 0, 0, 1, 1},
125 .visibility = VISIBILITY_SOLID,
127 .render = &render_color,
129 .selection_color = {1.0f, 1.0f, 1.0f},
133 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/pine_leaves.png"),
134 .visibility = VISIBILITY_CLIP,
136 .render = &render_color,
138 .selection_color = {1.0f, 1.0f, 1.0f},
143 .paths = {RESSOURCE_PATH "textures/palm_wood.png", RESSOURCE_PATH "textures/palm_wood_top.png", NULL, NULL, NULL, NULL},
144 .indices = {0, 0, 0, 0, 1, 1},
147 .visibility = VISIBILITY_SOLID,
149 .render = &render_color,
151 .selection_color = {1.0f, 1.0f, 1.0f},
155 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/palm_leaves.png"),
156 .visibility = VISIBILITY_SOLID,
158 .render = &render_color,
160 .selection_color = {1.0f, 1.0f, 1.0f},
164 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/sand.png"),
165 .visibility = VISIBILITY_SOLID,
169 .selection_color = {1.0f, 1.0f, 1.0f},
173 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/water.png"),
174 .visibility = VISIBILITY_BLEND,
178 .selection_color = {1.0f, 1.0f, 1.0f},
182 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/lava.png"),
183 .visibility = VISIBILITY_BLEND,
187 .selection_color = {1.0f, 1.0f, 1.0f},
191 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/vulcano_stone.png"),
192 .visibility = VISIBILITY_SOLID,
196 .selection_color = {1.0f, 1.0f, 1.0f},
200 void client_node_init()
202 for (NodeType node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
203 ClientNodeDefinition *def = &client_node_definitions[node];
205 if (def->visibility != VISIBILITY_NONE) {
206 Texture *textures[6];
208 for (int i = 0; i < 6; i++) {
209 char *path = def->tiles.paths[i];
212 textures[i] = texture_load(path, def->mipmap);
217 for (int i = 0; i < 6; i++)
218 def->tiles.textures[i] = textures[def->tiles.indices[i]];