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 MAPNODE_CONTENTFEATURES_HEADER
21 #define MAPNODE_CONTENTFEATURES_HEADER
23 #include "common_irrlicht.h"
29 #include "materials.h" // MaterialProperties
35 Used for determining properties of MapNodes by content type without
36 storing such properties in the nodes itself.
40 Initialize content feature table.
42 Must be called before accessing the table.
44 void init_contentfeatures(ITextureSource *tsrc);
51 // Direction for chests and furnaces and such
64 NODEBOX_REGULAR, // Regular block; allows buildable_to
65 NODEBOX_FIXED, // Static separately defined box
66 NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
71 enum NodeBoxType type;
72 // NODEBOX_REGULAR (no parameters)
74 core::aabbox3d<f32> fixed;
75 // NODEBOX_WALLMOUNTED
76 core::aabbox3d<f32> wall_top;
77 core::aabbox3d<f32> wall_bottom;
78 core::aabbox3d<f32> wall_side; // being at the -X side
81 type(NODEBOX_REGULAR),
82 // default is rail-like
83 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
84 // default is sign/ladder-like
85 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
86 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
87 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
94 struct ContentFeatures
107 video::ITexture *inventory_texture;
109 // Used currently for flowing liquids
111 // Post effect color, drawn when the camera is inside the node.
112 video::SColor post_effect_color;
113 // Special irrlicht material, used sometimes
114 video::SMaterial *special_material;
115 video::SMaterial *special_material2;
116 AtlasPointer *special_atlas;
119 // List of all block textures that have been used (value is dummy)
120 // Used for texture atlas making.
121 // Exists on server too for cleaner code in content_mapnode.cpp.
122 core::map<std::string, bool> used_texturenames;
124 // Type of MapNode::param1
125 ContentParamType param_type;
126 // True for all ground-like things like stone and mud, false for eg. trees
127 bool is_ground_content;
128 bool light_propagates;
129 bool sunlight_propagates;
130 u8 solidness; // Used when choosing which face is drawn
131 u8 visual_solidness; // When solidness=0, this tells how it looks like
132 // This is used for collision detection.
133 // Also for general solidness queries.
135 // Player can point to these
137 // Player can dig these
139 // Player can climb these
141 // Player can build on these
143 // If true, param2 is set to direction when placed. Used for torches.
144 // NOTE: the direction format is quite inefficient and should be changed
146 // If true, node is equivalent to air. Torches are, air is. Water is not.
147 // Is used for example to check whether a mud block can have grass on.
149 // Whether this content type often contains mineral.
150 // Used for texture atlas creation.
151 // Currently only enabled for CONTENT_STONE.
152 bool often_contains_mineral;
154 // Inventory item string as which the node appears in inventory when dug.
155 // Mineral overrides this.
156 std::string dug_item;
158 // Extra dug item and its rarity
159 std::string extra_dug_item;
160 s32 extra_dug_item_rarity;
162 // Initial metadata is cloned from this
163 NodeMetadata *initial_metadata;
165 // Whether the node is non-liquid, source liquid or flowing liquid
166 enum LiquidType liquid_type;
167 // If the content is liquid, this is the flowing version of the liquid.
168 content_t liquid_alternative_flowing;
169 // If the content is liquid, this is the source version of the liquid.
170 content_t liquid_alternative_source;
171 // Viscosity for fluid flow, ranging from 1 to 7, with
172 // 1 giving almost instantaneous propagation and 7 being
173 // the slowest possible
176 // Amount of light the node emits
179 u32 damage_per_second;
181 NodeBox selection_box;
183 MaterialProperties material;
185 // NOTE: Move relevant properties to here from elsewhere
190 inventory_texture = NULL;
193 post_effect_color = video::SColor(0, 0, 0, 0);
194 special_material = NULL;
195 special_material2 = NULL;
196 special_atlas = NULL;
198 param_type = CPT_NONE;
199 is_ground_content = false;
200 light_propagates = false;
201 sunlight_propagates = false;
203 visual_solidness = 0;
208 buildable_to = false;
209 wall_mounted = false;
210 air_equivalent = false;
211 often_contains_mineral = false;
213 initial_metadata = NULL;
214 liquid_type = LIQUID_NONE;
215 liquid_alternative_flowing = CONTENT_IGNORE;
216 liquid_alternative_source = CONTENT_IGNORE;
217 liquid_viscosity = 0;
219 damage_per_second = 0;
220 selection_box = NodeBox();
221 material = MaterialProperties();
232 Quickhands for simple materials
236 void setTexture(ITextureSource *tsrc, u16 i, std::string name,
239 void setAllTextures(ITextureSource *tsrc, std::string name, u8 alpha=255)
242 void setTexture(ITextureSource *tsrc,
243 u16 i, std::string name, u8 alpha=255);
245 void setAllTextures(ITextureSource *tsrc,
246 std::string name, u8 alpha=255)
248 for(u16 i=0; i<6; i++)
250 setTexture(tsrc, i, name, alpha);
252 // Force inventory texture too
253 setInventoryTexture(name, tsrc);
258 void setTile(u16 i, const TileSpec &tile)
262 void setAllTiles(const TileSpec &tile)
264 for(u16 i=0; i<6; i++)
272 void setInventoryTexture(std::string imgname,
273 ITextureSource *tsrc)
275 void setInventoryTextureCube(std::string top,
276 std::string left, std::string right, ITextureSource *tsrc)
279 void setInventoryTexture(std::string imgname, ITextureSource *tsrc);
281 void setInventoryTextureCube(std::string top,
282 std::string left, std::string right, ITextureSource *tsrc);
287 Call this to access the ContentFeature list
289 ContentFeatures & content_features(content_t i);
290 ContentFeatures & content_features(MapNode &n);
293 Here is a bunch of DEPRECATED functions.
297 If true, the material allows light propagation and brightness is stored
299 NOTE: Don't use, use "content_features(m).whatever" instead
301 inline bool light_propagates_content(content_t m)
303 return content_features(m).light_propagates;
306 If true, the material allows lossless sunlight propagation.
307 NOTE: It doesn't seem to go through torches regardlessly of this
308 NOTE: Don't use, use "content_features(m).whatever" instead
310 inline bool sunlight_propagates_content(content_t m)
312 return content_features(m).sunlight_propagates;
315 On a node-node surface, the material of the node with higher solidness
320 NOTE: Don't use, use "content_features(m).whatever" instead
322 inline u8 content_solidness(content_t m)
324 return content_features(m).solidness;
326 // Objects collide with walkable contents
327 // NOTE: Don't use, use "content_features(m).whatever" instead
328 inline bool content_walkable(content_t m)
330 return content_features(m).walkable;
332 // NOTE: Don't use, use "content_features(m).whatever" instead
333 inline bool content_liquid(content_t m)
335 return content_features(m).liquid_type != LIQUID_NONE;
337 // NOTE: Don't use, use "content_features(m).whatever" instead
338 inline bool content_flowing_liquid(content_t m)
340 return content_features(m).liquid_type == LIQUID_FLOWING;
342 // NOTE: Don't use, use "content_features(m).whatever" instead
343 inline bool content_liquid_source(content_t m)
345 return content_features(m).liquid_type == LIQUID_SOURCE;
347 // CONTENT_WATER || CONTENT_WATERSOURCE -> CONTENT_WATER
348 // CONTENT_LAVA || CONTENT_LAVASOURCE -> CONTENT_LAVA
349 // NOTE: Don't use, use "content_features(m).whatever" instead
350 inline content_t make_liquid_flowing(content_t m)
352 u8 c = content_features(m).liquid_alternative_flowing;
353 assert(c != CONTENT_IGNORE);
356 // Pointable contents can be pointed to in the map
357 // NOTE: Don't use, use "content_features(m).whatever" instead
358 inline bool content_pointable(content_t m)
360 return content_features(m).pointable;
362 // NOTE: Don't use, use "content_features(m).whatever" instead
363 inline bool content_diggable(content_t m)
365 return content_features(m).diggable;
367 // NOTE: Don't use, use "content_features(m).whatever" instead
368 inline bool content_buildable_to(content_t m)
370 return content_features(m).buildable_to;