]> git.lizzy.rs Git - dragonfireclient.git/blob - src/scriptapi.h
Workaround failing Travis clang build.
[dragonfireclient.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 /* server */
59 void scriptapi_on_shutdown(lua_State *L);
60
61 /* misc */
62 void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);
63 void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player);
64 bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player);
65 void scriptapi_on_joinplayer(lua_State *L, ServerActiveObject *player);
66 void scriptapi_on_leaveplayer(lua_State *L, ServerActiveObject *player);
67 bool scriptapi_get_auth(lua_State *L, const std::string &playername,
68                 std::string *dst_password, std::set<std::string> *dst_privs);
69 void scriptapi_create_auth(lua_State *L, const std::string &playername,
70                 const std::string &password);
71 bool scriptapi_set_password(lua_State *L, const std::string &playername,
72                 const std::string &password);
73
74 /* player */
75 void scriptapi_on_player_receive_fields(lua_State *L, 
76                 ServerActiveObject *player,
77                 const std::string &formname,
78                 const std::map<std::string, std::string> &fields);
79
80 /* item callbacks */
81 bool scriptapi_item_on_drop(lua_State *L, ItemStack &item,
82                 ServerActiveObject *dropper, v3f pos);
83 bool scriptapi_item_on_place(lua_State *L, ItemStack &item,
84                 ServerActiveObject *placer, const PointedThing &pointed);
85 bool scriptapi_item_on_use(lua_State *L, ItemStack &item,
86                 ServerActiveObject *user, const PointedThing &pointed);
87
88 /* node callbacks */
89 bool scriptapi_node_on_punch(lua_State *L, v3s16 p, MapNode node,
90                 ServerActiveObject *puncher);
91 bool scriptapi_node_on_dig(lua_State *L, v3s16 p, MapNode node,
92                 ServerActiveObject *digger);
93 // Node constructor
94 void scriptapi_node_on_construct(lua_State *L, v3s16 p, MapNode node);
95 // Node destructor
96 void scriptapi_node_on_destruct(lua_State *L, v3s16 p, MapNode node);
97 // Node post-destructor
98 void scriptapi_node_after_destruct(lua_State *L, v3s16 p, MapNode node);
99 // Node Timer event
100 bool scriptapi_node_on_timer(lua_State *L, v3s16 p, MapNode node, f32 dtime);
101 // Called when a metadata form returns values
102 void scriptapi_node_on_receive_fields(lua_State *L, v3s16 p,
103                 const std::string &formname,
104                 const std::map<std::string, std::string> &fields,
105                 ServerActiveObject *sender);
106
107 /* Node metadata inventory callbacks */
108 // Return number of accepted items to be moved
109 int scriptapi_nodemeta_inventory_allow_move(lua_State *L, v3s16 p,
110                 const std::string &from_list, int from_index,
111                 const std::string &to_list, int to_index,
112                 int count, ServerActiveObject *player);
113 // Return number of accepted items to be put
114 int scriptapi_nodemeta_inventory_allow_put(lua_State *L, v3s16 p,
115                 const std::string &listname, int index, ItemStack &stack,
116                 ServerActiveObject *player);
117 // Return number of accepted items to be taken
118 int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
119                 const std::string &listname, int index, ItemStack &stack,
120                 ServerActiveObject *player);
121 // Report moved items
122 void scriptapi_nodemeta_inventory_on_move(lua_State *L, v3s16 p,
123                 const std::string &from_list, int from_index,
124                 const std::string &to_list, int to_index,
125                 int count, ServerActiveObject *player);
126 // Report put items
127 void scriptapi_nodemeta_inventory_on_put(lua_State *L, v3s16 p,
128                 const std::string &listname, int index, ItemStack &stack,
129                 ServerActiveObject *player);
130 // Report taken items
131 void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
132                 const std::string &listname, int index, ItemStack &stack,
133                 ServerActiveObject *player);
134
135 /* Detached inventory callbacks */
136 // Return number of accepted items to be moved
137 int scriptapi_detached_inventory_allow_move(lua_State *L,
138                 const std::string &name,
139                 const std::string &from_list, int from_index,
140                 const std::string &to_list, int to_index,
141                 int count, ServerActiveObject *player);
142 // Return number of accepted items to be put
143 int scriptapi_detached_inventory_allow_put(lua_State *L,
144                 const std::string &name,
145                 const std::string &listname, int index, ItemStack &stack,
146                 ServerActiveObject *player);
147 // Return number of accepted items to be taken
148 int scriptapi_detached_inventory_allow_take(lua_State *L,
149                 const std::string &name,
150                 const std::string &listname, int index, ItemStack &stack,
151                 ServerActiveObject *player);
152 // Report moved items
153 void scriptapi_detached_inventory_on_move(lua_State *L,
154                 const std::string &name,
155                 const std::string &from_list, int from_index,
156                 const std::string &to_list, int to_index,
157                 int count, ServerActiveObject *player);
158 // Report put items
159 void scriptapi_detached_inventory_on_put(lua_State *L,
160                 const std::string &name,
161                 const std::string &listname, int index, ItemStack &stack,
162                 ServerActiveObject *player);
163 // Report taken items
164 void scriptapi_detached_inventory_on_take(lua_State *L,
165                 const std::string &name,
166                 const std::string &listname, int index, ItemStack &stack,
167                 ServerActiveObject *player);
168
169 /* luaentity */
170 // Returns true if succesfully added into Lua; false otherwise.
171 bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name);
172 void scriptapi_luaentity_activate(lua_State *L, u16 id,
173                 const std::string &staticdata, u32 dtime_s);
174 void scriptapi_luaentity_rm(lua_State *L, u16 id);
175 std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id);
176 void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
177                 ObjectProperties *prop);
178 void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
179 void scriptapi_luaentity_punch(lua_State *L, u16 id,
180                 ServerActiveObject *puncher, float time_from_last_punch,
181                 const ToolCapabilities *toolcap, v3f dir);
182 void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
183                 ServerActiveObject *clicker);
184
185 #endif
186