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.
22 #include "main.h" // For g_settings
23 #include "nodemetadata.h"
29 ContentFeatures::~ContentFeatures()
31 delete initial_metadata;
33 delete special_material;
39 void ContentFeatures::setTexture(ITextureSource *tsrc,
40 u16 i, std::string name, u8 alpha)
42 used_texturenames.insert(name);
46 tiles[i].texture = tsrc->getTexture(name);
51 tiles[i].alpha = alpha;
52 tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
55 if(inventory_texture == NULL)
56 setInventoryTexture(name, tsrc);
59 void ContentFeatures::setInventoryTexture(std::string imgname,
65 imgname += "^[forcesingle";
67 inventory_texture_name = imgname;
68 inventory_texture = tsrc->getTextureRaw(imgname);
71 void ContentFeatures::setInventoryTextureCube(std::string top,
72 std::string left, std::string right, ITextureSource *tsrc)
77 str_replace_char(top, '^', '&');
78 str_replace_char(left, '^', '&');
79 str_replace_char(right, '^', '&');
81 std::string imgname_full;
82 imgname_full += "[inventorycube{";
87 imgname_full += right;
88 inventory_texture_name = imgname_full;
89 inventory_texture = tsrc->getTextureRaw(imgname_full);
93 class CNodeDefManager: public IWritableNodeDefManager
96 CNodeDefManager(ITextureSource *tsrc)
100 Set initial material type to same in all tiles, so that the
101 same material can be used in more stuff.
102 This is set according to the leaves because they are the only
103 differing material to which all materials can be changed to
104 get this optimization.
106 u8 initial_material_type = MATERIAL_ALPHA_SIMPLE;
107 /*if(new_style_leaves)
108 initial_material_type = MATERIAL_ALPHA_SIMPLE;
110 initial_material_type = MATERIAL_ALPHA_NONE;*/
111 for(u16 i=0; i<=MAX_CONTENT; i++)
113 ContentFeatures *f = &m_content_features[i];
117 for(u16 j=0; j<6; j++)
118 f->tiles[j].material_type = initial_material_type;
122 Initially set every block to be shown as an unknown block.
123 Don't touch CONTENT_IGNORE or CONTENT_AIR.
125 for(u16 i=0; i<=MAX_CONTENT; i++)
127 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
129 ContentFeatures *f = &m_content_features[i];
130 f->setAllTextures(tsrc, "unknown_block.png");
131 f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
133 // Make CONTENT_IGNORE to not block the view when occlusion culling
134 m_content_features[CONTENT_IGNORE].solidness = 0;
136 virtual ~CNodeDefManager()
139 virtual IWritableNodeDefManager* clone()
141 CNodeDefManager *mgr = new CNodeDefManager(NULL);
142 for(u16 i=0; i<=MAX_CONTENT; i++)
148 virtual const ContentFeatures& get(content_t c) const
150 assert(c <= MAX_CONTENT);
151 return m_content_features[c];
153 virtual const ContentFeatures& get(const MapNode &n) const
155 return get(n.getContent());
158 virtual void set(content_t c, const ContentFeatures &def)
160 infostream<<"registerNode: registering content \""<<c<<"\""<<std::endl;
161 assert(c <= MAX_CONTENT);
162 m_content_features[c] = def;
164 virtual ContentFeatures* getModifiable(content_t c)
166 assert(c <= MAX_CONTENT);
167 return &m_content_features[c];
169 virtual void updateTextures(ITextureSource *tsrc)
172 infostream<<"CNodeDefManager::updateTextures(): Updating "
173 <<"textures in node definitions"<<std::endl;
174 for(u16 i=0; i<=MAX_CONTENT; i++)
176 ContentFeatures *f = &m_content_features[i];
177 for(u16 j=0; j<6; j++)
178 tsrc->updateAP(f->tiles[j].texture);
179 if(f->special_atlas){
180 tsrc->updateAP(*(f->special_atlas));
181 if(f->special_material)
182 f->special_material->setTexture(0, f->special_atlas->atlas);
183 if(f->special_material2)
184 f->special_material2->setTexture(0, f->special_atlas->atlas);
186 if(f->inventory_texture_name != ""){
187 f->inventory_texture =
188 tsrc->getTextureRaw(f->inventory_texture_name);
194 ContentFeatures m_content_features[MAX_CONTENT+1];
197 IWritableNodeDefManager* createNodeDefManager(ITextureSource *tsrc)
199 return new CNodeDefManager(tsrc);