3 Copyright (C) 2010 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.
20 #include "common_irrlicht.h"
28 #include "nodemetadata.h"
30 ContentFeatures::~ContentFeatures()
36 void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
40 tiles[i].texture = g_texturesource->getTexture(name);
45 tiles[i].alpha = alpha;
46 tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
49 if(inventory_texture == NULL)
50 setInventoryTexture(name);
53 void ContentFeatures::setInventoryTexture(std::string imgname)
55 if(g_texturesource == NULL)
58 imgname += "^[forcesingle";
60 inventory_texture = g_texturesource->getTextureRaw(imgname);
63 void ContentFeatures::setInventoryTextureCube(std::string top,
64 std::string left, std::string right)
66 if(g_texturesource == NULL)
69 str_replace_char(top, '^', '&');
70 str_replace_char(left, '^', '&');
71 str_replace_char(right, '^', '&');
73 std::string imgname_full;
74 imgname_full += "[inventorycube{";
79 imgname_full += right;
80 inventory_texture = g_texturesource->getTextureRaw(imgname_full);
83 struct ContentFeatures g_content_features[256];
85 ContentFeatures & content_features(u8 i)
87 return g_content_features[i];
91 See mapnode.h for description.
95 if(g_texturesource == NULL)
97 dstream<<"INFO: Initial run of init_mapnode with "
98 "g_texturesource=NULL. If this segfaults, "
99 "there is a bug with something not checking for "
100 "the NULL value."<<std::endl;
104 dstream<<"INFO: Full run of init_mapnode with "
105 "g_texturesource!=NULL"<<std::endl;
108 // Read some settings
109 bool new_style_water = g_settings.getBool("new_style_water");
110 bool new_style_leaves = g_settings.getBool("new_style_leaves");
113 Initialize content feature table
117 Set initial material type to same in all tiles, so that the
118 same material can be used in more stuff.
119 This is set according to the leaves because they are the only
120 differing material to which all materials can be changed to
121 get this optimization.
123 u8 initial_material_type = MATERIAL_ALPHA_SIMPLE;
124 /*if(new_style_leaves)
125 initial_material_type = MATERIAL_ALPHA_SIMPLE;
127 initial_material_type = MATERIAL_ALPHA_NONE;*/
128 for(u16 i=0; i<256; i++)
130 ContentFeatures *f = &g_content_features[i];
131 for(u16 j=0; j<6; j++)
132 f->tiles[j].material_type = initial_material_type;
136 ContentFeatures *f = NULL;
139 f = &g_content_features[i];
140 f->setAllTextures("stone.png");
141 f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
142 f->param_type = CPT_MINERAL;
143 f->is_ground_content = true;
144 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
147 f = &g_content_features[i];
148 f->setAllTextures("mud.png^grass_side.png");
149 f->setTexture(0, "grass.png");
150 f->setTexture(1, "mud.png");
151 f->param_type = CPT_MINERAL;
152 f->is_ground_content = true;
153 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
155 i = CONTENT_GRASS_FOOTSTEPS;
156 f = &g_content_features[i];
157 f->setAllTextures("mud.png^grass_side.png");
158 f->setTexture(0, "grass_footsteps.png");
159 f->setTexture(1, "mud.png");
160 f->param_type = CPT_MINERAL;
161 f->is_ground_content = true;
162 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
165 f = &g_content_features[i];
166 f->setAllTextures("mud.png");
167 f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
168 f->param_type = CPT_MINERAL;
169 f->is_ground_content = true;
170 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
173 f = &g_content_features[i];
174 f->setAllTextures("sand.png");
175 f->param_type = CPT_MINERAL;
176 f->is_ground_content = true;
177 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
180 f = &g_content_features[i];
181 f->setAllTextures("tree.png");
182 f->setTexture(0, "tree_top.png");
183 f->setTexture(1, "tree_top.png");
184 f->param_type = CPT_MINERAL;
185 f->is_ground_content = true;
186 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
189 f = &g_content_features[i];
190 f->light_propagates = true;
191 //f->param_type = CPT_MINERAL;
192 f->param_type = CPT_LIGHT;
193 f->is_ground_content = true;
196 f->solidness = 0; // drawn separately, makes no faces
197 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
201 f->setAllTextures("[noalpha:leaves.png");
203 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
206 i = CONTENT_COALSTONE;
207 f = &g_content_features[i];
208 //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
209 f->setAllTextures("stone.png^mineral_coal.png");
210 f->is_ground_content = true;
213 f = &g_content_features[i];
214 f->setAllTextures("wood.png");
215 f->is_ground_content = true;
216 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
219 f = &g_content_features[i];
220 f->setAllTextures("mese.png");
221 f->is_ground_content = true;
222 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
225 f = &g_content_features[i];
226 f->setAllTextures("cloud.png");
227 f->is_ground_content = true;
228 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
231 f = &g_content_features[i];
232 f->param_type = CPT_LIGHT;
233 f->light_propagates = true;
234 f->sunlight_propagates = true;
237 f->pointable = false;
239 f->buildable_to = true;
242 f = &g_content_features[i];
243 f->setInventoryTextureCube("water.png", "water.png", "water.png");
244 f->param_type = CPT_LIGHT;
245 f->light_propagates = true;
246 f->solidness = 0; // Drawn separately, makes no faces
248 f->pointable = false;
250 f->buildable_to = true;
251 f->liquid_type = LIQUID_FLOWING;
253 i = CONTENT_WATERSOURCE;
254 f = &g_content_features[i];
255 f->setInventoryTexture("water.png");
258 f->solidness = 0; // drawn separately, makes no faces
266 t.texture = g_texturesource->getTexture("water.png");
268 t.alpha = WATER_ALPHA;
269 t.material_type = MATERIAL_ALPHA_VERTEX;
270 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
273 f->param_type = CPT_LIGHT;
274 f->light_propagates = true;
276 f->pointable = false;
278 f->buildable_to = true;
279 f->liquid_type = LIQUID_SOURCE;
280 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
283 f = &g_content_features[i];
284 f->setInventoryTexture("torch_on_floor.png");
285 f->param_type = CPT_LIGHT;
286 f->light_propagates = true;
287 f->sunlight_propagates = true;
288 f->solidness = 0; // drawn separately, makes no faces
290 f->wall_mounted = true;
291 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
293 i = CONTENT_SIGN_WALL;
294 f = &g_content_features[i];
295 f->setInventoryTexture("sign_wall.png");
296 f->param_type = CPT_LIGHT;
297 f->light_propagates = true;
298 f->sunlight_propagates = true;
299 f->solidness = 0; // drawn separately, makes no faces
301 f->wall_mounted = true;
302 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
303 if(f->initial_metadata == NULL)
304 f->initial_metadata = new SignNodeMetadata("Some sign");
307 f = &g_content_features[i];
308 f->param_type = CPT_FACEDIR_SIMPLE;
309 f->setAllTextures("chest_side.png");
310 f->setTexture(0, "chest_top.png");
311 f->setTexture(1, "chest_top.png");
312 f->setTexture(5, "chest_front.png"); // Z-
313 f->setInventoryTexture("chest_top.png");
314 //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
315 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
316 if(f->initial_metadata == NULL)
317 f->initial_metadata = new ChestNodeMetadata();
320 f = &g_content_features[i];
321 f->param_type = CPT_FACEDIR_SIMPLE;
322 f->setAllTextures("furnace_side.png");
323 f->setTexture(5, "furnace_front.png"); // Z-
324 f->setInventoryTexture("furnace_front.png");
325 //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
326 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
327 if(f->initial_metadata == NULL)
328 f->initial_metadata = new FurnaceNodeMetadata();
331 f = &g_content_features[i];
332 f->setAllTextures("cobble.png");
333 f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
334 f->param_type = CPT_NONE;
335 f->is_ground_content = true;
336 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
339 f = &g_content_features[i];
340 f->setAllTextures("steel_block.png");
341 f->setInventoryTextureCube("steel_block.png", "steel_block.png",
343 f->param_type = CPT_NONE;
344 f->is_ground_content = true;
345 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
349 v3s16 facedir_rotate(u8 facedir, v3s16 dir)
352 Face 2 (normally Z-) direction:
359 if(facedir==0) // Same
360 newdir = v3s16(dir.X, dir.Y, dir.Z);
361 else if(facedir == 1) // Face is taken from rotXZccv(-90)
362 newdir = v3s16(-dir.Z, dir.Y, dir.X);
363 else if(facedir == 2) // Face is taken from rotXZccv(180)
364 newdir = v3s16(-dir.X, dir.Y, -dir.Z);
365 else if(facedir == 3) // Face is taken from rotXZccv(90)
366 newdir = v3s16(dir.Z, dir.Y, -dir.X);
372 TileSpec MapNode::getTile(v3s16 dir)
374 if(content_features(d).param_type == CPT_FACEDIR_SIMPLE)
375 dir = facedir_rotate(param1, dir);
381 if(dir == v3s16(0,0,0))
383 else if(dir == v3s16(0,1,0))
385 else if(dir == v3s16(0,-1,0))
387 else if(dir == v3s16(1,0,0))
389 else if(dir == v3s16(-1,0,0))
391 else if(dir == v3s16(0,0,1))
393 else if(dir == v3s16(0,0,-1))
398 spec = content_features(d).tiles[0];
400 spec = content_features(d).tiles[dir_i];
403 If it contains some mineral, change texture id
405 if(content_features(d).param_type == CPT_MINERAL && g_texturesource)
407 u8 mineral = param & 0x1f;
408 std::string mineral_texture_name = mineral_block_texture(mineral);
409 if(mineral_texture_name != "")
411 u32 orig_id = spec.texture.id;
412 std::string texture_name = g_texturesource->getTextureName(orig_id);
413 //texture_name += "^blit:";
415 texture_name += mineral_texture_name;
416 u32 new_id = g_texturesource->getTextureId(texture_name);
417 spec.texture = g_texturesource->getTexture(new_id);
424 u8 MapNode::getMineral()
426 if(content_features(d).param_type == CPT_MINERAL)
434 // Pointers to c_str()s g_content_features[i].inventory_image_path
435 //const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT] = {0};
437 void init_content_inventory_texture_paths()
439 dstream<<"DEPRECATED "<<__FUNCTION_NAME<<std::endl;
440 /*for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
442 g_content_inventory_texture_paths[i] =
443 g_content_features[i].inventory_image_path.c_str();