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);
199 f = &content_features(i);
200 f->light_propagates = true;
201 //f->param_type = CPT_MINERAL;
202 f->param_type = CPT_LIGHT;
203 f->is_ground_content = true;
206 f->solidness = 0; // drawn separately, makes no faces
207 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
211 f->setAllTextures("[noalpha:leaves.png");
213 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
214 setWoodLikeDiggingProperties(f->digging_properties, 0.15);
217 f = &content_features(i);
218 f->setAllTextures("cactus_side.png");
219 f->setTexture(0, "cactus_top.png");
220 f->setTexture(1, "cactus_top.png");
221 f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
222 f->param_type = CPT_MINERAL;
223 f->is_ground_content = true;
224 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
225 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
228 f = &content_features(i);
229 f->setInventoryTexture("papyrus.png");
230 f->light_propagates = true;
231 f->param_type = CPT_LIGHT;
232 f->is_ground_content = true;
233 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
234 f->solidness = 0; // drawn separately, makes no faces
236 setWoodLikeDiggingProperties(f->digging_properties, 0.25);
238 i = CONTENT_BOOKSHELF;
239 f = &content_features(i);
240 f->setAllTextures("bookshelf.png");
241 f->setTexture(0, "wood.png");
242 f->setTexture(1, "wood.png");
243 // FIXME: setInventoryTextureCube() only cares for the first texture
244 f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png");
245 //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
246 f->param_type = CPT_MINERAL;
247 f->is_ground_content = true;
248 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
251 f = &content_features(i);
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
257 f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
258 setWoodLikeDiggingProperties(f->digging_properties, 0.15);
261 f = &content_features(i);
262 f->light_propagates = true;
263 f->param_type = CPT_LIGHT;
264 f->is_ground_content = true;
265 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
266 f->solidness = 0; // drawn separately, makes no faces
267 f->air_equivalent = true; // grass grows underneath
268 f->setInventoryTexture("item_fence.png");
269 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
272 f = &content_features(i);
273 f->setInventoryTexture("rail.png");
274 f->light_propagates = true;
275 f->param_type = CPT_LIGHT;
276 f->is_ground_content = true;
277 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
278 f->solidness = 0; // drawn separately, makes no faces
279 f->air_equivalent = true; // grass grows underneath
281 setDirtLikeDiggingProperties(f->digging_properties, 0.75);
284 i = CONTENT_COALSTONE;
285 f = &content_features(i);
286 f->setAllTextures("stone.png^mineral_coal.png");
287 f->is_ground_content = true;
288 setStoneLikeDiggingProperties(f->digging_properties, 1.5);
291 f = &content_features(i);
292 f->setAllTextures("wood.png");
293 f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
294 f->is_ground_content = true;
295 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
296 setWoodLikeDiggingProperties(f->digging_properties, 0.75);
299 f = &content_features(i);
300 f->setAllTextures("mese.png");
301 f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
302 f->is_ground_content = true;
303 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
304 setStoneLikeDiggingProperties(f->digging_properties, 0.5);
307 f = &content_features(i);
308 f->setAllTextures("cloud.png");
309 f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
310 f->is_ground_content = true;
311 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
314 f = &content_features(i);
315 f->param_type = CPT_LIGHT;
316 f->light_propagates = true;
317 f->sunlight_propagates = true;
320 f->pointable = false;
322 f->buildable_to = true;
323 f->air_equivalent = true;
326 f = &content_features(i);
327 f->setInventoryTextureCube("water.png", "water.png", "water.png");
328 f->param_type = CPT_LIGHT;
329 f->light_propagates = true;
330 f->solidness = 0; // Drawn separately, makes no faces
332 f->pointable = false;
334 f->buildable_to = true;
335 f->liquid_type = LIQUID_FLOWING;
336 f->liquid_alternative_flowing = CONTENT_WATER;
337 f->liquid_alternative_source = CONTENT_WATERSOURCE;
339 i = CONTENT_WATERSOURCE;
340 f = &content_features(i);
341 //f->setInventoryTexture("water.png");
342 f->setInventoryTextureCube("water.png", "water.png", "water.png");
345 f->solidness = 0; // drawn separately, makes no faces
353 t.texture = g_texturesource->getTexture("water.png");
355 t.alpha = WATER_ALPHA;
356 t.material_type = MATERIAL_ALPHA_VERTEX;
357 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
360 f->param_type = CPT_LIGHT;
361 f->light_propagates = true;
363 f->pointable = false;
365 f->buildable_to = true;
366 f->liquid_type = LIQUID_SOURCE;
367 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
368 f->liquid_alternative_flowing = CONTENT_WATER;
369 f->liquid_alternative_source = CONTENT_WATERSOURCE;
372 f = &content_features(i);
373 f->setInventoryTexture("torch_on_floor.png");
374 f->param_type = CPT_LIGHT;
375 f->light_propagates = true;
376 f->sunlight_propagates = true;
377 f->solidness = 0; // drawn separately, makes no faces
379 f->wall_mounted = true;
380 f->air_equivalent = true;
381 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
382 f->light_source = LIGHT_MAX-1;
383 f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
385 i = CONTENT_SIGN_WALL;
386 f = &content_features(i);
387 f->setInventoryTexture("sign_wall.png");
388 f->param_type = CPT_LIGHT;
389 f->light_propagates = true;
390 f->sunlight_propagates = true;
391 f->solidness = 0; // drawn separately, makes no faces
393 f->wall_mounted = true;
394 f->air_equivalent = true;
395 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
396 if(f->initial_metadata == NULL)
397 f->initial_metadata = new SignNodeMetadata("Some sign");
398 f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
401 f = &content_features(i);
402 f->param_type = CPT_FACEDIR_SIMPLE;
403 f->setAllTextures("chest_side.png");
404 f->setTexture(0, "chest_top.png");
405 f->setTexture(1, "chest_top.png");
406 f->setTexture(5, "chest_front.png"); // Z-
407 f->setInventoryTexture("chest_top.png");
408 //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
409 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
410 if(f->initial_metadata == NULL)
411 f->initial_metadata = new ChestNodeMetadata();
412 setWoodLikeDiggingProperties(f->digging_properties, 1.0);
415 f = &content_features(i);
416 f->param_type = CPT_FACEDIR_SIMPLE;
417 f->setAllTextures("furnace_side.png");
418 f->setTexture(5, "furnace_front.png"); // Z-
419 f->setInventoryTexture("furnace_front.png");
420 //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
421 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
422 if(f->initial_metadata == NULL)
423 f->initial_metadata = new FurnaceNodeMetadata();
424 setStoneLikeDiggingProperties(f->digging_properties, 3.0);
427 f = &content_features(i);
428 f->setAllTextures("cobble.png");
429 f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
430 f->param_type = CPT_NONE;
431 f->is_ground_content = true;
432 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
433 setStoneLikeDiggingProperties(f->digging_properties, 0.9);
435 i = CONTENT_MOSSYCOBBLE;
436 f = &content_features(i);
437 f->setAllTextures("mossycobble.png");
438 f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
439 f->param_type = CPT_NONE;
440 f->is_ground_content = true;
441 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
442 setStoneLikeDiggingProperties(f->digging_properties, 0.8);
445 f = &content_features(i);
446 f->setAllTextures("steel_block.png");
447 f->setInventoryTextureCube("steel_block.png", "steel_block.png",
449 f->param_type = CPT_NONE;
450 f->is_ground_content = true;
451 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
452 setStoneLikeDiggingProperties(f->digging_properties, 5.0);
454 // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
458 Add MesePick to everything
460 for(u16 i=0; i<256; i++)
462 content_features(i).digging_properties.set("MesePick",
463 DiggingProperties(true, 0.0, 65535./1337));
468 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
471 DiggingProperties(true, 15.0*toughness, 0));
474 DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
476 DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
477 list.set("SteelPick",
478 DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
480 /*list.set("MesePick",
481 DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
484 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
487 DiggingProperties(true, 0.75*toughness, 0));
490 DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
492 DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
493 list.set("SteelShovel",
494 DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
497 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
500 DiggingProperties(true, 3.0*toughness, 0));
503 DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
505 DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
507 DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));