]> git.lizzy.rs Git - minetest.git/blob - src/script/common/c_content.h
aa8746eff62a349bde34cc425001b5df7a12fff9
[minetest.git] / src / script / common / c_content.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20
21 /******************************************************************************/
22 /******************************************************************************/
23 /* WARNING!!!! do NOT add this header in any include file or any code file    */
24 /*             not being a script/modapi file!!!!!!!!                         */
25 /******************************************************************************/
26 /******************************************************************************/
27
28 #pragma once
29
30 extern "C" {
31 #include <lua.h>
32 }
33
34 #include <iostream>
35 #include <vector>
36
37 #include "irrlichttypes_bloated.h"
38 #include "util/string.h"
39 #include "itemgroup.h"
40 #include "itemdef.h"
41 #include "c_types.h"
42 // We do an explicit path include because by default c_content.h include src/client/hud.h
43 // prior to the src/hud.h, which is not good on server only build
44 #include "../../hud.h"
45 #include "content/mods.h"
46
47 namespace Json { class Value; }
48
49 struct MapNode;
50 class NodeDefManager;
51 struct PointedThing;
52 struct ItemStack;
53 struct ItemDefinition;
54 struct ToolCapabilities;
55 struct ObjectProperties;
56 struct SimpleSoundSpec;
57 struct ServerPlayingSound;
58 class Inventory;
59 class InventoryList;
60 struct NodeBox;
61 struct ContentFeatures;
62 struct TileDef;
63 class IGameDef;
64 struct DigParams;
65 struct HitParams;
66 struct EnumString;
67 struct NoiseParams;
68 class Schematic;
69 class ServerActiveObject;
70 struct collisionMoveResult;
71
72 extern struct EnumString es_TileAnimationType[];
73
74 void               read_content_features     (lua_State *L, ContentFeatures &f,
75                                               int index);
76 void               push_content_features     (lua_State *L,
77                                               const ContentFeatures &c);
78
79 void               push_nodebox              (lua_State *L,
80                                               const NodeBox &box);
81 void               push_box                  (lua_State *L,
82                                               const std::vector<aabb3f> &box);
83
84 void               push_palette              (lua_State *L,
85                                               const std::vector<video::SColor> *palette);
86
87 TileDef            read_tiledef              (lua_State *L, int index,
88                                               u8 drawtype);
89
90 void               read_soundspec            (lua_State *L, int index,
91                                               SimpleSoundSpec &spec);
92 NodeBox            read_nodebox              (lua_State *L, int index);
93
94 void               read_server_sound_params  (lua_State *L, int index,
95                                               ServerPlayingSound &params);
96
97 void               push_dig_params           (lua_State *L,
98                                               const DigParams &params);
99 void               push_hit_params           (lua_State *L,
100                                               const HitParams &params);
101
102 ItemStack          read_item                 (lua_State *L, int index, IItemDefManager *idef);
103
104 struct TileAnimationParams read_animation_definition(lua_State *L, int index);
105
106 ToolCapabilities   read_tool_capabilities    (lua_State *L, int table);
107 void               push_tool_capabilities    (lua_State *L,
108                                               const ToolCapabilities &prop);
109
110 void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def,
111                 ItemDefinition &def);
112 void               push_item_definition      (lua_State *L,
113                                               const ItemDefinition &i);
114 void               push_item_definition_full (lua_State *L,
115                                               const ItemDefinition &i);
116
117 void               read_object_properties    (lua_State *L, int index,
118                                               ServerActiveObject *sao,
119                                               ObjectProperties *prop,
120                                               IItemDefManager *idef);
121 void               push_object_properties    (lua_State *L,
122                                               ObjectProperties *prop);
123
124 void               push_inventory_list       (lua_State *L,
125                                               const InventoryList &invlist);
126 void               push_inventory_lists      (lua_State *L,
127                                               const Inventory &inv);
128 void               read_inventory_list       (lua_State *L, int tableindex,
129                                               Inventory *inv, const char *name,
130                                               IGameDef *gdef, int forcesize=-1);
131
132 MapNode            readnode                  (lua_State *L, int index);
133 void               pushnode                  (lua_State *L, const MapNode &n);
134
135
136 void               read_groups               (lua_State *L, int index,
137                                               ItemGroupList &result);
138
139 void               push_groups               (lua_State *L,
140                                               const ItemGroupList &groups);
141
142 //TODO rename to "read_enum_field"
143 int                getenumfield              (lua_State *L, int table,
144                                               const char *fieldname,
145                                               const EnumString *spec,
146                                               int default_);
147
148 bool               getflagsfield             (lua_State *L, int table,
149                                               const char *fieldname,
150                                               FlagDesc *flagdesc,
151                                               u32 *flags, u32 *flagmask);
152
153 bool               read_flags                (lua_State *L, int index,
154                                               FlagDesc *flagdesc,
155                                               u32 *flags, u32 *flagmask);
156
157 void               push_flags_string         (lua_State *L, FlagDesc *flagdesc,
158                                               u32 flags, u32 flagmask);
159
160 u32                read_flags_table          (lua_State *L, int table,
161                                               FlagDesc *flagdesc, u32 *flagmask);
162
163 void               push_items                (lua_State *L,
164                                               const std::vector<ItemStack> &items);
165
166 std::vector<ItemStack> read_items            (lua_State *L,
167                                               int index,
168                                               IGameDef* gdef);
169
170 void               push_soundspec            (lua_State *L,
171                                               const SimpleSoundSpec &spec);
172
173 bool               string_to_enum            (const EnumString *spec,
174                                               int &result,
175                                               const std::string &str);
176
177 bool               read_noiseparams          (lua_State *L, int index,
178                                               NoiseParams *np);
179 void               push_noiseparams          (lua_State *L, NoiseParams *np);
180
181 void               luaentity_get             (lua_State *L,u16 id);
182
183 bool               push_json_value           (lua_State *L,
184                                               const Json::Value &value,
185                                               int nullindex);
186 void               read_json_value           (lua_State *L, Json::Value &root,
187                                               int index, u8 recursion = 0);
188
189 /*!
190  * Pushes a Lua `pointed_thing` to the given Lua stack.
191  * \param csm If true, a client side pointed thing is pushed
192  * \param hitpoint If true, the exact pointing location is also pushed
193  */
194 void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm =
195         false, bool hitpoint = false);
196
197 void push_objectRef            (lua_State *L, const u16 id);
198
199 void read_hud_element          (lua_State *L, HudElement *elem);
200
201 void push_hud_element          (lua_State *L, HudElement *elem);
202
203 bool read_hud_change           (lua_State *L, HudElementStat &stat, HudElement *elem, void **value);
204
205 void push_collision_move_result(lua_State *L, const collisionMoveResult &res);
206
207 void push_mod_spec(lua_State *L, const ModSpec &spec, bool include_unsatisfied);