]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapnode.cpp
be7f95adcd6edfe8f217843d0f2911b624f47d5d
[dragonfireclient.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
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);
33
34 void content_mapnode_init()
35 {
36         // Read some settings
37         bool new_style_water = g_settings.getBool("new_style_water");
38         bool new_style_leaves = g_settings.getBool("new_style_leaves");
39         bool invisible_stone = g_settings.getBool("invisible_stone");
40
41         u8 i;
42         ContentFeatures *f = NULL;
43
44         i = CONTENT_STONE;
45         f = &content_features(i);
46         f->setAllTextures("stone.png");
47         f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
48         f->param_type = CPT_MINERAL;
49         f->is_ground_content = true;
50         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
51         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
52         if(invisible_stone)
53                 f->solidness = 0; // For debugging, hides regular stone
54         
55         i = CONTENT_GRASS;
56         f = &content_features(i);
57         f->setAllTextures("mud.png^grass_side.png");
58         f->setTexture(0, "grass.png");
59         f->setTexture(1, "mud.png");
60         f->param_type = CPT_MINERAL;
61         f->is_ground_content = true;
62         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
63         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
64         
65         i = CONTENT_GRASS_FOOTSTEPS;
66         f = &content_features(i);
67         f->setAllTextures("mud.png^grass_side.png");
68         f->setTexture(0, "grass_footsteps.png");
69         f->setTexture(1, "mud.png");
70         f->param_type = CPT_MINERAL;
71         f->is_ground_content = true;
72         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
73         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
74         
75         i = CONTENT_MUD;
76         f = &content_features(i);
77         f->setAllTextures("mud.png");
78         f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
79         f->param_type = CPT_MINERAL;
80         f->is_ground_content = true;
81         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
82         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
83         
84         i = CONTENT_SAND;
85         f = &content_features(i);
86         f->setAllTextures("sand.png");
87         f->setInventoryTextureCube("sand.png", "sand.png", "sand.png");
88         f->param_type = CPT_MINERAL;
89         f->is_ground_content = true;
90         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
91         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
92         
93         i = CONTENT_GRAVEL;
94         f = &content_features(i);
95         f->setAllTextures("gravel.png");
96         f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png");
97         f->param_type = CPT_MINERAL;
98         f->is_ground_content = true;
99         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
100         setDirtLikeDiggingProperties(f->digging_properties, 1.75);
101         
102         i = CONTENT_SANDSTONE;
103         f = &content_features(i);
104         f->setAllTextures("sandstone.png");
105         f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png");
106         f->param_type = CPT_MINERAL;
107         f->is_ground_content = true;
108         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_SAND)+" 1";
109         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
110
111         i = CONTENT_CLAY;
112         f = &content_features(i);
113         f->setAllTextures("clay.png");
114         f->setInventoryTextureCube("clay.png", "clay.png", "clay.png");
115         f->param_type = CPT_MINERAL;
116         f->is_ground_content = true;
117         f->dug_item = std::string("CraftItem lump_of_clay 4");
118         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
119
120         i = CONTENT_BRICK;
121         f = &content_features(i);
122         f->setAllTextures("brick.png");
123         f->setInventoryTextureCube("brick.png", "brick.png", "brick.png");
124         f->param_type = CPT_MINERAL;
125         f->is_ground_content = true;
126         f->dug_item = std::string("CraftItem clay_brick 4");
127         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
128
129         i = CONTENT_TREE;
130         f = &content_features(i);
131         f->setAllTextures("tree.png");
132         f->setTexture(0, "tree_top.png");
133         f->setTexture(1, "tree_top.png");
134         f->param_type = CPT_MINERAL;
135         f->is_ground_content = true;
136         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
137         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
138         
139         i = CONTENT_JUNGLETREE;
140         f = &content_features(i);
141         f->setAllTextures("jungletree.png");
142         f->setTexture(0, "jungletree_top.png");
143         f->setTexture(1, "jungletree_top.png");
144         f->param_type = CPT_MINERAL;
145         //f->is_ground_content = true;
146         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
147         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
148         
149         i = CONTENT_JUNGLEGRASS;
150         f = &content_features(i);
151         f->setInventoryTexture("junglegrass.png");
152         f->light_propagates = true;
153         f->param_type = CPT_LIGHT;
154         //f->is_ground_content = true;
155         f->air_equivalent = false; // grass grows underneath
156         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
157         f->solidness = 0; // drawn separately, makes no faces
158         f->walkable = false;
159         setWoodLikeDiggingProperties(f->digging_properties, 0.10);
160
161         i = CONTENT_LEAVES;
162         f = &content_features(i);
163         f->light_propagates = true;
164         //f->param_type = CPT_MINERAL;
165         f->param_type = CPT_LIGHT;
166         //f->is_ground_content = true;
167         if(new_style_leaves)
168         {
169                 f->solidness = 0; // drawn separately, makes no faces
170                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
171         }
172         else
173         {
174                 f->setAllTextures("[noalpha:leaves.png");
175         }
176         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
177         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
178
179         i = CONTENT_CACTUS;
180         f = &content_features(i);
181         f->setAllTextures("cactus_side.png");
182         f->setTexture(0, "cactus_top.png");
183         f->setTexture(1, "cactus_top.png");
184         f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
185         f->param_type = CPT_MINERAL;
186         f->is_ground_content = true;
187         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
188         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
189
190         i = CONTENT_PAPYRUS;
191         f = &content_features(i);
192         f->setInventoryTexture("papyrus.png");
193         f->light_propagates = true;
194         f->param_type = CPT_LIGHT;
195         f->is_ground_content = true;
196         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
197         f->solidness = 0; // drawn separately, makes no faces
198         f->walkable = false;
199         setWoodLikeDiggingProperties(f->digging_properties, 0.25);
200
201         i = CONTENT_BOOKSHELF;
202         f = &content_features(i);
203         f->setAllTextures("bookshelf.png");
204         f->setTexture(0, "wood.png");
205         f->setTexture(1, "wood.png");
206         // FIXME: setInventoryTextureCube() only cares for the first texture
207         f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png");
208         //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
209         f->param_type = CPT_MINERAL;
210         f->is_ground_content = true;
211         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
212
213         i = CONTENT_GLASS;
214         f = &content_features(i);
215         f->light_propagates = true;
216         f->param_type = CPT_LIGHT;
217         f->is_ground_content = true;
218         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
219         f->solidness = 0; // drawn separately, makes no faces
220         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
221         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
222
223         i = CONTENT_FENCE;
224         f = &content_features(i);
225         f->light_propagates = true;
226         f->param_type = CPT_LIGHT;
227         f->is_ground_content = true;
228         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
229         f->solidness = 0; // drawn separately, makes no faces
230         f->air_equivalent = true; // grass grows underneath
231         f->setInventoryTexture("item_fence.png");
232         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
233
234         i = CONTENT_RAIL;
235         f = &content_features(i);
236         f->setInventoryTexture("rail.png");
237         f->light_propagates = true;
238         f->param_type = CPT_LIGHT;
239         f->is_ground_content = true;
240         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
241         f->solidness = 0; // drawn separately, makes no faces
242         f->air_equivalent = true; // grass grows underneath
243         f->walkable = false;
244         setDirtLikeDiggingProperties(f->digging_properties, 0.75);
245
246         // Deprecated
247         i = CONTENT_COALSTONE;
248         f = &content_features(i);
249         f->setAllTextures("stone.png^mineral_coal.png");
250         f->is_ground_content = true;
251         setStoneLikeDiggingProperties(f->digging_properties, 1.5);
252         
253         i = CONTENT_WOOD;
254         f = &content_features(i);
255         f->setAllTextures("wood.png");
256         f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
257         f->is_ground_content = true;
258         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
259         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
260         
261         i = CONTENT_MESE;
262         f = &content_features(i);
263         f->setAllTextures("mese.png");
264         f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
265         f->is_ground_content = true;
266         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
267         setStoneLikeDiggingProperties(f->digging_properties, 0.5);
268         
269         i = CONTENT_CLOUD;
270         f = &content_features(i);
271         f->setAllTextures("cloud.png");
272         f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
273         f->is_ground_content = true;
274         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
275         
276         i = CONTENT_AIR;
277         f = &content_features(i);
278         f->param_type = CPT_LIGHT;
279         f->light_propagates = true;
280         f->sunlight_propagates = true;
281         f->solidness = 0;
282         f->walkable = false;
283         f->pointable = false;
284         f->diggable = false;
285         f->buildable_to = true;
286         f->air_equivalent = true;
287         
288         i = CONTENT_WATER;
289         f = &content_features(i);
290         f->setInventoryTextureCube("water.png", "water.png", "water.png");
291         f->param_type = CPT_LIGHT;
292         f->light_propagates = true;
293         f->solidness = 0; // Drawn separately, makes no faces
294         f->walkable = false;
295         f->pointable = false;
296         f->diggable = false;
297         f->buildable_to = true;
298         f->liquid_type = LIQUID_FLOWING;
299         f->liquid_alternative_flowing = CONTENT_WATER;
300         f->liquid_alternative_source = CONTENT_WATERSOURCE;
301         
302         i = CONTENT_WATERSOURCE;
303         f = &content_features(i);
304         //f->setInventoryTexture("water.png");
305         f->setInventoryTextureCube("water.png", "water.png", "water.png");
306         if(new_style_water)
307         {
308                 f->solidness = 0; // drawn separately, makes no faces
309         }
310         else // old style
311         {
312                 f->solidness = 1;
313
314                 TileSpec t;
315                 if(g_texturesource)
316                         t.texture = g_texturesource->getTexture("water.png");
317                 
318                 t.alpha = WATER_ALPHA;
319                 t.material_type = MATERIAL_ALPHA_VERTEX;
320                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
321                 f->setAllTiles(t);
322         }
323         f->param_type = CPT_LIGHT;
324         f->light_propagates = true;
325         f->walkable = false;
326         f->pointable = false;
327         f->diggable = false;
328         f->buildable_to = true;
329         f->liquid_type = LIQUID_SOURCE;
330         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
331         f->liquid_alternative_flowing = CONTENT_WATER;
332         f->liquid_alternative_source = CONTENT_WATERSOURCE;
333         
334         i = CONTENT_TORCH;
335         f = &content_features(i);
336         f->setInventoryTexture("torch_on_floor.png");
337         f->param_type = CPT_LIGHT;
338         f->light_propagates = true;
339         f->sunlight_propagates = true;
340         f->solidness = 0; // drawn separately, makes no faces
341         f->walkable = false;
342         f->wall_mounted = true;
343         f->air_equivalent = true;
344         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
345         f->light_source = LIGHT_MAX-1;
346         f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
347         
348         i = CONTENT_SIGN_WALL;
349         f = &content_features(i);
350         f->setInventoryTexture("sign_wall.png");
351         f->param_type = CPT_LIGHT;
352         f->light_propagates = true;
353         f->sunlight_propagates = true;
354         f->solidness = 0; // drawn separately, makes no faces
355         f->walkable = false;
356         f->wall_mounted = true;
357         f->air_equivalent = true;
358         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
359         if(f->initial_metadata == NULL)
360                 f->initial_metadata = new SignNodeMetadata("Some sign");
361         f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
362         
363         i = CONTENT_CHEST;
364         f = &content_features(i);
365         f->param_type = CPT_FACEDIR_SIMPLE;
366         f->setAllTextures("chest_side.png");
367         f->setTexture(0, "chest_top.png");
368         f->setTexture(1, "chest_top.png");
369         f->setTexture(5, "chest_front.png"); // Z-
370         f->setInventoryTexture("chest_top.png");
371         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
372         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
373         if(f->initial_metadata == NULL)
374                 f->initial_metadata = new ChestNodeMetadata();
375         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
376         
377         i = CONTENT_FURNACE;
378         f = &content_features(i);
379         f->param_type = CPT_FACEDIR_SIMPLE;
380         f->setAllTextures("furnace_side.png");
381         f->setTexture(5, "furnace_front.png"); // Z-
382         f->setInventoryTexture("furnace_front.png");
383         //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
384         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
385         if(f->initial_metadata == NULL)
386                 f->initial_metadata = new FurnaceNodeMetadata();
387         setStoneLikeDiggingProperties(f->digging_properties, 3.0);
388         
389         i = CONTENT_COBBLE;
390         f = &content_features(i);
391         f->setAllTextures("cobble.png");
392         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
393         f->param_type = CPT_NONE;
394         f->is_ground_content = true;
395         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
396         setStoneLikeDiggingProperties(f->digging_properties, 0.9);
397
398         i = CONTENT_MOSSYCOBBLE;
399         f = &content_features(i);
400         f->setAllTextures("mossycobble.png");
401         f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
402         f->param_type = CPT_NONE;
403         f->is_ground_content = true;
404         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
405         setStoneLikeDiggingProperties(f->digging_properties, 0.8);
406         
407         i = CONTENT_STEEL;
408         f = &content_features(i);
409         f->setAllTextures("steel_block.png");
410         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
411                         "steel_block.png");
412         f->param_type = CPT_NONE;
413         f->is_ground_content = true;
414         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
415         setStoneLikeDiggingProperties(f->digging_properties, 5.0);
416         
417         // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
418         
419
420         /*
421                 Add MesePick to everything
422         */
423         for(u16 i=0; i<256; i++)
424         {
425                 content_features(i).digging_properties.set("MesePick",
426                                 DiggingProperties(true, 0.0, 65535./1337));
427         }
428
429 }
430
431 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
432 {
433         list.set("",
434                         DiggingProperties(true, 15.0*toughness, 0));
435         
436         list.set("WPick",
437                         DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
438         list.set("STPick",
439                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
440         list.set("SteelPick",
441                         DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
442
443         /*list.set("MesePick",
444                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
445 }
446
447 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
448 {
449         list.set("",
450                         DiggingProperties(true, 0.75*toughness, 0));
451         
452         list.set("WShovel",
453                         DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
454         list.set("STShovel",
455                         DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
456         list.set("SteelShovel",
457                         DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
458 }
459
460 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
461 {
462         list.set("",
463                         DiggingProperties(true, 3.0*toughness, 0));
464         
465         list.set("WAxe",
466                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
467         list.set("STAxe",
468                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
469         list.set("SteelAxe",
470                         DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));
471 }
472
473