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"
29 ContentFeatures::~ContentFeatures()
35 void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
39 tiles[i].texture = g_texturesource->getTexture(name);
44 tiles[i].alpha = alpha;
45 tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
48 if(inventory_texture == NULL)
49 setInventoryTexture(name);
52 void ContentFeatures::setInventoryTexture(std::string imgname)
54 if(g_texturesource == NULL)
57 imgname += "^[forcesingle";
59 inventory_texture = g_texturesource->getTextureRaw(imgname);
62 void ContentFeatures::setInventoryTextureCube(std::string top,
63 std::string left, std::string right)
65 if(g_texturesource == NULL)
68 str_replace_char(top, '^', '&');
69 str_replace_char(left, '^', '&');
70 str_replace_char(right, '^', '&');
72 std::string imgname_full;
73 imgname_full += "[inventorycube{";
78 imgname_full += right;
79 inventory_texture = g_texturesource->getTextureRaw(imgname_full);
82 struct ContentFeatures g_content_features[256];
84 ContentFeatures & content_features(u8 i)
86 return g_content_features[i];
90 See mapnode.h for description.
94 if(g_texturesource == NULL)
96 dstream<<"INFO: Initial run of init_mapnode with "
97 "g_texturesource=NULL. If this segfaults, "
98 "there is a bug with something not checking for "
99 "the NULL value."<<std::endl;
103 dstream<<"INFO: Full run of init_mapnode with "
104 "g_texturesource!=NULL"<<std::endl;
107 // Read some settings
108 bool new_style_water = g_settings.getBool("new_style_water");
109 bool new_style_leaves = g_settings.getBool("new_style_leaves");
112 Initialize content feature table
116 Set initial material type to same in all tiles, so that the
117 same material can be used in more stuff.
118 This is set according to the leaves because they are the only
119 differing material to which all materials can be changed to
120 get this optimization.
122 u8 initial_material_type = MATERIAL_ALPHA_SIMPLE;
123 /*if(new_style_leaves)
124 initial_material_type = MATERIAL_ALPHA_SIMPLE;
126 initial_material_type = MATERIAL_ALPHA_NONE;*/
127 for(u16 i=0; i<256; i++)
129 ContentFeatures *f = &g_content_features[i];
130 for(u16 j=0; j<6; j++)
131 f->tiles[j].material_type = initial_material_type;
135 ContentFeatures *f = NULL;
138 f = &g_content_features[i];
139 f->setAllTextures("stone.png");
140 f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
141 f->param_type = CPT_MINERAL;
142 f->is_ground_content = true;
143 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
146 f = &g_content_features[i];
147 f->setAllTextures("mud.png^grass_side.png");
148 f->setTexture(0, "grass.png");
149 f->setTexture(1, "mud.png");
150 f->param_type = CPT_MINERAL;
151 f->is_ground_content = true;
152 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
154 i = CONTENT_GRASS_FOOTSTEPS;
155 f = &g_content_features[i];
156 f->setAllTextures("mud.png^grass_side.png");
157 f->setTexture(0, "grass_footsteps.png");
158 f->setTexture(1, "mud.png");
159 f->param_type = CPT_MINERAL;
160 f->is_ground_content = true;
161 f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
164 f = &g_content_features[i];
165 f->setAllTextures("mud.png");
166 f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
167 f->param_type = CPT_MINERAL;
168 f->is_ground_content = true;
169 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
172 f = &g_content_features[i];
173 f->setAllTextures("sand.png");
174 f->param_type = CPT_MINERAL;
175 f->is_ground_content = true;
176 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
179 f = &g_content_features[i];
180 f->setAllTextures("tree.png");
181 f->setTexture(0, "tree_top.png");
182 f->setTexture(1, "tree_top.png");
183 f->param_type = CPT_MINERAL;
184 f->is_ground_content = true;
185 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
188 f = &g_content_features[i];
189 f->light_propagates = true;
190 //f->param_type = CPT_MINERAL;
191 f->param_type = CPT_LIGHT;
192 f->is_ground_content = true;
195 f->solidness = 0; // drawn separately, makes no faces
196 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
200 f->setAllTextures("[noalpha:leaves.png");
202 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
205 i = CONTENT_COALSTONE;
206 f = &g_content_features[i];
207 //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
208 f->setAllTextures("stone.png^mineral_coal.png");
209 f->is_ground_content = true;
212 f = &g_content_features[i];
213 f->setAllTextures("wood.png");
214 f->is_ground_content = true;
215 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
218 f = &g_content_features[i];
219 f->setAllTextures("mese.png");
220 f->is_ground_content = true;
221 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
224 f = &g_content_features[i];
225 f->setAllTextures("cloud.png");
226 f->is_ground_content = true;
227 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
230 f = &g_content_features[i];
231 f->param_type = CPT_LIGHT;
232 f->light_propagates = true;
233 f->sunlight_propagates = true;
236 f->pointable = false;
238 f->buildable_to = true;
241 f = &g_content_features[i];
242 f->setInventoryTextureCube("water.png", "water.png", "water.png");
243 f->param_type = CPT_LIGHT;
244 f->light_propagates = true;
245 f->solidness = 0; // Drawn separately, makes no faces
247 f->pointable = false;
249 f->buildable_to = true;
250 f->liquid_type = LIQUID_FLOWING;
252 i = CONTENT_WATERSOURCE;
253 f = &g_content_features[i];
254 f->setInventoryTexture("water.png");
257 f->solidness = 0; // drawn separately, makes no faces
265 t.texture = g_texturesource->getTexture("water.png");
267 t.alpha = WATER_ALPHA;
268 t.material_type = MATERIAL_ALPHA_VERTEX;
269 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
272 f->param_type = CPT_LIGHT;
273 f->light_propagates = true;
275 f->pointable = false;
277 f->buildable_to = true;
278 f->liquid_type = LIQUID_SOURCE;
279 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
282 f = &g_content_features[i];
283 f->setInventoryTexture("torch_on_floor.png");
284 f->param_type = CPT_LIGHT;
285 f->light_propagates = true;
286 f->solidness = 0; // drawn separately, makes no faces
288 f->wall_mounted = true;
289 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
291 i = CONTENT_SIGN_WALL;
292 f = &g_content_features[i];
293 f->setInventoryTexture("sign_wall.png");
294 f->param_type = CPT_LIGHT;
295 f->light_propagates = true;
296 f->sunlight_propagates = true;
297 f->solidness = 0; // drawn separately, makes no faces
299 f->wall_mounted = true;
300 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
301 if(f->initial_metadata == NULL)
302 f->initial_metadata = new SignNodeMetadata("Some sign");
305 f = &g_content_features[i];
306 f->param_type = CPT_FACEDIR_SIMPLE;
307 f->setAllTextures("chest_side.png");
308 f->setTexture(0, "chest_top.png");
309 f->setTexture(1, "chest_top.png");
310 f->setTexture(5, "chest_front.png"); // Z-
311 f->setInventoryTexture("chest_top.png");
312 //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
313 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
314 if(f->initial_metadata == NULL)
315 f->initial_metadata = new ChestNodeMetadata();
318 f = &g_content_features[i];
319 f->param_type = CPT_FACEDIR_SIMPLE;
320 f->setAllTextures("furnace_side.png");
321 f->setTexture(5, "furnace_front.png"); // Z-
322 f->setInventoryTexture("furnace_front.png");
323 f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
327 v3s16 facedir_rotate(u8 facedir, v3s16 dir)
330 Face 2 (normally Z-) direction:
337 if(facedir==0) // Same
338 newdir = v3s16(dir.X, dir.Y, dir.Z);
339 else if(facedir == 1) // Face is taken from rotXZccv(-90)
340 newdir = v3s16(-dir.Z, dir.Y, dir.X);
341 else if(facedir == 2) // Face is taken from rotXZccv(180)
342 newdir = v3s16(-dir.X, dir.Y, -dir.Z);
343 else if(facedir == 3) // Face is taken from rotXZccv(90)
344 newdir = v3s16(dir.Z, dir.Y, -dir.X);
350 TileSpec MapNode::getTile(v3s16 dir)
352 if(content_features(d).param_type == CPT_FACEDIR_SIMPLE)
353 dir = facedir_rotate(param1, dir);
359 if(dir == v3s16(0,0,0))
361 else if(dir == v3s16(0,1,0))
363 else if(dir == v3s16(0,-1,0))
365 else if(dir == v3s16(1,0,0))
367 else if(dir == v3s16(-1,0,0))
369 else if(dir == v3s16(0,0,1))
371 else if(dir == v3s16(0,0,-1))
376 spec = content_features(d).tiles[0];
378 spec = content_features(d).tiles[dir_i];
381 If it contains some mineral, change texture id
383 if(content_features(d).param_type == CPT_MINERAL && g_texturesource)
385 u8 mineral = param & 0x1f;
386 std::string mineral_texture_name = mineral_block_texture(mineral);
387 if(mineral_texture_name != "")
389 u32 orig_id = spec.texture.id;
390 std::string texture_name = g_texturesource->getTextureName(orig_id);
391 //texture_name += "^blit:";
393 texture_name += mineral_texture_name;
394 u32 new_id = g_texturesource->getTextureId(texture_name);
395 spec.texture = g_texturesource->getTexture(new_id);
402 u8 MapNode::getMineral()
404 if(content_features(d).param_type == CPT_MINERAL)
412 // Pointers to c_str()s g_content_features[i].inventory_image_path
413 //const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT] = {0};
415 void init_content_inventory_texture_paths()
417 dstream<<"DEPRECATED "<<__FUNCTION_NAME<<std::endl;
418 /*for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
420 g_content_inventory_texture_paths[i] =
421 g_content_features[i].inventory_image_path.c_str();