]> git.lizzy.rs Git - minetest.git/blob - src/scriptapi.h
Update ContentFeatures serialization format now as PROTOCOL_VERSION was changed
[minetest.git] / src / scriptapi.h
1 /*
2 Minetest-c55
3 Copyright (C) 2011 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 #ifndef SCRIPTAPI_HEADER
21 #define SCRIPTAPI_HEADER
22
23 #include "irrlichttypes_bloated.h"
24 #include <string>
25 #include "mapnode.h"
26 #include <set>
27 #include <map>
28
29 class Server;
30 class ServerEnvironment;
31 class ServerActiveObject;
32 typedef struct lua_State lua_State;
33 struct ObjectProperties;
34 struct ItemStack;
35 struct PointedThing;
36 //class IGameDef;
37 struct ToolCapabilities;
38
39 void scriptapi_export(lua_State *L, Server *server);
40 bool scriptapi_loadmod(lua_State *L, const std::string &scriptpath,
41                 const std::string &modname);
42 void scriptapi_add_environment(lua_State *L, ServerEnvironment *env);
43
44 void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj);
45 void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
46
47 // Returns true if script handled message
48 bool scriptapi_on_chat_message(lua_State *L, const std::string &name,
49                 const std::string &message);
50
51 /* environment */
52 // On environment step
53 void scriptapi_environment_step(lua_State *L, float dtime);
54 // After generating a piece of map
55 void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp,
56                 u32 blockseed);
57
58 /* misc */
59 void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);
60 void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player);
61 bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player);
62 void scriptapi_on_joinplayer(lua_State *L, ServerActiveObject *player);
63 void scriptapi_on_leaveplayer(lua_State *L, ServerActiveObject *player);
64 bool scriptapi_get_auth(lua_State *L, const std::string &playername,
65                 std::string *dst_password, std::set<std::string> *dst_privs);
66 void scriptapi_create_auth(lua_State *L, const std::string &playername,
67                 const std::string &password);
68 bool scriptapi_set_password(lua_State *L, const std::string &playername,
69                 const std::string &password);
70
71 /* player */
72 void scriptapi_on_player_receive_fields(lua_State *L, 
73                 ServerActiveObject *player,
74                 const std::string &formname,
75                 const std::map<std::string, std::string> &fields);
76
77 /* item callbacks */
78 bool scriptapi_item_on_drop(lua_State *L, ItemStack &item,
79                 ServerActiveObject *dropper, v3f pos);
80 bool scriptapi_item_on_place(lua_State *L, ItemStack &item,
81                 ServerActiveObject *placer, const PointedThing &pointed);
82 bool scriptapi_item_on_use(lua_State *L, ItemStack &item,
83                 ServerActiveObject *user, const PointedThing &pointed);
84
85 /* node callbacks */
86 bool scriptapi_node_on_punch(lua_State *L, v3s16 p, MapNode node,
87                 ServerActiveObject *puncher);
88 bool scriptapi_node_on_dig(lua_State *L, v3s16 p, MapNode node,
89                 ServerActiveObject *digger);
90 // Node constructor
91 void scriptapi_node_on_construct(lua_State *L, v3s16 p, MapNode node);
92 // Node destructor
93 void scriptapi_node_on_destruct(lua_State *L, v3s16 p, MapNode node);
94 // Node post-destructor
95 void scriptapi_node_after_destruct(lua_State *L, v3s16 p, MapNode node);
96 // Node Timer event
97 bool scriptapi_node_on_timer(lua_State *L, v3s16 p, MapNode node, f32 dtime);
98 // Called when a metadata form returns values
99 void scriptapi_node_on_receive_fields(lua_State *L, v3s16 p,
100                 const std::string &formname,
101                 const std::map<std::string, std::string> &fields,
102                 ServerActiveObject *sender);
103
104 /* Node metadata inventory callbacks */
105 // Return number of accepted items to be moved
106 int scriptapi_nodemeta_inventory_allow_move(lua_State *L, v3s16 p,
107                 const std::string &from_list, int from_index,
108                 const std::string &to_list, int to_index,
109                 int count, ServerActiveObject *player);
110 // Return number of accepted items to be put
111 int scriptapi_nodemeta_inventory_allow_put(lua_State *L, v3s16 p,
112                 const std::string &listname, int index, ItemStack &stack,
113                 ServerActiveObject *player);
114 // Return number of accepted items to be taken
115 int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
116                 const std::string &listname, int index, ItemStack &stack,
117                 ServerActiveObject *player);
118 // Report moved items
119 void scriptapi_nodemeta_inventory_on_move(lua_State *L, v3s16 p,
120                 const std::string &from_list, int from_index,
121                 const std::string &to_list, int to_index,
122                 int count, ServerActiveObject *player);
123 // Report put items
124 void scriptapi_nodemeta_inventory_on_put(lua_State *L, v3s16 p,
125                 const std::string &listname, int index, ItemStack &stack,
126                 ServerActiveObject *player);
127 // Report taken items
128 void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
129                 const std::string &listname, int index, ItemStack &stack,
130                 ServerActiveObject *player);
131
132 /* Detached inventory callbacks */
133 // Return number of accepted items to be moved
134 int scriptapi_detached_inventory_allow_move(lua_State *L,
135                 const std::string &name,
136                 const std::string &from_list, int from_index,
137                 const std::string &to_list, int to_index,
138                 int count, ServerActiveObject *player);
139 // Return number of accepted items to be put
140 int scriptapi_detached_inventory_allow_put(lua_State *L,
141                 const std::string &name,
142                 const std::string &listname, int index, ItemStack &stack,
143                 ServerActiveObject *player);
144 // Return number of accepted items to be taken
145 int scriptapi_detached_inventory_allow_take(lua_State *L,
146                 const std::string &name,
147                 const std::string &listname, int index, ItemStack &stack,
148                 ServerActiveObject *player);
149 // Report moved items
150 void scriptapi_detached_inventory_on_move(lua_State *L,
151                 const std::string &name,
152                 const std::string &from_list, int from_index,
153                 const std::string &to_list, int to_index,
154                 int count, ServerActiveObject *player);
155 // Report put items
156 void scriptapi_detached_inventory_on_put(lua_State *L,
157                 const std::string &name,
158                 const std::string &listname, int index, ItemStack &stack,
159                 ServerActiveObject *player);
160 // Report taken items
161 void scriptapi_detached_inventory_on_take(lua_State *L,
162                 const std::string &name,
163                 const std::string &listname, int index, ItemStack &stack,
164                 ServerActiveObject *player);
165
166 /* luaentity */
167 // Returns true if succesfully added into Lua; false otherwise.
168 bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name);
169 void scriptapi_luaentity_activate(lua_State *L, u16 id,
170                 const std::string &staticdata, u32 dtime_s);
171 void scriptapi_luaentity_rm(lua_State *L, u16 id);
172 std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id);
173 void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
174                 ObjectProperties *prop);
175 void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
176 void scriptapi_luaentity_punch(lua_State *L, u16 id,
177                 ServerActiveObject *puncher, float time_from_last_punch,
178                 const ToolCapabilities *toolcap, v3f dir);
179 void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
180                 ServerActiveObject *clicker);
181
182 #endif
183