Create framework for getting rid of global definitions of node/tool/item/whatever...
[oweals/minetest.git] / src / content_mapnode.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 // For g_settings
21 #include "main.h"
22
23 #include "content_mapnode.h"
24 #include "mapnode.h"
25 #include "content_nodemeta.h"
26 #include "settings.h"
27 #include "mapnode_contentfeatures.h"
28
29 #define WATER_ALPHA 160
30
31 #define WATER_VISC 1
32 #define LAVA_VISC 7
33
34 void setConstantMaterialProperties(MaterialProperties &mprop, float time)
35 {
36         mprop.diggability = DIGGABLE_CONSTANT;
37         mprop.constant_time = time;
38 }
39
40 void setStoneLikeMaterialProperties(MaterialProperties &mprop, float toughness)
41 {
42         mprop.diggability = DIGGABLE_NORMAL;
43         mprop.weight = 5.0 * toughness;
44         mprop.crackiness = 1.0;
45         mprop.crumbliness = -0.1;
46         mprop.cuttability = -0.2;
47 }
48
49 void setDirtLikeMaterialProperties(MaterialProperties &mprop, float toughness)
50 {
51         mprop.diggability = DIGGABLE_NORMAL;
52         mprop.weight = toughness * 1.2;
53         mprop.crackiness = 0;
54         mprop.crumbliness = 1.2;
55         mprop.cuttability = -0.4;
56 }
57
58 void setGravelLikeMaterialProperties(MaterialProperties &mprop, float toughness)
59 {
60         mprop.diggability = DIGGABLE_NORMAL;
61         mprop.weight = toughness * 2.0;
62         mprop.crackiness = 0.5;
63         mprop.crumbliness = 1.5;
64         mprop.cuttability = -1.0;
65 }
66
67 void setWoodLikeMaterialProperties(MaterialProperties &mprop, float toughness)
68 {
69         mprop.diggability = DIGGABLE_NORMAL;
70         mprop.weight = toughness * 1.0;
71         mprop.crackiness = 0.75;
72         mprop.crumbliness = -1.0;
73         mprop.cuttability = 1.5;
74 }
75
76 void setLeavesLikeMaterialProperties(MaterialProperties &mprop, float toughness)
77 {
78         mprop.diggability = DIGGABLE_NORMAL;
79         mprop.weight = -0.5 * toughness;
80         mprop.crackiness = 0;
81         mprop.crumbliness = 0;
82         mprop.cuttability = 2.0;
83 }
84
85 void setGlassLikeMaterialProperties(MaterialProperties &mprop, float toughness)
86 {
87         mprop.diggability = DIGGABLE_NORMAL;
88         mprop.weight = 0.1 * toughness;
89         mprop.crackiness = 2.0;
90         mprop.crumbliness = -1.0;
91         mprop.cuttability = -1.0;
92 }
93
94 /*
95         A conversion table for backwards compatibility.
96         Maps <=v19 content types to current ones.
97         Should never be touched.
98 */
99 content_t trans_table_19[21][2] = {
100         {CONTENT_GRASS, 1},
101         {CONTENT_TREE, 4},
102         {CONTENT_LEAVES, 5},
103         {CONTENT_GRASS_FOOTSTEPS, 6},
104         {CONTENT_MESE, 7},
105         {CONTENT_MUD, 8},
106         {CONTENT_CLOUD, 10},
107         {CONTENT_COALSTONE, 11},
108         {CONTENT_WOOD, 12},
109         {CONTENT_SAND, 13},
110         {CONTENT_COBBLE, 18},
111         {CONTENT_STEEL, 19},
112         {CONTENT_GLASS, 20},
113         {CONTENT_MOSSYCOBBLE, 22},
114         {CONTENT_GRAVEL, 23},
115         {CONTENT_SANDSTONE, 24},
116         {CONTENT_CACTUS, 25},
117         {CONTENT_BRICK, 26},
118         {CONTENT_CLAY, 27},
119         {CONTENT_PAPYRUS, 28},
120         {CONTENT_BOOKSHELF, 29},
121 };
122
123 MapNode mapnode_translate_from_internal(MapNode n_from, u8 version)
124 {
125         MapNode result = n_from;
126         if(version <= 19)
127         {
128                 content_t c_from = n_from.getContent();
129                 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
130                 {
131                         if(trans_table_19[i][0] == c_from)
132                         {
133                                 result.setContent(trans_table_19[i][1]);
134                                 break;
135                         }
136                 }
137         }
138         return result;
139 }
140 MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
141 {
142         MapNode result = n_from;
143         if(version <= 19)
144         {
145                 content_t c_from = n_from.getContent();
146                 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
147                 {
148                         if(trans_table_19[i][1] == c_from)
149                         {
150                                 result.setContent(trans_table_19[i][0]);
151                                 break;
152                         }
153                 }
154         }
155         return result;
156 }
157
158 // See header for description
159 void content_mapnode_init(ITextureSource *tsrc)
160 {
161         if(tsrc == NULL)
162                 dstream<<"INFO: Initial run of content_mapnode_init with "
163                                 "tsrc=NULL. If this segfaults, "
164                                 "there is a bug with something not checking for "
165                                 "the NULL value."<<std::endl;
166         else
167                 dstream<<"INFO: Full run of content_mapnode_init with "
168                                 "tsrc!=NULL"<<std::endl;
169
170         // Read some settings
171         bool new_style_water = g_settings->getBool("new_style_water");
172         bool new_style_leaves = g_settings->getBool("new_style_leaves");
173         bool invisible_stone = g_settings->getBool("invisible_stone");
174         bool opaque_water = g_settings->getBool("opaque_water");
175
176         content_t i;
177         ContentFeatures *f = NULL;
178
179         i = CONTENT_STONE;
180         f = &content_features(i);
181         f->setAllTextures(tsrc, "stone.png");
182         f->setInventoryTextureCube("stone.png", "stone.png", "stone.png", tsrc);
183         f->param_type = CPT_MINERAL;
184         f->is_ground_content = true;
185         f->often_contains_mineral = true;
186         f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 1";
187         setStoneLikeMaterialProperties(f->material, 1.0);
188         if(invisible_stone)
189                 f->solidness = 0; // For debugging, hides regular stone
190         
191         i = CONTENT_GRASS;
192         f = &content_features(i);
193         f->setAllTextures(tsrc, "mud.png^grass_side.png");
194         f->setTexture(tsrc, 0, "grass.png");
195         f->setTexture(tsrc, 1, "mud.png");
196         f->param_type = CPT_MINERAL;
197         f->is_ground_content = true;
198         f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
199         setDirtLikeMaterialProperties(f->material, 1.0);
200         
201         i = CONTENT_GRASS_FOOTSTEPS;
202         f = &content_features(i);
203         f->setAllTextures(tsrc, "mud.png^grass_side.png");
204         f->setTexture(tsrc, 0, "grass_footsteps.png");
205         f->setTexture(tsrc, 1, "mud.png");
206         f->param_type = CPT_MINERAL;
207         f->is_ground_content = true;
208         f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
209         setDirtLikeMaterialProperties(f->material, 1.0);
210         
211         i = CONTENT_MUD;
212         f = &content_features(i);
213         f->setAllTextures(tsrc, "mud.png");
214         f->setInventoryTextureCube("mud.png", "mud.png", "mud.png", tsrc);
215         f->param_type = CPT_MINERAL;
216         f->is_ground_content = true;
217         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
218         setDirtLikeMaterialProperties(f->material, 1.0);
219         
220         i = CONTENT_SAND;
221         f = &content_features(i);
222         f->setAllTextures(tsrc, "sand.png");
223         f->setInventoryTextureCube("sand.png", "sand.png", "sand.png", tsrc);
224         f->param_type = CPT_MINERAL;
225         f->is_ground_content = true;
226         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
227         setDirtLikeMaterialProperties(f->material, 1.0);
228         
229         i = CONTENT_GRAVEL;
230         f = &content_features(i);
231         f->setAllTextures(tsrc, "gravel.png");
232         f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png", tsrc);
233         f->param_type = CPT_MINERAL;
234         f->is_ground_content = true;
235         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
236         setGravelLikeMaterialProperties(f->material, 1.0);
237         
238         i = CONTENT_SANDSTONE;
239         f = &content_features(i);
240         f->setAllTextures(tsrc, "sandstone.png");
241         f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png", tsrc);
242         f->param_type = CPT_MINERAL;
243         f->is_ground_content = true;
244         f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAND)+" 1";
245         setDirtLikeMaterialProperties(f->material, 1.0);
246
247         i = CONTENT_CLAY;
248         f = &content_features(i);
249         f->setAllTextures(tsrc, "clay.png");
250         f->setInventoryTextureCube("clay.png", "clay.png", "clay.png", tsrc);
251         f->param_type = CPT_MINERAL;
252         f->is_ground_content = true;
253         f->dug_item = std::string("CraftItem lump_of_clay 4");
254         setDirtLikeMaterialProperties(f->material, 1.0);
255
256         i = CONTENT_BRICK;
257         f = &content_features(i);
258         f->setAllTextures(tsrc, "brick.png");
259         f->setInventoryTextureCube("brick.png", "brick.png", "brick.png", tsrc);
260         f->param_type = CPT_MINERAL;
261         f->is_ground_content = true;
262         f->dug_item = std::string("CraftItem clay_brick 4");
263         setStoneLikeMaterialProperties(f->material, 1.0);
264
265         i = CONTENT_TREE;
266         f = &content_features(i);
267         f->setAllTextures(tsrc, "tree.png");
268         f->setTexture(tsrc, 0, "tree_top.png");
269         f->setTexture(tsrc, 1, "tree_top.png");
270         f->param_type = CPT_MINERAL;
271         f->is_ground_content = true;
272         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
273         setWoodLikeMaterialProperties(f->material, 1.0);
274         
275         i = CONTENT_JUNGLETREE;
276         f = &content_features(i);
277         f->setAllTextures(tsrc, "jungletree.png");
278         f->setTexture(tsrc, 0, "jungletree_top.png");
279         f->setTexture(tsrc, 1, "jungletree_top.png");
280         f->param_type = CPT_MINERAL;
281         //f->is_ground_content = true;
282         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
283         setWoodLikeMaterialProperties(f->material, 1.0);
284         
285         i = CONTENT_JUNGLEGRASS;
286         f = &content_features(i);
287         f->setInventoryTexture("junglegrass.png", tsrc);
288         f->used_texturenames["junglegrass.png"] = true;
289         f->light_propagates = true;
290         f->param_type = CPT_LIGHT;
291         //f->is_ground_content = true;
292         f->air_equivalent = false; // grass grows underneath
293         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
294         f->solidness = 0; // drawn separately, makes no faces
295         f->walkable = false;
296         setLeavesLikeMaterialProperties(f->material, 1.0);
297
298         i = CONTENT_LEAVES;
299         f = &content_features(i);
300         f->light_propagates = true;
301         //f->param_type = CPT_MINERAL;
302         f->param_type = CPT_LIGHT;
303         //f->is_ground_content = true;
304         if(new_style_leaves)
305         {
306                 f->solidness = 0; // drawn separately, makes no faces
307                 f->visual_solidness = 1;
308                 f->setAllTextures(tsrc, "leaves.png");
309                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png", tsrc);
310         }
311         else
312         {
313                 f->setAllTextures(tsrc, "[noalpha:leaves.png");
314         }
315         f->extra_dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAPLING)+" 1";
316         f->extra_dug_item_rarity = 20;
317         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
318         setLeavesLikeMaterialProperties(f->material, 1.0);
319
320         i = CONTENT_CACTUS;
321         f = &content_features(i);
322         f->setAllTextures(tsrc, "cactus_side.png");
323         f->setTexture(tsrc, 0, "cactus_top.png");
324         f->setTexture(tsrc, 1, "cactus_top.png");
325         f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png", tsrc);
326         f->param_type = CPT_MINERAL;
327         f->is_ground_content = true;
328         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
329         setWoodLikeMaterialProperties(f->material, 0.75);
330
331         i = CONTENT_PAPYRUS;
332         f = &content_features(i);
333         f->setInventoryTexture("papyrus.png", tsrc);
334         f->used_texturenames["papyrus.png"] = true;
335         f->light_propagates = true;
336         f->param_type = CPT_LIGHT;
337         f->is_ground_content = true;
338         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
339         f->solidness = 0; // drawn separately, makes no faces
340         f->walkable = false;
341         setLeavesLikeMaterialProperties(f->material, 0.5);
342
343         i = CONTENT_BOOKSHELF;
344         f = &content_features(i);
345         f->setAllTextures(tsrc, "bookshelf.png");
346         f->setTexture(tsrc, 0, "wood.png");
347         f->setTexture(tsrc, 1, "wood.png");
348         // FIXME: setInventoryTextureCube() only cares for the first texture
349         f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png", tsrc);
350         //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png", tsrc);
351         f->param_type = CPT_MINERAL;
352         f->is_ground_content = true;
353         setWoodLikeMaterialProperties(f->material, 0.75);
354
355         i = CONTENT_GLASS;
356         f = &content_features(i);
357         f->light_propagates = true;
358         f->sunlight_propagates = true;
359         f->param_type = CPT_LIGHT;
360         f->is_ground_content = true;
361         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
362         f->solidness = 0; // drawn separately, makes no faces
363         f->visual_solidness = 1;
364         f->setAllTextures(tsrc, "glass.png");
365         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png", tsrc);
366         setGlassLikeMaterialProperties(f->material, 1.0);
367
368         i = CONTENT_FENCE;
369         f = &content_features(i);
370         f->light_propagates = true;
371         f->param_type = CPT_LIGHT;
372         f->is_ground_content = true;
373         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
374         f->solidness = 0; // drawn separately, makes no faces
375         f->air_equivalent = true; // grass grows underneath
376         f->setInventoryTexture("fence.png", tsrc);
377         f->used_texturenames["fence.png"] = true;
378         setWoodLikeMaterialProperties(f->material, 0.75);
379
380         i = CONTENT_RAIL;
381         f = &content_features(i);
382         f->setInventoryTexture("rail.png", tsrc);
383         f->used_texturenames["rail.png"] = true;
384         f->light_propagates = true;
385         f->param_type = CPT_LIGHT;
386         f->is_ground_content = true;
387         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
388         f->solidness = 0; // drawn separately, makes no faces
389         f->air_equivalent = true; // grass grows underneath
390         f->walkable = false;
391         f->selection_box.type = NODEBOX_FIXED;
392         setDirtLikeMaterialProperties(f->material, 0.75);
393
394         i = CONTENT_LADDER;
395         f = &content_features(i);
396         f->setInventoryTexture("ladder.png", tsrc);
397         f->used_texturenames["ladder.png"] = true;
398         f->light_propagates = true;
399         f->param_type = CPT_LIGHT;
400         f->is_ground_content = true;
401         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
402         f->wall_mounted = true;
403         f->solidness = 0;
404         f->air_equivalent = true;
405         f->walkable = false;
406         f->climbable = true;
407         f->selection_box.type = NODEBOX_WALLMOUNTED;
408         setWoodLikeMaterialProperties(f->material, 0.5);
409
410         // Deprecated
411         i = CONTENT_COALSTONE;
412         f = &content_features(i);
413         f->setAllTextures(tsrc, "stone.png^mineral_coal.png");
414         f->is_ground_content = true;
415         setStoneLikeMaterialProperties(f->material, 1.5);
416         
417         i = CONTENT_WOOD;
418         f = &content_features(i);
419         f->setAllTextures(tsrc, "wood.png");
420         f->setInventoryTextureCube("wood.png", "wood.png", "wood.png", tsrc);
421         f->is_ground_content = true;
422         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
423         setWoodLikeMaterialProperties(f->material, 0.75);
424         
425         i = CONTENT_MESE;
426         f = &content_features(i);
427         f->setAllTextures(tsrc, "mese.png");
428         f->setInventoryTextureCube("mese.png", "mese.png", "mese.png", tsrc);
429         f->is_ground_content = true;
430         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
431         setStoneLikeMaterialProperties(f->material, 0.5);
432         
433         i = CONTENT_CLOUD;
434         f = &content_features(i);
435         f->setAllTextures(tsrc, "cloud.png");
436         f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png", tsrc);
437         f->is_ground_content = true;
438         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
439         
440         i = CONTENT_AIR;
441         f = &content_features(i);
442         f->param_type = CPT_LIGHT;
443         f->light_propagates = true;
444         f->sunlight_propagates = true;
445         f->solidness = 0;
446         f->walkable = false;
447         f->pointable = false;
448         f->diggable = false;
449         f->buildable_to = true;
450         f->air_equivalent = true;
451         
452         i = CONTENT_WATER;
453         f = &content_features(i);
454         f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
455         f->param_type = CPT_LIGHT;
456         f->light_propagates = true;
457         f->solidness = 0; // Drawn separately, makes no faces
458         f->visual_solidness = 1;
459         f->walkable = false;
460         f->pointable = false;
461         f->diggable = false;
462         f->buildable_to = true;
463         f->liquid_type = LIQUID_FLOWING;
464         f->liquid_alternative_flowing = CONTENT_WATER;
465         f->liquid_alternative_source = CONTENT_WATERSOURCE;
466         f->liquid_viscosity = WATER_VISC;
467 #ifndef SERVER
468         if(!opaque_water)
469                 f->vertex_alpha = WATER_ALPHA;
470         f->post_effect_color = video::SColor(64, 100, 100, 200);
471         if(f->special_material == NULL && tsrc)
472         {
473                 // Flowing water material
474                 f->special_material = new video::SMaterial;
475                 f->special_material->setFlag(video::EMF_LIGHTING, false);
476                 f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
477                 f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
478                 f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
479                 if(!opaque_water)
480                         f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
481                 AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
482                                 tsrc->getTextureId("water.png")));
483                 f->special_material->setTexture(0, pa_water1->atlas);
484
485                 // Flowing water material, backface culled
486                 f->special_material2 = new video::SMaterial;
487                 *f->special_material2 = *f->special_material;
488                 f->special_material2->setFlag(video::EMF_BACK_FACE_CULLING, true);
489                 
490                 f->special_atlas = pa_water1;
491         }
492 #endif
493         
494         i = CONTENT_WATERSOURCE;
495         f = &content_features(i);
496         //f->setInventoryTexture("water.png", tsrc);
497         f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
498         if(new_style_water)
499         {
500                 f->solidness = 0; // drawn separately, makes no faces
501         }
502         else // old style
503         {
504                 f->solidness = 1;
505 #ifndef SERVER
506                 TileSpec t;
507                 if(tsrc)
508                         t.texture = tsrc->getTexture("water.png");
509                 
510                 if(!opaque_water){
511                         t.alpha = WATER_ALPHA;
512                         t.material_type = MATERIAL_ALPHA_VERTEX;
513                 }
514                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
515                 f->setAllTiles(t);
516 #endif
517         }
518         f->param_type = CPT_LIGHT;
519         f->light_propagates = true;
520         f->walkable = false;
521         f->pointable = false;
522         f->diggable = false;
523         f->buildable_to = true;
524         f->liquid_type = LIQUID_SOURCE;
525         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
526         f->liquid_alternative_flowing = CONTENT_WATER;
527         f->liquid_alternative_source = CONTENT_WATERSOURCE;
528         f->liquid_viscosity = WATER_VISC;
529 #ifndef SERVER
530         if(!opaque_water)
531                 f->vertex_alpha = WATER_ALPHA;
532         f->post_effect_color = video::SColor(64, 100, 100, 200);
533         if(f->special_material == NULL && tsrc)
534         {
535                 // New-style water source material (mostly unused)
536                 f->special_material = new video::SMaterial;
537                 f->special_material->setFlag(video::EMF_LIGHTING, false);
538                 f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
539                 f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
540                 f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
541                 f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
542                 AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
543                                 tsrc->getTextureId("water.png")));
544                 f->special_material->setTexture(0, pa_water1->atlas);
545                 f->special_atlas = pa_water1;
546         }
547 #endif
548         
549         i = CONTENT_LAVA;
550         f = &content_features(i);
551         f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
552         f->used_texturenames["lava.png"] = true;
553         f->param_type = CPT_LIGHT;
554         f->light_propagates = false;
555         f->light_source = LIGHT_MAX-1;
556         f->solidness = 0; // Drawn separately, makes no faces
557         f->visual_solidness = 1; // Does not completely cover block boundaries
558         f->walkable = false;
559         f->pointable = false;
560         f->diggable = false;
561         f->buildable_to = true;
562         f->liquid_type = LIQUID_FLOWING;
563         f->liquid_alternative_flowing = CONTENT_LAVA;
564         f->liquid_alternative_source = CONTENT_LAVASOURCE;
565         f->liquid_viscosity = LAVA_VISC;
566         f->damage_per_second = 4*2;
567 #ifndef SERVER
568         f->post_effect_color = video::SColor(192, 255, 64, 0);
569         if(f->special_material == NULL && tsrc)
570         {
571                 // Flowing lava material
572                 f->special_material = new video::SMaterial;
573                 f->special_material->setFlag(video::EMF_LIGHTING, false);
574                 f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
575                 f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
576                 f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
577                 f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
578
579                 AtlasPointer *pa_lava1 = new AtlasPointer(
580                         tsrc->getTexture(
581                                 tsrc->getTextureId("lava.png")));
582                 f->special_material->setTexture(0, pa_lava1->atlas);
583
584                 // Flowing lava material, backface culled
585                 f->special_material2 = new video::SMaterial;
586                 *f->special_material2 = *f->special_material;
587                 f->special_material2->setFlag(video::EMF_BACK_FACE_CULLING, true);
588
589                 f->special_atlas = pa_lava1;
590         }
591 #endif
592         
593         i = CONTENT_LAVASOURCE;
594         f = &content_features(i);
595         f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
596         f->used_texturenames["ladder.png"] = true;
597         if(new_style_water)
598         {
599                 f->solidness = 0; // drawn separately, makes no faces
600         }
601         else // old style
602         {
603                 f->solidness = 2;
604 #ifndef SERVER
605                 TileSpec t;
606                 if(tsrc)
607                         t.texture = tsrc->getTexture("lava.png");
608                 
609                 //t.alpha = 255;
610                 //t.material_type = MATERIAL_ALPHA_VERTEX;
611                 //t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
612                 f->setAllTiles(t);
613 #endif
614         }
615         f->param_type = CPT_LIGHT;
616         f->light_propagates = false;
617         f->light_source = LIGHT_MAX-1;
618         f->walkable = false;
619         f->pointable = false;
620         f->diggable = false;
621         f->buildable_to = true;
622         f->liquid_type = LIQUID_SOURCE;
623         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
624         f->liquid_alternative_flowing = CONTENT_LAVA;
625         f->liquid_alternative_source = CONTENT_LAVASOURCE;
626         f->liquid_viscosity = LAVA_VISC;
627         f->damage_per_second = 4*2;
628 #ifndef SERVER
629         f->post_effect_color = video::SColor(192, 255, 64, 0);
630         if(f->special_material == NULL && tsrc)
631         {
632                 // New-style lava source material (mostly unused)
633                 f->special_material = new video::SMaterial;
634                 f->special_material->setFlag(video::EMF_LIGHTING, false);
635                 f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
636                 f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
637                 f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
638                 f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
639                 AtlasPointer *pa_lava1 = new AtlasPointer(
640                         tsrc->getTexture(
641                                 tsrc->getTextureId("lava.png")));
642                 f->special_material->setTexture(0, pa_lava1->atlas);
643
644                 f->special_atlas = pa_lava1;
645         }
646 #endif
647         
648         i = CONTENT_TORCH;
649         f = &content_features(i);
650         f->setInventoryTexture("torch_on_floor.png", tsrc);
651         f->used_texturenames["torch_on_floor.png"] = true;
652         f->used_texturenames["torch_on_ceiling.png"] = true;
653         f->used_texturenames["torch_on_floor.png"] = true;
654         f->used_texturenames["torch.png"] = true;
655         f->param_type = CPT_LIGHT;
656         f->light_propagates = true;
657         f->sunlight_propagates = true;
658         f->solidness = 0; // drawn separately, makes no faces
659         f->walkable = false;
660         f->wall_mounted = true;
661         f->air_equivalent = true;
662         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
663         f->light_source = LIGHT_MAX-1;
664         f->selection_box.type = NODEBOX_WALLMOUNTED;
665         f->selection_box.wall_top = core::aabbox3d<f32>(
666                         -BS/10, BS/2-BS/3.333*2, -BS/10, BS/10, BS/2, BS/10);
667         f->selection_box.wall_bottom = core::aabbox3d<f32>(
668                         -BS/10, -BS/2, -BS/10, BS/10, -BS/2+BS/3.333*2, BS/10);
669         f->selection_box.wall_side = core::aabbox3d<f32>(
670                         -BS/2, -BS/3.333, -BS/10, -BS/2+BS/3.333, BS/3.333, BS/10);
671         setConstantMaterialProperties(f->material, 0.0);
672         
673         i = CONTENT_SIGN_WALL;
674         f = &content_features(i);
675         f->setInventoryTexture("sign_wall.png", tsrc);
676         f->used_texturenames["sign_wall.png"] = true;
677         f->param_type = CPT_LIGHT;
678         f->light_propagates = true;
679         f->sunlight_propagates = true;
680         f->solidness = 0; // drawn separately, makes no faces
681         f->walkable = false;
682         f->wall_mounted = true;
683         f->air_equivalent = true;
684         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
685         if(f->initial_metadata == NULL)
686                 f->initial_metadata = new SignNodeMetadata(NULL, "Some sign");
687         setConstantMaterialProperties(f->material, 0.5);
688         f->selection_box.type = NODEBOX_WALLMOUNTED;
689         
690         i = CONTENT_CHEST;
691         f = &content_features(i);
692         f->param_type = CPT_FACEDIR_SIMPLE;
693         f->setAllTextures(tsrc, "chest_side.png");
694         f->setTexture(tsrc, 0, "chest_top.png");
695         f->setTexture(tsrc, 1, "chest_top.png");
696         f->setTexture(tsrc, 5, "chest_front.png"); // Z-
697         f->setInventoryTexture("chest_top.png", tsrc);
698         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
699         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
700         if(f->initial_metadata == NULL)
701                 f->initial_metadata = new ChestNodeMetadata(NULL);
702         setWoodLikeMaterialProperties(f->material, 1.0);
703         
704         i = CONTENT_LOCKABLE_CHEST;
705         f = &content_features(i);
706         f->param_type = CPT_FACEDIR_SIMPLE;
707         f->setAllTextures(tsrc, "chest_side.png");
708         f->setTexture(tsrc, 0, "chest_top.png");
709         f->setTexture(tsrc, 1, "chest_top.png");
710         f->setTexture(tsrc, 5, "chest_lock.png"); // Z-
711         f->setInventoryTexture("chest_lock.png", tsrc);
712         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
713         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
714         if(f->initial_metadata == NULL)
715                 f->initial_metadata = new LockingChestNodeMetadata(NULL);
716         setWoodLikeMaterialProperties(f->material, 1.0);
717
718         i = CONTENT_FURNACE;
719         f = &content_features(i);
720         f->param_type = CPT_FACEDIR_SIMPLE;
721         f->setAllTextures(tsrc, "furnace_side.png");
722         f->setTexture(tsrc, 5, "furnace_front.png"); // Z-
723         f->setInventoryTexture("furnace_front.png", tsrc);
724         //f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
725         f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 6";
726         if(f->initial_metadata == NULL)
727                 f->initial_metadata = new FurnaceNodeMetadata(NULL);
728         setStoneLikeMaterialProperties(f->material, 3.0);
729         
730         i = CONTENT_COBBLE;
731         f = &content_features(i);
732         f->setAllTextures(tsrc, "cobble.png");
733         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png", tsrc);
734         f->param_type = CPT_NONE;
735         f->is_ground_content = true;
736         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
737         setStoneLikeMaterialProperties(f->material, 0.9);
738
739         i = CONTENT_MOSSYCOBBLE;
740         f = &content_features(i);
741         f->setAllTextures(tsrc, "mossycobble.png");
742         f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png", tsrc);
743         f->param_type = CPT_NONE;
744         f->is_ground_content = true;
745         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
746         setStoneLikeMaterialProperties(f->material, 0.8);
747         
748         i = CONTENT_STEEL;
749         f = &content_features(i);
750         f->setAllTextures(tsrc, "steel_block.png");
751         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
752                         "steel_block.png", tsrc);
753         f->param_type = CPT_NONE;
754         f->is_ground_content = true;
755         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
756         setStoneLikeMaterialProperties(f->material, 5.0);
757         
758         i = CONTENT_NC;
759         f = &content_features(i);
760         f->param_type = CPT_FACEDIR_SIMPLE;
761         f->setAllTextures(tsrc, "nc_side.png");
762         f->setTexture(tsrc, 5, "nc_front.png"); // Z-
763         f->setTexture(tsrc, 4, "nc_back.png"); // Z+
764         f->setInventoryTexture("nc_front.png", tsrc);
765         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
766         setStoneLikeMaterialProperties(f->material, 3.0);
767         
768         i = CONTENT_NC_RB;
769         f = &content_features(i);
770         f->setAllTextures(tsrc, "nc_rb.png");
771         f->setInventoryTexture("nc_rb.png", tsrc);
772         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
773         setStoneLikeMaterialProperties(f->material, 3.0);
774
775         i = CONTENT_SAPLING;
776         f = &content_features(i);
777         f->param_type = CPT_LIGHT;
778         f->setAllTextures(tsrc, "sapling.png");
779         f->setInventoryTexture("sapling.png", tsrc);
780         f->used_texturenames["sapling.png"] = true;
781         f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
782         f->light_propagates = true;
783         f->air_equivalent = false;
784         f->solidness = 0; // drawn separately, makes no faces
785         f->walkable = false;
786         setConstantMaterialProperties(f->material, 0.0);
787         
788         i = CONTENT_APPLE;
789         f = &content_features(i);
790         f->setInventoryTexture("apple.png", tsrc);
791         f->used_texturenames["apple.png"] = true;
792         f->param_type = CPT_LIGHT;
793         f->light_propagates = true;
794         f->sunlight_propagates = true;
795         f->solidness = 0; // drawn separately, makes no faces
796         f->walkable = false;
797         f->air_equivalent = true;
798         f->dug_item = std::string("CraftItem apple 1");
799         setConstantMaterialProperties(f->material, 0.0);
800 }
801
802