3 Copyright (C) 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 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.
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.
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.
20 #ifndef SCRIPTAPI_HEADER
21 #define SCRIPTAPI_HEADER
23 #include "irrlichttypes_bloated.h"
30 class ServerEnvironment;
31 class ServerActiveObject;
32 typedef struct lua_State lua_State;
33 struct ObjectProperties;
37 struct ToolCapabilities;
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);
44 void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj);
45 void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
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);
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,
59 void scriptapi_on_shutdown(lua_State *L);
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);
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);
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);
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);
94 void scriptapi_node_on_construct(lua_State *L, v3s16 p, MapNode node);
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);
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);
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);
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);
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);
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);
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);