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
32 class IItemDefManager;
41 // Direction for chests and furnaces and such
54 NODEBOX_REGULAR, // Regular block; allows buildable_to
55 NODEBOX_FIXED, // Static separately defined box
56 NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
61 enum NodeBoxType type;
62 // NODEBOX_REGULAR (no parameters)
64 core::aabbox3d<f32> fixed;
65 // NODEBOX_WALLMOUNTED
66 core::aabbox3d<f32> wall_top;
67 core::aabbox3d<f32> wall_bottom;
68 core::aabbox3d<f32> wall_side; // being at the -X side
71 type(NODEBOX_REGULAR),
72 // default is rail-like
73 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
74 // default is sign/ladder-like
75 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
76 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
77 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
80 void serialize(std::ostream &os) const;
81 void deSerialize(std::istream &is);
90 bool backface_culling;
92 MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
94 backface_culling(backface_culling_)
97 void serialize(std::ostream &os) const;
98 void deSerialize(std::istream &is);
103 NDT_NORMAL, // A basic solid block
104 NDT_AIRLIKE, // Nothing is drawn
105 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
106 NDT_FLOWINGLIQUID, // A very special kind of thing
107 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
108 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
109 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
117 #define CF_SPECIAL_COUNT 2
119 struct ContentFeatures
126 // up down right left back front
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;
141 std::string name; // "" = undefined node
144 enum NodeDrawType drawtype;
145 float visual_scale; // Misc. scale parameter
146 std::string tname_tiles[6];
147 MaterialSpec mspec_special[CF_SPECIAL_COUNT]; // Use setter methods
150 // Post effect color, drawn when the camera is inside the node.
151 video::SColor post_effect_color;
152 // Type of MapNode::param1
153 ContentParamType param_type;
154 // True for all ground-like things like stone and mud, false for eg. trees
155 bool is_ground_content;
156 bool light_propagates;
157 bool sunlight_propagates;
158 // This is used for collision detection.
159 // Also for general solidness queries.
161 // Player can point to these
163 // Player can dig these
165 // Player can climb these
167 // Player can build on these
169 // If true, param2 is set to direction when placed. Used for torches.
170 // NOTE: the direction format is quite inefficient and should be changed
172 // Inventory item string as which the node appears in inventory when dug.
173 // Mineral overrides this.
174 std::string dug_item;
175 // Extra dug item and its rarity
176 std::string extra_dug_item;
177 // Usual get interval for extra dug item
178 s32 extra_dug_item_rarity;
179 // Metadata name of node (eg. "furnace")
180 std::string metadata_name;
181 // Whether the node is non-liquid, source liquid or flowing liquid
182 enum LiquidType liquid_type;
183 // If the content is liquid, this is the flowing version of the liquid.
184 std::string liquid_alternative_flowing;
185 // If the content is liquid, this is the source version of the liquid.
186 std::string liquid_alternative_source;
187 // Viscosity for fluid flow, ranging from 1 to 7, with
188 // 1 giving almost instantaneous propagation and 7 being
189 // the slowest possible
191 // Amount of light the node emits
193 u32 damage_per_second;
194 NodeBox selection_box;
195 MaterialProperties material;
204 void serialize(std::ostream &os);
205 void deSerialize(std::istream &is);
210 bool isLiquid() const{
211 return (liquid_type != LIQUID_NONE);
213 bool sameLiquid(const ContentFeatures &f) const{
214 if(!isLiquid() || !f.isLiquid()) return false;
215 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
219 class INodeDefManager
223 virtual ~INodeDefManager(){}
224 // Get node definition
225 virtual const ContentFeatures& get(content_t c) const=0;
226 virtual const ContentFeatures& get(const MapNode &n) const=0;
227 virtual bool getId(const std::string &name, content_t &result) const=0;
228 virtual content_t getId(const std::string &name) const=0;
229 virtual const ContentFeatures& get(const std::string &name) const=0;
231 virtual void serialize(std::ostream &os)=0;
234 class IWritableNodeDefManager : public INodeDefManager
237 IWritableNodeDefManager(){}
238 virtual ~IWritableNodeDefManager(){}
239 virtual IWritableNodeDefManager* clone()=0;
240 // Get node definition
241 virtual const ContentFeatures& get(content_t c) const=0;
242 virtual const ContentFeatures& get(const MapNode &n) const=0;
243 virtual bool getId(const std::string &name, content_t &result) const=0;
244 virtual content_t getId(const std::string &name) const=0;
245 // If not found, returns the features of CONTENT_IGNORE
246 virtual const ContentFeatures& get(const std::string &name) const=0;
248 // Register node definition
249 virtual void set(content_t c, const ContentFeatures &def)=0;
250 // Register node definition by name (allocate an id)
251 // If returns CONTENT_IGNORE, could not allocate id
252 virtual content_t set(const std::string &name,
253 const ContentFeatures &def)=0;
254 // If returns CONTENT_IGNORE, could not allocate id
255 virtual content_t allocateDummy(const std::string &name)=0;
258 Update item alias mapping.
259 Call after updating item definitions.
261 virtual void updateAliases(IItemDefManager *idef)=0;
264 Update tile textures to latest return values of TextueSource.
265 Call after updating the texture atlas of a TextureSource.
267 virtual void updateTextures(ITextureSource *tsrc)=0;
269 virtual void serialize(std::ostream &os)=0;
270 virtual void deSerialize(std::istream &is)=0;
273 IWritableNodeDefManager* createNodeDefManager();