3 Copyright (C) 2010-2011 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 #ifndef NODEDEF_HEADER
21 #define NODEDEF_HEADER
23 #include "common_irrlicht.h"
30 #include "materials.h" // MaterialProperties
34 TODO: Rename to nodedef.h
42 Used for determining properties of MapNodes by content type without
43 storing such properties in the nodes itself.
47 Initialize content feature table.
49 Must be called before accessing the table.
51 void init_contentfeatures(ITextureSource *tsrc);
60 // Direction for chests and furnaces and such
73 NODEBOX_REGULAR, // Regular block; allows buildable_to
74 NODEBOX_FIXED, // Static separately defined box
75 NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
80 enum NodeBoxType type;
81 // NODEBOX_REGULAR (no parameters)
83 core::aabbox3d<f32> fixed;
84 // NODEBOX_WALLMOUNTED
85 core::aabbox3d<f32> wall_top;
86 core::aabbox3d<f32> wall_bottom;
87 core::aabbox3d<f32> wall_side; // being at the -X side
90 type(NODEBOX_REGULAR),
91 // default is rail-like
92 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
93 // default is sign/ladder-like
94 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
95 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
96 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
106 bool backface_culling;
108 MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
110 backface_culling(backface_culling_)
114 #define CF_SPECIAL_COUNT 2
116 struct ContentFeatures
120 // up down right left back front
123 video::ITexture *inventory_texture;
125 // Post effect color, drawn when the camera is inside the node.
126 video::SColor post_effect_color;
128 // Special material/texture
129 // - Currently used for flowing liquids
130 video::SMaterial *special_materials[CF_SPECIAL_COUNT];
131 AtlasPointer *special_aps[CF_SPECIAL_COUNT];
135 std::string tname_tiles[6];
136 std::string tname_inventory;
137 MaterialSpec mspec_special[CF_SPECIAL_COUNT];
139 bool backface_culling;
140 u8 solidness; // Used when choosing which face is drawn
141 u8 visual_solidness; // When solidness=0, this tells how it looks like
143 // List of all block textures that have been used (value is dummy)
144 // Used for texture atlas making.
145 // Exists on server too for cleaner code in content_mapnode.cpp.
146 std::set<std::string> used_texturenames;
148 // Type of MapNode::param1
149 ContentParamType param_type;
150 // True for all ground-like things like stone and mud, false for eg. trees
151 bool is_ground_content;
152 bool light_propagates;
153 bool sunlight_propagates;
154 // This is used for collision detection.
155 // Also for general solidness queries.
157 // Player can point to these
159 // Player can dig these
161 // Player can climb these
163 // Player can build on these
165 // If true, param2 is set to direction when placed. Used for torches.
166 // NOTE: the direction format is quite inefficient and should be changed
168 // If true, node is equivalent to air. Torches are, air is. Water is not.
169 // Is used for example to check whether a mud block can have grass on.
171 // Whether this content type often contains mineral.
172 // Used for texture atlas creation.
173 // Currently only enabled for CONTENT_STONE.
174 bool often_contains_mineral;
176 // Inventory item string as which the node appears in inventory when dug.
177 // Mineral overrides this.
178 std::string dug_item;
180 // Extra dug item and its rarity
181 std::string extra_dug_item;
182 s32 extra_dug_item_rarity;
184 // Initial metadata is cloned from this
185 NodeMetadata *initial_metadata;
187 // Whether the node is non-liquid, source liquid or flowing liquid
188 enum LiquidType liquid_type;
189 // If the content is liquid, this is the flowing version of the liquid.
190 content_t liquid_alternative_flowing;
191 // If the content is liquid, this is the source version of the liquid.
192 content_t liquid_alternative_source;
193 // Viscosity for fluid flow, ranging from 1 to 7, with
194 // 1 giving almost instantaneous propagation and 7 being
195 // the slowest possible
198 // Amount of light the node emits
201 u32 damage_per_second;
203 NodeBox selection_box;
205 MaterialProperties material;
207 // NOTE: Move relevant properties to here from elsewhere
211 // This isn't exactly complete due to lazyness
212 // TODO: Make it completely reset everything
214 inventory_texture = NULL;
216 post_effect_color = video::SColor(0, 0, 0, 0);
217 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
218 special_materials[j] = NULL;
219 special_aps[j] = NULL;
222 for(u32 i=0; i<6; i++)
224 for(u16 j=0; j<CF_SPECIAL_COUNT; j++)
225 mspec_special[j] = MaterialSpec();
226 tname_inventory = "";
228 backface_culling = true;
230 visual_solidness = 0;
231 used_texturenames.clear();
232 param_type = CPT_NONE;
233 is_ground_content = false;
234 light_propagates = false;
235 sunlight_propagates = false;
240 buildable_to = false;
241 wall_mounted = false;
242 air_equivalent = false;
243 often_contains_mineral = false;
245 initial_metadata = NULL;
246 liquid_type = LIQUID_NONE;
247 liquid_alternative_flowing = CONTENT_IGNORE;
248 liquid_alternative_source = CONTENT_IGNORE;
249 liquid_viscosity = 0;
251 damage_per_second = 0;
252 selection_box = NodeBox();
253 material = MaterialProperties();
264 Quickhands for simple materials
267 void setTexture(u16 i, std::string name);
269 void setAllTextures(std::string name, u8 alpha=255)
271 for(u16 i=0; i<6; i++)
274 // Force inventory texture too
275 setInventoryTexture(name);
278 void setInventoryTexture(std::string imgname);
279 void setInventoryTextureCube(std::string top,
280 std::string left, std::string right);
285 bool isLiquid() const{
286 return (liquid_type != LIQUID_NONE);
288 bool sameLiquid(const ContentFeatures &f) const{
289 if(!isLiquid() || !f.isLiquid()) return false;
290 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
294 class INodeDefManager
298 virtual ~INodeDefManager(){}
299 // Get node definition
300 virtual const ContentFeatures& get(content_t c) const=0;
301 virtual const ContentFeatures& get(const MapNode &n) const=0;
304 class IWritableNodeDefManager : public INodeDefManager
307 IWritableNodeDefManager(){}
308 virtual ~IWritableNodeDefManager(){}
309 virtual IWritableNodeDefManager* clone()=0;
310 // Get node definition
311 virtual const ContentFeatures& get(content_t c) const=0;
312 virtual const ContentFeatures& get(const MapNode &n) const=0;
314 // Register node definition
315 virtual void set(content_t c, const ContentFeatures &def)=0;
316 virtual ContentFeatures* getModifiable(content_t c)=0;
319 Update tile textures to latest return values of TextueSource.
320 Call after updating the texture atlas of a TextureSource.
322 virtual void updateTextures(ITextureSource *tsrc)=0;
325 IWritableNodeDefManager* createNodeDefManager();