Add protocol_version and supported package types to ContentDB urls
[oweals/minetest.git] / src / script / lua_api / l_object.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 #pragma once
21
22 #include "lua_api/l_base.h"
23 #include "irrlichttypes.h"
24
25 class ServerActiveObject;
26 class LuaEntitySAO;
27 class PlayerSAO;
28 class RemotePlayer;
29
30 /*
31         ObjectRef
32 */
33
34 class ObjectRef : public ModApiBase {
35 public:
36         ObjectRef(ServerActiveObject *object);
37
38         ~ObjectRef() = default;
39
40         // Creates an ObjectRef and leaves it on top of stack
41         // Not callable from Lua; all references are created on the C side.
42         static void create(lua_State *L, ServerActiveObject *object);
43
44         static void set_null(lua_State *L);
45
46         static void Register(lua_State *L);
47
48         static ObjectRef *checkobject(lua_State *L, int narg);
49
50         static ServerActiveObject* getobject(ObjectRef *ref);
51 private:
52         ServerActiveObject *m_object = nullptr;
53         static const char className[];
54         static luaL_Reg methods[];
55
56
57         static LuaEntitySAO* getluaobject(ObjectRef *ref);
58
59         static PlayerSAO* getplayersao(ObjectRef *ref);
60
61         static RemotePlayer *getplayer(ObjectRef *ref);
62
63         // Exported functions
64
65         // garbage collector
66         static int gc_object(lua_State *L);
67
68         // remove(self)
69         static int l_remove(lua_State *L);
70
71         // get_pos(self)
72         // returns: {x=num, y=num, z=num}
73         static int l_get_pos(lua_State *L);
74
75         // set_pos(self, pos)
76         static int l_set_pos(lua_State *L);
77
78         // move_to(self, pos, continuous=false)
79         static int l_move_to(lua_State *L);
80
81         // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
82         static int l_punch(lua_State *L);
83
84         // right_click(self, clicker); clicker = an another ObjectRef
85         static int l_right_click(lua_State *L);
86
87         // set_hp(self, hp)
88         // hp = number of hitpoints (2 * number of hearts)
89         // returns: nil
90         static int l_set_hp(lua_State *L);
91
92         // get_hp(self)
93         // returns: number of hitpoints (2 * number of hearts)
94         // 0 if not applicable to this type of object
95         static int l_get_hp(lua_State *L);
96
97         // get_inventory(self)
98         static int l_get_inventory(lua_State *L);
99
100         // get_wield_list(self)
101         static int l_get_wield_list(lua_State *L);
102
103         // get_wield_index(self)
104         static int l_get_wield_index(lua_State *L);
105
106         // get_wielded_item(self)
107         static int l_get_wielded_item(lua_State *L);
108
109         // set_wielded_item(self, itemstack or itemstring or table or nil)
110         static int l_set_wielded_item(lua_State *L);
111
112         // set_armor_groups(self, groups)
113         static int l_set_armor_groups(lua_State *L);
114
115         // get_armor_groups(self)
116         static int l_get_armor_groups(lua_State *L);
117
118         // set_physics_override(self, physics_override_speed, physics_override_jump,
119         //                      physics_override_gravity, sneak, sneak_glitch, new_move)
120         static int l_set_physics_override(lua_State *L);
121
122         // get_physics_override(self)
123         static int l_get_physics_override(lua_State *L);
124
125         // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
126         static int l_set_animation(lua_State *L);
127
128         // set_animation_frame_speed(self, frame_speed)
129         static int l_set_animation_frame_speed(lua_State *L);
130
131         // get_animation(self)
132         static int l_get_animation(lua_State *L);
133
134         // set_bone_position(self, std::string bone, v3f position, v3f rotation)
135         static int l_set_bone_position(lua_State *L);
136
137         // get_bone_position(self, bone)
138         static int l_get_bone_position(lua_State *L);
139
140         // set_attach(self, parent, bone, position, rotation)
141         static int l_set_attach(lua_State *L);
142
143         // get_attach(self)
144         static int l_get_attach(lua_State *L);
145
146         // set_detach(self)
147         static int l_set_detach(lua_State *L);
148
149         // set_properties(self, properties)
150         static int l_set_properties(lua_State *L);
151
152         // get_properties(self)
153         static int l_get_properties(lua_State *L);
154
155         // is_player(self)
156         static int l_is_player(lua_State *L);
157
158         /* LuaEntitySAO-only */
159
160         // set_velocity(self, {x=num, y=num, z=num})
161         static int l_set_velocity(lua_State *L);
162
163         // add_velocity(self, {x=num, y=num, z=num})
164         static int l_add_velocity(lua_State *L);
165
166         // get_velocity(self)
167         static int l_get_velocity(lua_State *L);
168
169         // set_acceleration(self, {x=num, y=num, z=num})
170         static int l_set_acceleration(lua_State *L);
171
172         // get_acceleration(self)
173         static int l_get_acceleration(lua_State *L);
174
175         // set_yaw(self, radians)
176         static int l_set_yaw(lua_State *L);
177
178         // get_yaw(self)
179         static int l_get_yaw(lua_State *L);
180
181         // set_texture_mod(self, mod)
182         static int l_set_texture_mod(lua_State *L);
183
184         // l_get_texture_mod(self)
185         static int l_get_texture_mod(lua_State *L);
186
187         // set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
188         //           select_horiz_by_yawpitch=false)
189         static int l_set_sprite(lua_State *L);
190
191         // DEPRECATED
192         // get_entity_name(self)
193         static int l_get_entity_name(lua_State *L);
194
195         // get_luaentity(self)
196         static int l_get_luaentity(lua_State *L);
197
198         /* Player-only */
199
200         // is_player_connected(self)
201         static int l_is_player_connected(lua_State *L);
202
203         // get_player_name(self)
204         static int l_get_player_name(lua_State *L);
205
206         // get_player_velocity(self)
207         static int l_get_player_velocity(lua_State *L);
208
209         // get_look_dir(self)
210         static int l_get_look_dir(lua_State *L);
211
212         // DEPRECATED
213         // get_look_pitch(self)
214         static int l_get_look_pitch(lua_State *L);
215
216         // DEPRECATED
217         // get_look_yaw(self)
218         static int l_get_look_yaw(lua_State *L);
219
220         // get_look_pitch2(self)
221         static int l_get_look_vertical(lua_State *L);
222
223         // get_look_yaw2(self)
224         static int l_get_look_horizontal(lua_State *L);
225
226         // set_look_vertical(self, radians)
227         static int l_set_look_vertical(lua_State *L);
228
229         // set_look_horizontal(self, radians)
230         static int l_set_look_horizontal(lua_State *L);
231
232         // DEPRECATED
233         // set_look_pitch(self, radians)
234         static int l_set_look_pitch(lua_State *L);
235
236         // DEPRECATED
237         // set_look_yaw(self, radians)
238         static int l_set_look_yaw(lua_State *L);
239
240         // set_breath(self, breath)
241         static int l_set_breath(lua_State *L);
242
243         // get_breath(self, breath)
244         static int l_get_breath(lua_State *L);
245
246         // set_attribute(self, attribute, value)
247         static int l_set_attribute(lua_State *L);
248
249         // get_attribute(self, attribute)
250         static int l_get_attribute(lua_State *L);
251
252         // get_meta(self)
253         static int l_get_meta(lua_State *L);
254
255         // set_inventory_formspec(self, formspec)
256         static int l_set_inventory_formspec(lua_State *L);
257
258         // get_inventory_formspec(self) -> formspec
259         static int l_get_inventory_formspec(lua_State *L);
260
261         // set_formspec_prepend(self, formspec)
262         static int l_set_formspec_prepend(lua_State *L);
263
264         // get_formspec_prepend(self) -> formspec
265         static int l_get_formspec_prepend(lua_State *L);
266
267         // get_player_control(self)
268         static int l_get_player_control(lua_State *L);
269
270         // get_player_control_bits(self)
271         static int l_get_player_control_bits(lua_State *L);
272
273         // hud_add(self, id, form)
274         static int l_hud_add(lua_State *L);
275
276         // hud_rm(self, id)
277         static int l_hud_remove(lua_State *L);
278
279         // hud_change(self, id, stat, data)
280         static int l_hud_change(lua_State *L);
281
282         // hud_get_next_id(self)
283         static u32 hud_get_next_id(lua_State *L);
284
285         // hud_get(self, id)
286         static int l_hud_get(lua_State *L);
287
288         // hud_set_flags(self, flags)
289         static int l_hud_set_flags(lua_State *L);
290
291         // hud_get_flags()
292         static int l_hud_get_flags(lua_State *L);
293
294         // hud_set_hotbar_itemcount(self, hotbar_itemcount)
295         static int l_hud_set_hotbar_itemcount(lua_State *L);
296
297         // hud_get_hotbar_itemcount(self)
298         static int l_hud_get_hotbar_itemcount(lua_State *L);
299
300         // hud_set_hotbar_image(self, name)
301         static int l_hud_set_hotbar_image(lua_State *L);
302
303         // hud_get_hotbar_image(self)
304         static int l_hud_get_hotbar_image(lua_State *L);
305
306         // hud_set_hotbar_selected_image(self, name)
307         static int l_hud_set_hotbar_selected_image(lua_State *L);
308
309         // hud_get_hotbar_selected_image(self)
310         static int l_hud_get_hotbar_selected_image(lua_State *L);
311
312         // set_sky(self, bgcolor, type, list, clouds = true)
313         static int l_set_sky(lua_State *L);
314
315         // get_sky(self)
316         static int l_get_sky(lua_State *L);
317
318         // set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})
319         static int l_set_clouds(lua_State *L);
320
321         // get_clouds(self)
322         static int l_get_clouds(lua_State *L);
323
324         // override_day_night_ratio(self, type)
325         static int l_override_day_night_ratio(lua_State *L);
326
327         // get_day_night_ratio(self)
328         static int l_get_day_night_ratio(lua_State *L);
329
330         // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
331         static int l_set_local_animation(lua_State *L);
332
333         // get_local_animation(self)
334         static int l_get_local_animation(lua_State *L);
335
336         // set_eye_offset(self, v3f first pv, v3f third pv)
337         static int l_set_eye_offset(lua_State *L);
338
339         // get_eye_offset(self)
340         static int l_get_eye_offset(lua_State *L);
341
342         // set_nametag_attributes(self, attributes)
343         static int l_set_nametag_attributes(lua_State *L);
344
345         // get_nametag_attributes(self)
346         static int l_get_nametag_attributes(lua_State *L);
347
348 };