]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapnode.cpp
fixed block unloading from memory (a better fix coming next)
[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_TREE;
103         f = &content_features(i);
104         f->setAllTextures("tree.png");
105         f->setTexture(0, "tree_top.png");
106         f->setTexture(1, "tree_top.png");
107         f->param_type = CPT_MINERAL;
108         f->is_ground_content = true;
109         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
110         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
111         
112         i = CONTENT_LEAVES;
113         f = &content_features(i);
114         f->light_propagates = true;
115         //f->param_type = CPT_MINERAL;
116         f->param_type = CPT_LIGHT;
117         f->is_ground_content = true;
118         if(new_style_leaves)
119         {
120                 f->solidness = 0; // drawn separately, makes no faces
121                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
122         }
123         else
124         {
125                 f->setAllTextures("[noalpha:leaves.png");
126         }
127         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
128         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
129
130         i = CONTENT_GLASS;
131         f = &content_features(i);
132         f->light_propagates = true;
133         f->param_type = CPT_LIGHT;
134         f->is_ground_content = true;
135         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
136         f->solidness = 0; // drawn separately, makes no faces
137         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
138         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
139
140         i = CONTENT_FENCE;
141         f = &content_features(i);
142         f->light_propagates = true;
143         f->param_type = CPT_LIGHT;
144         f->is_ground_content = true;
145         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
146         f->solidness = 0; // drawn separately, makes no faces
147         f->air_equivalent = true; // grass grows underneath
148         f->setInventoryTexture("item_fence.png");
149         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
150
151         // Deprecated
152         i = CONTENT_COALSTONE;
153         f = &content_features(i);
154         //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
155         f->setAllTextures("stone.png^mineral_coal.png");
156         f->is_ground_content = true;
157         setStoneLikeDiggingProperties(f->digging_properties, 1.5);
158         
159         i = CONTENT_WOOD;
160         f = &content_features(i);
161         f->setAllTextures("wood.png");
162         f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
163         f->is_ground_content = true;
164         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
165         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
166         
167         i = CONTENT_MESE;
168         f = &content_features(i);
169         f->setAllTextures("mese.png");
170         f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
171         f->is_ground_content = true;
172         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
173         setStoneLikeDiggingProperties(f->digging_properties, 0.5);
174         
175         i = CONTENT_CLOUD;
176         f = &content_features(i);
177         f->setAllTextures("cloud.png");
178         f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
179         f->is_ground_content = true;
180         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
181         
182         i = CONTENT_AIR;
183         f = &content_features(i);
184         f->param_type = CPT_LIGHT;
185         f->light_propagates = true;
186         f->sunlight_propagates = true;
187         f->solidness = 0;
188         f->walkable = false;
189         f->pointable = false;
190         f->diggable = false;
191         f->buildable_to = true;
192         f->air_equivalent = true;
193         
194         i = CONTENT_WATER;
195         f = &content_features(i);
196         f->setInventoryTextureCube("water.png", "water.png", "water.png");
197         f->param_type = CPT_LIGHT;
198         f->light_propagates = true;
199         f->solidness = 0; // Drawn separately, makes no faces
200         f->walkable = false;
201         f->pointable = false;
202         f->diggable = false;
203         f->buildable_to = true;
204         f->liquid_type = LIQUID_FLOWING;
205         f->liquid_alternative_flowing = CONTENT_WATER;
206         
207         i = CONTENT_WATERSOURCE;
208         f = &content_features(i);
209         //f->setInventoryTexture("water.png");
210         f->setInventoryTextureCube("water.png", "water.png", "water.png");
211         if(new_style_water)
212         {
213                 f->solidness = 0; // drawn separately, makes no faces
214         }
215         else // old style
216         {
217                 f->solidness = 1;
218
219                 TileSpec t;
220                 if(g_texturesource)
221                         t.texture = g_texturesource->getTexture("water.png");
222                 
223                 t.alpha = WATER_ALPHA;
224                 t.material_type = MATERIAL_ALPHA_VERTEX;
225                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
226                 f->setAllTiles(t);
227         }
228         f->param_type = CPT_LIGHT;
229         f->light_propagates = true;
230         f->walkable = false;
231         f->pointable = false;
232         f->diggable = false;
233         f->buildable_to = true;
234         f->liquid_type = LIQUID_SOURCE;
235         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
236         f->liquid_alternative_flowing = CONTENT_WATER;
237         
238         i = CONTENT_TORCH;
239         f = &content_features(i);
240         f->setInventoryTexture("torch_on_floor.png");
241         f->param_type = CPT_LIGHT;
242         f->light_propagates = true;
243         f->sunlight_propagates = true;
244         f->solidness = 0; // drawn separately, makes no faces
245         f->walkable = false;
246         f->wall_mounted = true;
247         f->air_equivalent = true;
248         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
249         f->light_source = LIGHT_MAX-1;
250         f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
251         
252         i = CONTENT_SIGN_WALL;
253         f = &content_features(i);
254         f->setInventoryTexture("sign_wall.png");
255         f->param_type = CPT_LIGHT;
256         f->light_propagates = true;
257         f->sunlight_propagates = true;
258         f->solidness = 0; // drawn separately, makes no faces
259         f->walkable = false;
260         f->wall_mounted = true;
261         f->air_equivalent = true;
262         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
263         if(f->initial_metadata == NULL)
264                 f->initial_metadata = new SignNodeMetadata("Some sign");
265         f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
266         
267         i = CONTENT_CHEST;
268         f = &content_features(i);
269         f->param_type = CPT_FACEDIR_SIMPLE;
270         f->setAllTextures("chest_side.png");
271         f->setTexture(0, "chest_top.png");
272         f->setTexture(1, "chest_top.png");
273         f->setTexture(5, "chest_front.png"); // Z-
274         f->setInventoryTexture("chest_top.png");
275         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
276         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
277         if(f->initial_metadata == NULL)
278                 f->initial_metadata = new ChestNodeMetadata();
279         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
280         
281         i = CONTENT_FURNACE;
282         f = &content_features(i);
283         f->param_type = CPT_FACEDIR_SIMPLE;
284         f->setAllTextures("furnace_side.png");
285         f->setTexture(5, "furnace_front.png"); // Z-
286         f->setInventoryTexture("furnace_front.png");
287         //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
288         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
289         if(f->initial_metadata == NULL)
290                 f->initial_metadata = new FurnaceNodeMetadata();
291         setStoneLikeDiggingProperties(f->digging_properties, 3.0);
292         
293         i = CONTENT_COBBLE;
294         f = &content_features(i);
295         f->setAllTextures("cobble.png");
296         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
297         f->param_type = CPT_NONE;
298         f->is_ground_content = true;
299         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
300         setStoneLikeDiggingProperties(f->digging_properties, 0.9);
301
302         i = CONTENT_MOSSYCOBBLE;
303         f = &content_features(i);
304         f->setAllTextures("mossycobble.png");
305         f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
306         f->param_type = CPT_NONE;
307         f->is_ground_content = true;
308         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
309         setStoneLikeDiggingProperties(f->digging_properties, 0.8);
310         
311         i = CONTENT_STEEL;
312         f = &content_features(i);
313         f->setAllTextures("steel_block.png");
314         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
315                         "steel_block.png");
316         f->param_type = CPT_NONE;
317         f->is_ground_content = true;
318         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
319         setStoneLikeDiggingProperties(f->digging_properties, 5.0);
320         
321         // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
322         
323
324         /*
325                 Add MesePick to everything
326         */
327         for(u16 i=0; i<256; i++)
328         {
329                 content_features(i).digging_properties.set("MesePick",
330                                 DiggingProperties(true, 0.0, 65535./1337));
331         }
332
333 }
334
335 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
336 {
337         list.set("",
338                         DiggingProperties(true, 15.0*toughness, 0));
339         
340         list.set("WPick",
341                         DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
342         list.set("STPick",
343                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
344         list.set("SteelPick",
345                         DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
346
347         /*list.set("MesePick",
348                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
349 }
350
351 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
352 {
353         list.set("",
354                         DiggingProperties(true, 0.75*toughness, 0));
355         
356         list.set("WShovel",
357                         DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
358         list.set("STShovel",
359                         DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
360         list.set("SteelShovel",
361                         DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
362 }
363
364 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
365 {
366         list.set("",
367                         DiggingProperties(true, 3.0*toughness, 0));
368         
369         list.set("WAxe",
370                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
371         list.set("STAxe",
372                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
373         list.set("SteelAxe",
374                         DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));
375 }
376
377