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 = tsrc->getTextureRaw(imgname);
70 void ContentFeatures::setInventoryTextureCube(std::string top,
71 std::string left, std::string right, ITextureSource *tsrc)
76 str_replace_char(top, '^', '&');
77 str_replace_char(left, '^', '&');
78 str_replace_char(right, '^', '&');
80 std::string imgname_full;
81 imgname_full += "[inventorycube{";
86 imgname_full += right;
87 inventory_texture = tsrc->getTextureRaw(imgname_full);
91 class CNodeDefManager: public IWritableNodeDefManager
94 CNodeDefManager(ITextureSource *tsrc)
98 Set initial material type to same in all tiles, so that the
99 same material can be used in more stuff.
100 This is set according to the leaves because they are the only
101 differing material to which all materials can be changed to
102 get this optimization.
104 u8 initial_material_type = MATERIAL_ALPHA_SIMPLE;
105 /*if(new_style_leaves)
106 initial_material_type = MATERIAL_ALPHA_SIMPLE;
108 initial_material_type = MATERIAL_ALPHA_NONE;*/
109 for(u16 i=0; i<=MAX_CONTENT; i++)
111 ContentFeatures *f = &m_content_features[i];
115 for(u16 j=0; j<6; j++)
116 f->tiles[j].material_type = initial_material_type;
120 Initially set every block to be shown as an unknown block.
121 Don't touch CONTENT_IGNORE or CONTENT_AIR.
123 for(u16 i=0; i<=MAX_CONTENT; i++)
125 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
127 ContentFeatures *f = &m_content_features[i];
128 f->setAllTextures(tsrc, "unknown_block.png");
129 f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
131 // Make CONTENT_IGNORE to not block the view when occlusion culling
132 m_content_features[CONTENT_IGNORE].solidness = 0;
134 virtual ~CNodeDefManager()
137 virtual IWritableNodeDefManager* clone()
139 CNodeDefManager *mgr = new CNodeDefManager(NULL);
140 for(u16 i=0; i<=MAX_CONTENT; i++)
146 virtual const ContentFeatures& get(content_t c) const
148 assert(c <= MAX_CONTENT);
149 return m_content_features[c];
151 virtual const ContentFeatures& get(const MapNode &n) const
153 return get(n.getContent());
156 virtual void set(content_t c, const ContentFeatures &def)
158 infostream<<"registerNode: registering content \""<<c<<"\""<<std::endl;
159 assert(c <= MAX_CONTENT);
160 m_content_features[c] = def;
162 virtual ContentFeatures* getModifiable(content_t c)
164 assert(c <= MAX_CONTENT);
165 return &m_content_features[c];
167 virtual void updateTextures(ITextureSource *tsrc)
170 infostream<<"CNodeDefManager::updateTextures(): Updating "
171 <<"textures in node definitions"<<std::endl;
172 for(u16 i=0; i<=MAX_CONTENT; i++)
174 ContentFeatures *f = &m_content_features[i];
175 for(u16 j=0; j<6; j++)
176 tsrc->updateAP(f->tiles[j].texture);
178 tsrc->updateAP(*(f->special_atlas));
183 ContentFeatures m_content_features[MAX_CONTENT+1];
186 IWritableNodeDefManager* createNodeDefManager(ITextureSource *tsrc)
188 return new CNodeDefManager(tsrc);