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 "mapnode_contentfeatures.h"
22 #include "main.h" // For g_settings and g_texturesource
23 #include "nodemetadata.h"
25 struct ContentFeatures g_content_features[MAX_CONTENT+1];
28 Initialize content feature table.
30 Must be called before accessing the table.
32 void init_contentfeatures()
36 Set initial material type to same in all tiles, so that the
37 same material can be used in more stuff.
38 This is set according to the leaves because they are the only
39 differing material to which all materials can be changed to
40 get this optimization.
42 u8 initial_material_type = MATERIAL_ALPHA_SIMPLE;
43 /*if(new_style_leaves)
44 initial_material_type = MATERIAL_ALPHA_SIMPLE;
46 initial_material_type = MATERIAL_ALPHA_NONE;*/
47 for(u16 i=0; i<MAX_CONTENT+1; i++)
49 ContentFeatures *f = &g_content_features[i];
53 for(u16 j=0; j<6; j++)
54 f->tiles[j].material_type = initial_material_type;
59 Initially set every block to be shown as an unknown block.
60 Don't touch CONTENT_IGNORE or CONTENT_AIR.
62 for(u16 i=0; i<MAX_CONTENT+1; i++)
64 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
66 ContentFeatures *f = &g_content_features[i];
67 f->setAllTextures("unknown_block.png");
68 f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
71 // Make CONTENT_IGNORE to not block the view when occlusion culling
72 content_features(CONTENT_IGNORE).solidness = 0;
76 ContentFeatures::~ContentFeatures()
78 delete initial_metadata;
80 delete special_material;
86 void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
88 used_texturenames[name] = true;
92 tiles[i].texture = g_texturesource->getTexture(name);
97 tiles[i].alpha = alpha;
98 tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
101 if(inventory_texture == NULL)
102 setInventoryTexture(name);
105 void ContentFeatures::setInventoryTexture(std::string imgname)
107 if(g_texturesource == NULL)
110 imgname += "^[forcesingle";
112 inventory_texture = g_texturesource->getTextureRaw(imgname);
115 void ContentFeatures::setInventoryTextureCube(std::string top,
116 std::string left, std::string right)
118 if(g_texturesource == NULL)
121 str_replace_char(top, '^', '&');
122 str_replace_char(left, '^', '&');
123 str_replace_char(right, '^', '&');
125 std::string imgname_full;
126 imgname_full += "[inventorycube{";
129 imgname_full += left;
131 imgname_full += right;
132 inventory_texture = g_texturesource->getTextureRaw(imgname_full);
136 ContentFeatures & content_features(content_t i)
138 return g_content_features[i];
140 ContentFeatures & content_features(MapNode &n)
142 return content_features(n.getContent());