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"
31 #include "materials.h" // MaterialProperties
40 // Direction for chests and furnaces and such
53 NODEBOX_REGULAR, // Regular block; allows buildable_to
54 NODEBOX_FIXED, // Static separately defined box
55 NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
60 enum NodeBoxType type;
61 // NODEBOX_REGULAR (no parameters)
63 core::aabbox3d<f32> fixed;
64 // NODEBOX_WALLMOUNTED
65 core::aabbox3d<f32> wall_top;
66 core::aabbox3d<f32> wall_bottom;
67 core::aabbox3d<f32> wall_side; // being at the -X side
70 type(NODEBOX_REGULAR),
71 // default is rail-like
72 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
73 // default is sign/ladder-like
74 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
75 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
76 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
79 void serialize(std::ostream &os) const;
80 void deSerialize(std::istream &is);
89 bool backface_culling;
91 MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
93 backface_culling(backface_culling_)
96 void serialize(std::ostream &os) const;
97 void deSerialize(std::istream &is);
102 NDT_NORMAL, // A basic solid block
103 NDT_AIRLIKE, // Nothing is drawn
104 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
105 NDT_FLOWINGLIQUID, // A very special kind of thing
106 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
107 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
108 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
116 #define CF_SPECIAL_COUNT 2
118 struct ContentFeatures
125 // up down right left back front
127 video::ITexture *inventory_texture;
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];
132 u8 solidness; // Used when choosing which face is drawn
133 u8 visual_solidness; // When solidness=0, this tells how it looks like
134 bool backface_culling;
137 // List of textures that are used and are wanted to be included in
139 std::set<std::string> used_texturenames;
145 std::string name; // "" = undefined node
148 enum NodeDrawType drawtype;
149 float visual_scale; // Misc. scale parameter
150 std::string tname_tiles[6];
151 std::string tname_inventory;
152 MaterialSpec mspec_special[CF_SPECIAL_COUNT]; // Use setter methods
155 // Post effect color, drawn when the camera is inside the node.
156 video::SColor post_effect_color;
157 // Type of MapNode::param1
158 ContentParamType param_type;
159 // True for all ground-like things like stone and mud, false for eg. trees
160 bool is_ground_content;
161 bool light_propagates;
162 bool sunlight_propagates;
163 // This is used for collision detection.
164 // Also for general solidness queries.
166 // Player can point to these
168 // Player can dig these
170 // Player can climb these
172 // Player can build on these
174 // If true, param2 is set to direction when placed. Used for torches.
175 // NOTE: the direction format is quite inefficient and should be changed
177 // Whether this content type often contains mineral.
178 // Used for texture atlas creation.
179 // Currently only enabled for CONTENT_STONE.
180 bool often_contains_mineral;
181 // Inventory item string as which the node appears in inventory when dug.
182 // Mineral overrides this.
183 std::string dug_item;
184 // Extra dug item and its rarity
185 std::string extra_dug_item;
186 // Usual get interval for extra dug item
187 s32 extra_dug_item_rarity;
188 // Metadata name of node (eg. "furnace")
189 std::string metadata_name;
190 // Whether the node is non-liquid, source liquid or flowing liquid
191 enum LiquidType liquid_type;
192 // If the content is liquid, this is the flowing version of the liquid.
193 std::string liquid_alternative_flowing;
194 // If the content is liquid, this is the source version of the liquid.
195 std::string liquid_alternative_source;
196 // Viscosity for fluid flow, ranging from 1 to 7, with
197 // 1 giving almost instantaneous propagation and 7 being
198 // the slowest possible
200 // Amount of light the node emits
202 u32 damage_per_second;
203 NodeBox selection_box;
204 MaterialProperties material;
205 std::string cookresult_item;
206 float furnace_cooktime;
207 float furnace_burntime;
216 void serialize(std::ostream &os);
217 void deSerialize(std::istream &is, IGameDef *gamedef);
224 // Texture setters. They also add stuff to used_texturenames.
225 void setTexture(u16 i, std::string name);
226 void setAllTextures(std::string name);
227 void setSpecialMaterial(u16 i, const MaterialSpec &mspec);
229 void setInventoryTexture(std::string imgname);
230 void setInventoryTextureCube(std::string top,
231 std::string left, std::string right);
236 bool isLiquid() const{
237 return (liquid_type != LIQUID_NONE);
239 bool sameLiquid(const ContentFeatures &f) const{
240 if(!isLiquid() || !f.isLiquid()) return false;
241 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
245 class INodeDefManager
249 virtual ~INodeDefManager(){}
250 // Get node definition
251 virtual const ContentFeatures& get(content_t c) const=0;
252 virtual const ContentFeatures& get(const MapNode &n) const=0;
253 virtual bool getId(const std::string &name, content_t &result) const=0;
254 virtual content_t getId(const std::string &name) const=0;
255 virtual const ContentFeatures& get(const std::string &name) const=0;
257 virtual void serialize(std::ostream &os)=0;
260 class IWritableNodeDefManager : public INodeDefManager
263 IWritableNodeDefManager(){}
264 virtual ~IWritableNodeDefManager(){}
265 virtual IWritableNodeDefManager* clone()=0;
266 // Get node definition
267 virtual const ContentFeatures& get(content_t c) const=0;
268 virtual const ContentFeatures& get(const MapNode &n) const=0;
269 virtual bool getId(const std::string &name, content_t &result) const=0;
270 virtual content_t getId(const std::string &name) const=0;
271 // If not found, returns the features of CONTENT_IGNORE
272 virtual const ContentFeatures& get(const std::string &name) const=0;
274 // Register node definition
275 virtual void set(content_t c, const ContentFeatures &def)=0;
276 // Register node definition by name (allocate an id)
277 // If returns CONTENT_IGNORE, could not allocate id
278 virtual content_t set(const std::string &name,
279 const ContentFeatures &def)=0;
280 // If returns CONTENT_IGNORE, could not allocate id
281 virtual content_t allocateDummy(const std::string &name)=0;
284 Update tile textures to latest return values of TextueSource.
285 Call after updating the texture atlas of a TextureSource.
287 virtual void updateTextures(ITextureSource *tsrc)=0;
289 virtual void serialize(std::ostream &os)=0;
290 virtual void deSerialize(std::istream &is, IGameDef *gamedef)=0;
293 IWritableNodeDefManager* createNodeDefManager();