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" // DiggingProperties
34 Used for determining properties of MapNodes by content type without
35 storing such properties in the nodes itself.
39 Initialize content feature table.
41 Must be called before accessing the table.
43 void init_contentfeatures();
50 // Direction for chests and furnaces and such
63 NODEBOX_REGULAR, // Regular block; allows buildable_to
64 NODEBOX_FIXED, // Static separately defined box
65 NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
70 enum NodeBoxType type;
71 // NODEBOX_REGULAR (no parameters)
73 core::aabbox3d<f32> fixed;
74 // NODEBOX_WALLMOUNTED
75 core::aabbox3d<f32> wall_top;
76 core::aabbox3d<f32> wall_bottom;
77 core::aabbox3d<f32> wall_side; // being at the -X side
80 type(NODEBOX_REGULAR),
81 // default is rail-like
82 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
83 // default is sign/ladder-like
84 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
85 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
86 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
93 struct ContentFeatures
106 video::ITexture *inventory_texture;
108 // Used currently for flowing liquids
110 // Post effect color, drawn when the camera is inside the node.
111 video::SColor post_effect_color;
112 // Special irrlicht material, used sometimes
113 video::SMaterial *special_material;
114 video::SMaterial *special_material2;
115 AtlasPointer *special_atlas;
118 // List of all block textures that have been used (value is dummy)
119 // Used for texture atlas making.
120 // Exists on server too for cleaner code in content_mapnode.cpp.
121 core::map<std::string, bool> used_texturenames;
123 // Type of MapNode::param1
124 ContentParamType param_type;
125 // True for all ground-like things like stone and mud, false for eg. trees
126 bool is_ground_content;
127 bool light_propagates;
128 bool sunlight_propagates;
129 u8 solidness; // Used when choosing which face is drawn
130 u8 visual_solidness; // When solidness=0, this tells how it looks like
131 // This is used for collision detection.
132 // Also for general solidness queries.
134 // Player can point to these
136 // Player can dig these
138 // Player can climb these
140 // Player can build on these
142 // If true, param2 is set to direction when placed. Used for torches.
143 // NOTE: the direction format is quite inefficient and should be changed
145 // If true, node is equivalent to air. Torches are, air is. Water is not.
146 // Is used for example to check whether a mud block can have grass on.
148 // Whether this content type often contains mineral.
149 // Used for texture atlas creation.
150 // Currently only enabled for CONTENT_STONE.
151 bool often_contains_mineral;
153 // Inventory item string as which the node appears in inventory when dug.
154 // Mineral overrides this.
155 std::string dug_item;
157 // Extra dug item and its rarity
158 std::string extra_dug_item;
159 s32 extra_dug_item_rarity;
161 // Initial metadata is cloned from this
162 NodeMetadata *initial_metadata;
164 // Whether the node is non-liquid, source liquid or flowing liquid
165 enum LiquidType liquid_type;
166 // If the content is liquid, this is the flowing version of the liquid.
167 content_t liquid_alternative_flowing;
168 // If the content is liquid, this is the source version of the liquid.
169 content_t liquid_alternative_source;
170 // Viscosity for fluid flow, ranging from 1 to 7, with
171 // 1 giving almost instantaneous propagation and 7 being
172 // the slowest possible
175 // Amount of light the node emits
178 // Digging properties for different tools
179 DiggingPropertiesList digging_properties;
181 u32 damage_per_second;
183 NodeBox selection_box;
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 digging_properties.clear();
220 damage_per_second = 0;
221 selection_box = NodeBox();
232 Quickhands for simple materials
236 void setTexture(u16 i, std::string name, u8 alpha=255)
238 void setAllTextures(std::string name, u8 alpha=255)
241 void setTexture(u16 i, std::string name, u8 alpha=255);
243 void setAllTextures(std::string name, u8 alpha=255)
245 for(u16 i=0; i<6; i++)
247 setTexture(i, name, alpha);
249 // Force inventory texture too
250 setInventoryTexture(name);
255 void setTile(u16 i, const TileSpec &tile)
259 void setAllTiles(const TileSpec &tile)
261 for(u16 i=0; i<6; i++)
269 void setInventoryTexture(std::string imgname)
271 void setInventoryTextureCube(std::string top,
272 std::string left, std::string right)
275 void setInventoryTexture(std::string imgname);
277 void setInventoryTextureCube(std::string top,
278 std::string left, std::string right);
283 Call this to access the ContentFeature list
285 ContentFeatures & content_features(content_t i);
286 ContentFeatures & content_features(MapNode &n);
289 Here is a bunch of DEPRECATED functions.
293 If true, the material allows light propagation and brightness is stored
295 NOTE: Don't use, use "content_features(m).whatever" instead
297 inline bool light_propagates_content(content_t m)
299 return content_features(m).light_propagates;
302 If true, the material allows lossless sunlight propagation.
303 NOTE: It doesn't seem to go through torches regardlessly of this
304 NOTE: Don't use, use "content_features(m).whatever" instead
306 inline bool sunlight_propagates_content(content_t m)
308 return content_features(m).sunlight_propagates;
311 On a node-node surface, the material of the node with higher solidness
316 NOTE: Don't use, use "content_features(m).whatever" instead
318 inline u8 content_solidness(content_t m)
320 return content_features(m).solidness;
322 // Objects collide with walkable contents
323 // NOTE: Don't use, use "content_features(m).whatever" instead
324 inline bool content_walkable(content_t m)
326 return content_features(m).walkable;
328 // NOTE: Don't use, use "content_features(m).whatever" instead
329 inline bool content_liquid(content_t m)
331 return content_features(m).liquid_type != LIQUID_NONE;
333 // NOTE: Don't use, use "content_features(m).whatever" instead
334 inline bool content_flowing_liquid(content_t m)
336 return content_features(m).liquid_type == LIQUID_FLOWING;
338 // NOTE: Don't use, use "content_features(m).whatever" instead
339 inline bool content_liquid_source(content_t m)
341 return content_features(m).liquid_type == LIQUID_SOURCE;
343 // CONTENT_WATER || CONTENT_WATERSOURCE -> CONTENT_WATER
344 // CONTENT_LAVA || CONTENT_LAVASOURCE -> CONTENT_LAVA
345 // NOTE: Don't use, use "content_features(m).whatever" instead
346 inline content_t make_liquid_flowing(content_t m)
348 u8 c = content_features(m).liquid_alternative_flowing;
349 assert(c != CONTENT_IGNORE);
352 // Pointable contents can be pointed to in the map
353 // NOTE: Don't use, use "content_features(m).whatever" instead
354 inline bool content_pointable(content_t m)
356 return content_features(m).pointable;
358 // NOTE: Don't use, use "content_features(m).whatever" instead
359 inline bool content_diggable(content_t m)
361 return content_features(m).diggable;
363 // NOTE: Don't use, use "content_features(m).whatever" instead
364 inline bool content_buildable_to(content_t m)
366 return content_features(m).buildable_to;