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"
33 #include "itemgroup.h"
34 #include "sound.h" // SimpleSoundSpec
35 #include "constants.h" // BS
37 class IItemDefManager;
42 typedef std::list<std::pair<content_t, int> > GroupItems;
50 enum ContentParamType2
55 // Flowing liquid properties
57 // Direction for chests and furnaces and such
59 // Direction for signs, torches and such
61 // Block level like FLOWINGLIQUID
74 NODEBOX_REGULAR, // Regular block; allows buildable_to
75 NODEBOX_FIXED, // Static separately defined box(es)
76 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
77 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
82 enum NodeBoxType type;
83 // NODEBOX_REGULAR (no parameters)
85 std::vector<aabb3f> fixed;
86 // NODEBOX_WALLMOUNTED
89 aabb3f wall_side; // being at the -X side
95 void serialize(std::ostream &os, u16 protocol_version) const;
96 void deSerialize(std::istream &is);
103 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
105 enum TileAnimationType{
107 TAT_VERTICAL_FRAMES=1,
112 bool backface_culling; // Takes effect only in special cases
114 enum TileAnimationType type;
115 int aspect_w; // width for aspect ratio
116 int aspect_h; // height for aspect ratio
117 float length; // seconds
123 backface_culling = true;
124 animation.type = TAT_NONE;
125 animation.aspect_w = 1;
126 animation.aspect_h = 1;
127 animation.length = 1.0;
130 void serialize(std::ostream &os, u16 protocol_version) const;
131 void deSerialize(std::istream &is);
136 NDT_NORMAL, // A basic solid block
137 NDT_AIRLIKE, // Nothing is drawn
138 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
139 NDT_FLOWINGLIQUID, // A very special kind of thing
140 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
141 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
142 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
149 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
151 // uses 2 textures, one for frames, second for faces
154 #define CF_SPECIAL_COUNT 2
156 struct ContentFeatures
163 // up down right left back front
166 // - Currently used for flowing liquids
167 TileSpec special_tiles[CF_SPECIAL_COUNT];
168 u8 solidness; // Used when choosing which face is drawn
169 u8 visual_solidness; // When solidness=0, this tells how it looks like
170 bool backface_culling;
173 // Server-side cached callback existence for fast skipping
174 bool has_on_construct;
175 bool has_on_destruct;
176 bool has_after_destruct;
182 std::string name; // "" = undefined node
183 ItemGroupList groups; // Same as in itemdef
186 enum NodeDrawType drawtype;
187 float visual_scale; // Misc. scale parameter
189 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
192 // Post effect color, drawn when the camera is inside the node.
193 video::SColor post_effect_color;
194 // Type of MapNode::param1
195 ContentParamType param_type;
196 // Type of MapNode::param2
197 ContentParamType2 param_type_2;
198 // True for all ground-like things like stone and mud, false for eg. trees
199 bool is_ground_content;
200 bool light_propagates;
201 bool sunlight_propagates;
202 // This is used for collision detection.
203 // Also for general solidness queries.
205 // Player can point to these
207 // Player can dig these
209 // Player can climb these
211 // Player can build on these
213 // Player cannot build to these (placement prediction disabled)
215 // Flowing liquid or snow, value = default level
217 // Whether the node is non-liquid, source liquid or flowing liquid
218 enum LiquidType liquid_type;
219 // If the content is liquid, this is the flowing version of the liquid.
220 std::string liquid_alternative_flowing;
221 // If the content is liquid, this is the source version of the liquid.
222 std::string liquid_alternative_source;
223 // Viscosity for fluid flow, ranging from 1 to 7, with
224 // 1 giving almost instantaneous propagation and 7 being
225 // the slowest possible
227 // Is liquid renewable (new liquid source will be created between 2 existing)
228 bool liquid_renewable;
229 // Ice for water, water for ice
230 std::string freezemelt;
231 // Number of flowing liquids surrounding source
234 // Amount of light the node emits
236 u32 damage_per_second;
238 NodeBox selection_box;
239 // Used for waving leaves/plants
241 // Compatibility with old maps
242 // Set to true if paramtype used to be 'facedir_simple'
243 bool legacy_facedir_simple;
244 // Set to true if wall_mounted used to be set to true
245 bool legacy_wallmounted;
248 SimpleSoundSpec sound_footstep;
249 SimpleSoundSpec sound_dig;
250 SimpleSoundSpec sound_dug;
259 void serialize(std::ostream &os, u16 protocol_version);
260 void deSerialize(std::istream &is);
261 void serializeOld(std::ostream &os, u16 protocol_version);
262 void deSerializeOld(std::istream &is, int version);
267 bool isLiquid() const{
268 return (liquid_type != LIQUID_NONE);
270 bool sameLiquid(const ContentFeatures &f) const{
271 if(!isLiquid() || !f.isLiquid()) return false;
272 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
276 class INodeDefManager
280 virtual ~INodeDefManager(){}
281 // Get node definition
282 virtual const ContentFeatures& get(content_t c) const=0;
283 virtual const ContentFeatures& get(const MapNode &n) const=0;
284 virtual bool getId(const std::string &name, content_t &result) const=0;
285 virtual content_t getId(const std::string &name) const=0;
286 // Allows "group:name" in addition to regular node names
287 virtual void getIds(const std::string &name, std::set<content_t> &result)
289 virtual const ContentFeatures& get(const std::string &name) const=0;
291 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
294 class IWritableNodeDefManager : public INodeDefManager
297 IWritableNodeDefManager(){}
298 virtual ~IWritableNodeDefManager(){}
299 virtual IWritableNodeDefManager* clone()=0;
300 // Get node definition
301 virtual const ContentFeatures& get(content_t c) const=0;
302 virtual const ContentFeatures& get(const MapNode &n) const=0;
303 virtual bool getId(const std::string &name, content_t &result) const=0;
304 // If not found, returns CONTENT_IGNORE
305 virtual content_t getId(const std::string &name) const=0;
306 // Allows "group:name" in addition to regular node names
307 virtual void getIds(const std::string &name, std::set<content_t> &result)
309 // If not found, returns the features of CONTENT_UNKNOWN
310 virtual const ContentFeatures& get(const std::string &name) const=0;
312 // Register node definition by name (allocate an id)
313 // If returns CONTENT_IGNORE, could not allocate id
314 virtual content_t set(const std::string &name,
315 const ContentFeatures &def)=0;
316 // If returns CONTENT_IGNORE, could not allocate id
317 virtual content_t allocateDummy(const std::string &name)=0;
320 Update item alias mapping.
321 Call after updating item definitions.
323 virtual void updateAliases(IItemDefManager *idef)=0;
326 Update tile textures to latest return values of TextueSource.
328 virtual void updateTextures(ITextureSource *tsrc,
329 IShaderSource *shdsrc)=0;
331 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
332 virtual void deSerialize(std::istream &is)=0;
335 IWritableNodeDefManager* createNodeDefManager();