3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes_bloated.h"
32 #include "itemgroup.h"
33 #include "sound.h" // SimpleSoundSpec
34 #include "constants.h" // BS
36 class IItemDefManager;
40 typedef std::list<std::pair<content_t, int> > GroupItems;
48 enum ContentParamType2
53 // Flowing liquid properties
55 // Direction for chests and furnaces and such
57 // Direction for signs, torches and such
70 NODEBOX_REGULAR, // Regular block; allows buildable_to
71 NODEBOX_FIXED, // Static separately defined box(es)
72 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
77 enum NodeBoxType type;
78 // NODEBOX_REGULAR (no parameters)
80 std::vector<aabb3f> fixed;
81 // NODEBOX_WALLMOUNTED
84 aabb3f wall_side; // being at the -X side
90 void serialize(std::ostream &os) const;
91 void deSerialize(std::istream &is);
98 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
100 enum TileAnimationType{
102 TAT_VERTICAL_FRAMES=1,
107 bool backface_culling; // Takes effect only in special cases
109 enum TileAnimationType type;
110 int aspect_w; // width for aspect ratio
111 int aspect_h; // height for aspect ratio
112 float length; // seconds
118 backface_culling = true;
119 animation.type = TAT_NONE;
120 animation.aspect_w = 1;
121 animation.aspect_h = 1;
122 animation.length = 1.0;
125 void serialize(std::ostream &os, u16 protocol_version) const;
126 void deSerialize(std::istream &is);
131 NDT_NORMAL, // A basic solid block
132 NDT_AIRLIKE, // Nothing is drawn
133 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
134 NDT_FLOWINGLIQUID, // A very special kind of thing
135 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
136 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all visible faces
137 // uses 2 textures, one for frames, second for faces
138 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
139 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
148 #define CF_SPECIAL_COUNT 2
150 struct ContentFeatures
157 // up down right left back front
160 // - Currently used for flowing liquids
161 TileSpec special_tiles[CF_SPECIAL_COUNT];
162 u8 solidness; // Used when choosing which face is drawn
163 u8 visual_solidness; // When solidness=0, this tells how it looks like
164 bool backface_culling;
167 // Server-side cached callback existence for fast skipping
168 bool has_on_construct;
169 bool has_on_destruct;
170 bool has_after_destruct;
176 std::string name; // "" = undefined node
177 ItemGroupList groups; // Same as in itemdef
180 enum NodeDrawType drawtype;
181 float visual_scale; // Misc. scale parameter
183 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
186 // Post effect color, drawn when the camera is inside the node.
187 video::SColor post_effect_color;
188 // Type of MapNode::param1
189 ContentParamType param_type;
190 // Type of MapNode::param2
191 ContentParamType2 param_type_2;
192 // True for all ground-like things like stone and mud, false for eg. trees
193 bool is_ground_content;
194 bool light_propagates;
195 bool sunlight_propagates;
196 // This is used for collision detection.
197 // Also for general solidness queries.
199 // Player can point to these
201 // Player can dig these
203 // Player can climb these
205 // Player can build on these
207 // Player cannot build to these (placement prediction disabled)
209 // Whether the node is non-liquid, source liquid or flowing liquid
210 enum LiquidType liquid_type;
211 // If the content is liquid, this is the flowing version of the liquid.
212 std::string liquid_alternative_flowing;
213 // If the content is liquid, this is the source version of the liquid.
214 std::string liquid_alternative_source;
215 // Viscosity for fluid flow, ranging from 1 to 7, with
216 // 1 giving almost instantaneous propagation and 7 being
217 // the slowest possible
219 // Is liquid renewable (new liquid source will be created between 2 existing)
220 bool liquid_renewable;
221 // Amount of light the node emits
223 u32 damage_per_second;
225 NodeBox selection_box;
226 // Compatibility with old maps
227 // Set to true if paramtype used to be 'facedir_simple'
228 bool legacy_facedir_simple;
229 // Set to true if wall_mounted used to be set to true
230 bool legacy_wallmounted;
233 SimpleSoundSpec sound_footstep;
234 SimpleSoundSpec sound_dig;
235 SimpleSoundSpec sound_dug;
244 void serialize(std::ostream &os, u16 protocol_version);
245 void deSerialize(std::istream &is);
246 void serializeOld(std::ostream &os, u16 protocol_version);
247 void deSerializeOld(std::istream &is, int version);
252 bool isLiquid() const{
253 return (liquid_type != LIQUID_NONE);
255 bool sameLiquid(const ContentFeatures &f) const{
256 if(!isLiquid() || !f.isLiquid()) return false;
257 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
261 class INodeDefManager
265 virtual ~INodeDefManager(){}
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 // Allows "group:name" in addition to regular node names
272 virtual void getIds(const std::string &name, std::set<content_t> &result)
274 virtual const ContentFeatures& get(const std::string &name) const=0;
276 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
279 class IWritableNodeDefManager : public INodeDefManager
282 IWritableNodeDefManager(){}
283 virtual ~IWritableNodeDefManager(){}
284 virtual IWritableNodeDefManager* clone()=0;
285 // Get node definition
286 virtual const ContentFeatures& get(content_t c) const=0;
287 virtual const ContentFeatures& get(const MapNode &n) const=0;
288 virtual bool getId(const std::string &name, content_t &result) const=0;
289 virtual content_t getId(const std::string &name) const=0;
290 // Allows "group:name" in addition to regular node names
291 virtual void getIds(const std::string &name, std::set<content_t> &result)
293 // If not found, returns the features of CONTENT_IGNORE
294 virtual const ContentFeatures& get(const std::string &name) const=0;
296 // Register node definition
297 virtual void set(content_t c, const ContentFeatures &def)=0;
298 // Register node definition by name (allocate an id)
299 // If returns CONTENT_IGNORE, could not allocate id
300 virtual content_t set(const std::string &name,
301 const ContentFeatures &def)=0;
302 // If returns CONTENT_IGNORE, could not allocate id
303 virtual content_t allocateDummy(const std::string &name)=0;
306 Update item alias mapping.
307 Call after updating item definitions.
309 virtual void updateAliases(IItemDefManager *idef)=0;
312 Update tile textures to latest return values of TextueSource.
313 Call after updating the texture atlas of a TextureSource.
315 virtual void updateTextures(ITextureSource *tsrc)=0;
317 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
318 virtual void deSerialize(std::istream &is)=0;
321 IWritableNodeDefManager* createNodeDefManager();