3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "content_mapnode.h"
25 #include "content_nodemeta.h"
27 // TODO: Get rid of these and set up some attributes like toughness,
28 // fluffyness, and a funciton to calculate time and durability loss
29 // (and sound? and whatever else) from them
30 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
31 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
32 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
34 content_t trans_table_19[][2] = {
38 {CONTENT_GRASS_FOOTSTEPS, 6},
42 {CONTENT_COALSTONE, 11},
48 {CONTENT_MOSSYCOBBLE, 22},
50 {CONTENT_SANDSTONE, 24},
54 {CONTENT_PAPYRUS, 28},
55 {CONTENT_BOOKSHELF, 29},
58 MapNode mapnode_translate_from_internal(MapNode n_from, u8 version)
60 MapNode result = n_from;
63 content_t c_from = n_from.getContent();
64 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
66 if(trans_table_19[i][0] == c_from)
68 result.setContent(trans_table_19[i][1]);
75 MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
77 MapNode result = n_from;
80 content_t c_from = n_from.getContent();
81 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
83 if(trans_table_19[i][1] == c_from)
85 result.setContent(trans_table_19[i][0]);
93 void content_mapnode_init()
96 bool new_style_water = g_settings.getBool("new_style_water");
97 bool new_style_leaves = g_settings.getBool("new_style_leaves");
98 bool invisible_stone = g_settings.getBool("invisible_stone");
101 ContentFeatures *f = NULL;
104 f = &content_features(i);
105 f->setAllTextures("stone.png");
106 f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
107 f->param_type = CPT_MINERAL;
108 f->is_ground_content = true;
109 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
110 setStoneLikeDiggingProperties(f->digging_properties, 1.0);
112 f->solidness = 0; // For debugging, hides regular stone
115 f = &content_features(i);
116 f->setAllTextures("mud.png^grass_side.png");
117 f->setTexture(0, "grass.png");
118 f->setTexture(1, "mud.png");
119 f->param_type = CPT_MINERAL;
120 f->is_ground_content = true;
121 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
122 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
124 i = CONTENT_GRASS_FOOTSTEPS;
125 f = &content_features(i);
126 f->setAllTextures("mud.png^grass_side.png");
127 f->setTexture(0, "grass_footsteps.png");
128 f->setTexture(1, "mud.png");
129 f->param_type = CPT_MINERAL;
130 f->is_ground_content = true;
131 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
132 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
135 f = &content_features(i);
136 f->setAllTextures("mud.png");
137 f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
138 f->param_type = CPT_MINERAL;
139 f->is_ground_content = true;
140 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
141 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
144 f = &content_features(i);
145 f->setAllTextures("sand.png");
146 f->setInventoryTextureCube("sand.png", "sand.png", "sand.png");
147 f->param_type = CPT_MINERAL;
148 f->is_ground_content = true;
149 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
150 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
153 f = &content_features(i);
154 f->setAllTextures("gravel.png");
155 f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png");
156 f->param_type = CPT_MINERAL;
157 f->is_ground_content = true;
158 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
159 setDirtLikeDiggingProperties(f->digging_properties, 1.75);
161 i = CONTENT_SANDSTONE;
162 f = &content_features(i);
163 f->setAllTextures("sandstone.png");
164 f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png");
165 f->param_type = CPT_MINERAL;
166 f->is_ground_content = true;
167 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_SAND)+" 1";
168 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
171 f = &content_features(i);
172 f->setAllTextures("clay.png");
173 f->setInventoryTextureCube("clay.png", "clay.png", "clay.png");
174 f->param_type = CPT_MINERAL;
175 f->is_ground_content = true;
176 f->dug_item = std::string("CraftItem lump_of_clay 4");
177 setDirtLikeDiggingProperties(f->digging_properties, 1.0);
180 f = &content_features(i);
181 f->setAllTextures("brick.png");
182 f->setInventoryTextureCube("brick.png", "brick.png", "brick.png");
183 f->param_type = CPT_MINERAL;
184 f->is_ground_content = true;
185 f->dug_item = std::string("CraftItem clay_brick 4");
186 setStoneLikeDiggingProperties(f->digging_properties, 1.0);
189 f = &content_features(i);
190 f->setAllTextures("tree.png");
191 f->setTexture(0, "tree_top.png");
192 f->setTexture(1, "tree_top.png");
193 f->param_type = CPT_MINERAL;
194 f->is_ground_content = true;
195 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
196 setWoodLikeDiggingProperties(f->digging_properties, 1.0);
198 i = CONTENT_JUNGLETREE;
199 f = &content_features(i);
200 f->setAllTextures("jungletree.png");
201 f->setTexture(0, "jungletree_top.png");
202 f->setTexture(1, "jungletree_top.png");
203 f->param_type = CPT_MINERAL;
204 //f->is_ground_content = true;
205 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
206 setWoodLikeDiggingProperties(f->digging_properties, 1.0);
208 i = CONTENT_JUNGLEGRASS;
209 f = &content_features(i);
210 f->setInventoryTexture("junglegrass.png");
211 f->light_propagates = true;
212 f->param_type = CPT_LIGHT;
213 //f->is_ground_content = true;
214 f->air_equivalent = false; // grass grows underneath
215 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
216 f->solidness = 0; // drawn separately, makes no faces
218 setWoodLikeDiggingProperties(f->digging_properties, 0.10);
221 f = &content_features(i);
222 f->light_propagates = true;
223 //f->param_type = CPT_MINERAL;
224 f->param_type = CPT_LIGHT;
225 //f->is_ground_content = true;
228 f->solidness = 0; // drawn separately, makes no faces
229 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
233 f->setAllTextures("[noalpha:leaves.png");
235 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
236 setWoodLikeDiggingProperties(f->digging_properties, 0.15);
239 f = &content_features(i);
240 f->setAllTextures("cactus_side.png");
241 f->setTexture(0, "cactus_top.png");
242 f->setTexture(1, "cactus_top.png");
243 f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
244 f->param_type = CPT_MINERAL;
245 f->is_ground_content = true;
246 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
247 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
250 f = &content_features(i);
251 f->setInventoryTexture("papyrus.png");
252 f->light_propagates = true;
253 f->param_type = CPT_LIGHT;
254 f->is_ground_content = true;
255 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
256 f->solidness = 0; // drawn separately, makes no faces
258 setWoodLikeDiggingProperties(f->digging_properties, 0.25);
260 i = CONTENT_BOOKSHELF;
261 f = &content_features(i);
262 f->setAllTextures("bookshelf.png");
263 f->setTexture(0, "wood.png");
264 f->setTexture(1, "wood.png");
265 // FIXME: setInventoryTextureCube() only cares for the first texture
266 f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png");
267 //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
268 f->param_type = CPT_MINERAL;
269 f->is_ground_content = true;
270 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
273 f = &content_features(i);
274 f->light_propagates = true;
275 f->sunlight_propagates = true;
276 f->param_type = CPT_LIGHT;
277 f->is_ground_content = true;
278 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
279 f->solidness = 0; // drawn separately, makes no faces
280 f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
281 setWoodLikeDiggingProperties(f->digging_properties, 0.15);
284 f = &content_features(i);
285 f->light_propagates = true;
286 f->param_type = CPT_LIGHT;
287 f->is_ground_content = true;
288 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
289 f->solidness = 0; // drawn separately, makes no faces
290 f->air_equivalent = true; // grass grows underneath
291 f->setInventoryTexture("item_fence.png");
292 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
295 f = &content_features(i);
296 f->setInventoryTexture("rail.png");
297 f->light_propagates = true;
298 f->param_type = CPT_LIGHT;
299 f->is_ground_content = true;
300 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
301 f->solidness = 0; // drawn separately, makes no faces
302 f->air_equivalent = true; // grass grows underneath
304 setDirtLikeDiggingProperties(f->digging_properties, 0.75);
307 i = CONTENT_COALSTONE;
308 f = &content_features(i);
309 f->setAllTextures("stone.png^mineral_coal.png");
310 f->is_ground_content = true;
311 setStoneLikeDiggingProperties(f->digging_properties, 1.5);
314 f = &content_features(i);
315 f->setAllTextures("wood.png");
316 f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
317 f->is_ground_content = true;
318 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
319 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
322 f = &content_features(i);
323 f->setAllTextures("mese.png");
324 f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
325 f->is_ground_content = true;
326 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
327 setStoneLikeDiggingProperties(f->digging_properties, 0.5);
330 f = &content_features(i);
331 f->setAllTextures("cloud.png");
332 f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
333 f->is_ground_content = true;
334 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
337 f = &content_features(i);
338 f->param_type = CPT_LIGHT;
339 f->light_propagates = true;
340 f->sunlight_propagates = true;
343 f->pointable = false;
345 f->buildable_to = true;
346 f->air_equivalent = true;
349 f = &content_features(i);
350 f->setInventoryTextureCube("water.png", "water.png", "water.png");
351 f->param_type = CPT_LIGHT;
352 f->light_propagates = true;
353 f->solidness = 0; // Drawn separately, makes no faces
355 f->pointable = false;
357 f->buildable_to = true;
358 f->liquid_type = LIQUID_FLOWING;
359 f->liquid_alternative_flowing = CONTENT_WATER;
360 f->liquid_alternative_source = CONTENT_WATERSOURCE;
362 i = CONTENT_WATERSOURCE;
363 f = &content_features(i);
364 //f->setInventoryTexture("water.png");
365 f->setInventoryTextureCube("water.png", "water.png", "water.png");
368 f->solidness = 0; // drawn separately, makes no faces
376 t.texture = g_texturesource->getTexture("water.png");
378 t.alpha = WATER_ALPHA;
379 t.material_type = MATERIAL_ALPHA_VERTEX;
380 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
383 f->param_type = CPT_LIGHT;
384 f->light_propagates = true;
386 f->pointable = false;
388 f->buildable_to = true;
389 f->liquid_type = LIQUID_SOURCE;
390 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
391 f->liquid_alternative_flowing = CONTENT_WATER;
392 f->liquid_alternative_source = CONTENT_WATERSOURCE;
395 f = &content_features(i);
396 f->setInventoryTexture("torch_on_floor.png");
397 f->param_type = CPT_LIGHT;
398 f->light_propagates = true;
399 f->sunlight_propagates = true;
400 f->solidness = 0; // drawn separately, makes no faces
402 f->wall_mounted = true;
403 f->air_equivalent = true;
404 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
405 f->light_source = LIGHT_MAX-1;
406 f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
408 i = CONTENT_SIGN_WALL;
409 f = &content_features(i);
410 f->setInventoryTexture("sign_wall.png");
411 f->param_type = CPT_LIGHT;
412 f->light_propagates = true;
413 f->sunlight_propagates = true;
414 f->solidness = 0; // drawn separately, makes no faces
416 f->wall_mounted = true;
417 f->air_equivalent = true;
418 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
419 if(f->initial_metadata == NULL)
420 f->initial_metadata = new SignNodeMetadata("Some sign");
421 f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
424 f = &content_features(i);
425 f->param_type = CPT_FACEDIR_SIMPLE;
426 f->setAllTextures("chest_side.png");
427 f->setTexture(0, "chest_top.png");
428 f->setTexture(1, "chest_top.png");
429 f->setTexture(5, "chest_front.png"); // Z-
430 f->setInventoryTexture("chest_top.png");
431 //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
432 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
433 if(f->initial_metadata == NULL)
434 f->initial_metadata = new ChestNodeMetadata();
435 setWoodLikeDiggingProperties(f->digging_properties, 1.0);
438 f = &content_features(i);
439 f->param_type = CPT_FACEDIR_SIMPLE;
440 f->setAllTextures("furnace_side.png");
441 f->setTexture(5, "furnace_front.png"); // Z-
442 f->setInventoryTexture("furnace_front.png");
443 //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
444 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
445 if(f->initial_metadata == NULL)
446 f->initial_metadata = new FurnaceNodeMetadata();
447 setStoneLikeDiggingProperties(f->digging_properties, 3.0);
450 f = &content_features(i);
451 f->setAllTextures("cobble.png");
452 f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
453 f->param_type = CPT_NONE;
454 f->is_ground_content = true;
455 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
456 setStoneLikeDiggingProperties(f->digging_properties, 0.9);
458 i = CONTENT_MOSSYCOBBLE;
459 f = &content_features(i);
460 f->setAllTextures("mossycobble.png");
461 f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
462 f->param_type = CPT_NONE;
463 f->is_ground_content = true;
464 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
465 setStoneLikeDiggingProperties(f->digging_properties, 0.8);
468 f = &content_features(i);
469 f->setAllTextures("steel_block.png");
470 f->setInventoryTextureCube("steel_block.png", "steel_block.png",
472 f->param_type = CPT_NONE;
473 f->is_ground_content = true;
474 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
475 setStoneLikeDiggingProperties(f->digging_properties, 5.0);
477 // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
481 Add MesePick to everything
483 for(u16 i=0; i<256; i++)
485 content_features(i).digging_properties.set("MesePick",
486 DiggingProperties(true, 0.0, 65535./1337));
491 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
494 DiggingProperties(true, 15.0*toughness, 0));
497 DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
499 DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
500 list.set("SteelPick",
501 DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
503 /*list.set("MesePick",
504 DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
507 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
510 DiggingProperties(true, 0.75*toughness, 0));
513 DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
515 DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
516 list.set("SteelShovel",
517 DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
520 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
523 DiggingProperties(true, 3.0*toughness, 0));
526 DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
528 DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
530 DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));