3 Copyright (C) 2013 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.
22 #include "lua_api/l_base.h"
23 #include "irrlichttypes.h"
25 class ServerActiveObject;
34 class ObjectRef : public ModApiBase {
36 ObjectRef(ServerActiveObject *object);
38 ~ObjectRef() = default;
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);
44 static void set_null(lua_State *L);
46 static void Register(lua_State *L);
48 static ObjectRef *checkobject(lua_State *L, int narg);
50 static ServerActiveObject* getobject(ObjectRef *ref);
52 ServerActiveObject *m_object = nullptr;
53 static const char className[];
54 static luaL_Reg methods[];
57 static LuaEntitySAO* getluaobject(ObjectRef *ref);
59 static PlayerSAO* getplayersao(ObjectRef *ref);
61 static RemotePlayer *getplayer(ObjectRef *ref);
66 static int gc_object(lua_State *L);
69 static int l_remove(lua_State *L);
72 static int l_get_pos(lua_State *L);
75 static int l_set_pos(lua_State *L);
77 // move_to(self, pos, continuous)
78 static int l_move_to(lua_State *L);
80 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
81 static int l_punch(lua_State *L);
83 // right_click(self, clicker)
84 static int l_right_click(lua_State *L);
86 // set_hp(self, hp, reason)
87 static int l_set_hp(lua_State *L);
90 static int l_get_hp(lua_State *L);
92 // get_inventory(self)
93 static int l_get_inventory(lua_State *L);
95 // get_wield_list(self)
96 static int l_get_wield_list(lua_State *L);
98 // get_wield_index(self)
99 static int l_get_wield_index(lua_State *L);
101 // get_wielded_item(self)
102 static int l_get_wielded_item(lua_State *L);
104 // set_wielded_item(self, item)
105 static int l_set_wielded_item(lua_State *L);
107 // set_armor_groups(self, groups)
108 static int l_set_armor_groups(lua_State *L);
110 // get_armor_groups(self)
111 static int l_get_armor_groups(lua_State *L);
113 // set_physics_override(self, override_table)
114 static int l_set_physics_override(lua_State *L);
116 // get_physics_override(self)
117 static int l_get_physics_override(lua_State *L);
119 // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
120 static int l_set_animation(lua_State *L);
122 // set_animation_frame_speed(self, frame_speed)
123 static int l_set_animation_frame_speed(lua_State *L);
125 // get_animation(self)
126 static int l_get_animation(lua_State *L);
128 // set_bone_position(self, bone, position, rotation)
129 static int l_set_bone_position(lua_State *L);
131 // get_bone_position(self, bone)
132 static int l_get_bone_position(lua_State *L);
134 // set_attach(self, parent, bone, position, rotation)
135 static int l_set_attach(lua_State *L);
138 static int l_get_attach(lua_State *L);
140 // get_children(self)
141 static int l_get_children(lua_State *L);
144 static int l_set_detach(lua_State *L);
146 // set_properties(self, properties)
147 static int l_set_properties(lua_State *L);
149 // get_properties(self)
150 static int l_get_properties(lua_State *L);
153 static int l_is_player(lua_State *L);
155 /* LuaEntitySAO-only */
157 // set_velocity(self, velocity)
158 static int l_set_velocity(lua_State *L);
160 // add_velocity(self, velocity)
161 static int l_add_velocity(lua_State *L);
163 // get_velocity(self)
164 static int l_get_velocity(lua_State *L);
166 // set_acceleration(self, acceleration)
167 static int l_set_acceleration(lua_State *L);
169 // get_acceleration(self)
170 static int l_get_acceleration(lua_State *L);
172 // set_rotation(self, rotation)
173 static int l_set_rotation(lua_State *L);
175 // get_rotation(self)
176 static int l_get_rotation(lua_State *L);
178 // set_yaw(self, yaw)
179 static int l_set_yaw(lua_State *L);
182 static int l_get_yaw(lua_State *L);
184 // set_texture_mod(self, mod)
185 static int l_set_texture_mod(lua_State *L);
187 // l_get_texture_mod(self)
188 static int l_get_texture_mod(lua_State *L);
190 // set_sprite(self, start_frame, num_frames, framelength, select_x_by_camera)
191 static int l_set_sprite(lua_State *L);
194 // get_entity_name(self)
195 static int l_get_entity_name(lua_State *L);
197 // get_luaentity(self)
198 static int l_get_luaentity(lua_State *L);
202 // get_player_name(self)
203 static int l_get_player_name(lua_State *L);
206 static int l_get_fov(lua_State *L);
208 // get_look_dir(self)
209 static int l_get_look_dir(lua_State *L);
212 // get_look_pitch(self)
213 static int l_get_look_pitch(lua_State *L);
216 // get_look_yaw(self)
217 static int l_get_look_yaw(lua_State *L);
219 // get_look_pitch2(self)
220 static int l_get_look_vertical(lua_State *L);
222 // get_look_yaw2(self)
223 static int l_get_look_horizontal(lua_State *L);
225 // set_fov(self, degrees, is_multiplier, transition_time)
226 static int l_set_fov(lua_State *L);
228 // set_look_vertical(self, radians)
229 static int l_set_look_vertical(lua_State *L);
231 // set_look_horizontal(self, radians)
232 static int l_set_look_horizontal(lua_State *L);
235 // set_look_pitch(self, radians)
236 static int l_set_look_pitch(lua_State *L);
239 // set_look_yaw(self, radians)
240 static int l_set_look_yaw(lua_State *L);
242 // set_breath(self, breath)
243 static int l_set_breath(lua_State *L);
245 // get_breath(self, breath)
246 static int l_get_breath(lua_State *L);
249 // set_attribute(self, attribute, value)
250 static int l_set_attribute(lua_State *L);
253 // get_attribute(self, attribute)
254 static int l_get_attribute(lua_State *L);
257 static int l_get_meta(lua_State *L);
259 // set_inventory_formspec(self, formspec)
260 static int l_set_inventory_formspec(lua_State *L);
262 // get_inventory_formspec(self)
263 static int l_get_inventory_formspec(lua_State *L);
265 // set_formspec_prepend(self, formspec)
266 static int l_set_formspec_prepend(lua_State *L);
268 // get_formspec_prepend(self)
269 static int l_get_formspec_prepend(lua_State *L);
271 // get_player_control(self)
272 static int l_get_player_control(lua_State *L);
274 // get_player_control_bits(self)
275 static int l_get_player_control_bits(lua_State *L);
277 // hud_add(self, id, form)
278 static int l_hud_add(lua_State *L);
281 static int l_hud_remove(lua_State *L);
283 // hud_change(self, id, stat, data)
284 static int l_hud_change(lua_State *L);
286 // hud_get_next_id(self)
287 static u32 hud_get_next_id(lua_State *L);
290 static int l_hud_get(lua_State *L);
292 // hud_set_flags(self, flags)
293 static int l_hud_set_flags(lua_State *L);
296 static int l_hud_get_flags(lua_State *L);
298 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
299 static int l_hud_set_hotbar_itemcount(lua_State *L);
301 // hud_get_hotbar_itemcount(self)
302 static int l_hud_get_hotbar_itemcount(lua_State *L);
304 // hud_set_hotbar_image(self, name)
305 static int l_hud_set_hotbar_image(lua_State *L);
307 // hud_get_hotbar_image(self)
308 static int l_hud_get_hotbar_image(lua_State *L);
310 // hud_set_hotbar_selected_image(self, name)
311 static int l_hud_set_hotbar_selected_image(lua_State *L);
313 // hud_get_hotbar_selected_image(self)
314 static int l_hud_get_hotbar_selected_image(lua_State *L);
316 // set_sky(self, sky_parameters)
317 static int l_set_sky(lua_State *L);
319 // get_sky(self, as_table)
320 static int l_get_sky(lua_State *L);
323 // get_sky_color(self)
324 static int l_get_sky_color(lua_State* L);
326 // set_sun(self, sun_parameters)
327 static int l_set_sun(lua_State *L);
330 static int l_get_sun(lua_State *L);
332 // set_moon(self, moon_parameters)
333 static int l_set_moon(lua_State *L);
336 static int l_get_moon(lua_State *L);
338 // set_stars(self, star_parameters)
339 static int l_set_stars(lua_State *L);
342 static int l_get_stars(lua_State *L);
344 // set_clouds(self, cloud_parameters)
345 static int l_set_clouds(lua_State *L);
348 static int l_get_clouds(lua_State *L);
350 // override_day_night_ratio(self, type)
351 static int l_override_day_night_ratio(lua_State *L);
353 // get_day_night_ratio(self)
354 static int l_get_day_night_ratio(lua_State *L);
356 // set_local_animation(self, idle, walk, dig, walk_while_dig, frame_speed)
357 static int l_set_local_animation(lua_State *L);
359 // get_local_animation(self)
360 static int l_get_local_animation(lua_State *L);
362 // set_eye_offset(self, firstperson, thirdperson)
363 static int l_set_eye_offset(lua_State *L);
365 // get_eye_offset(self)
366 static int l_get_eye_offset(lua_State *L);
368 // set_nametag_attributes(self, attributes)
369 static int l_set_nametag_attributes(lua_State *L);
371 // get_nametag_attributes(self)
372 static int l_get_nametag_attributes(lua_State *L);
374 // send_mapblock(pos)
375 static int l_send_mapblock(lua_State *L);
377 // set_minimap_modes(self, modes, wanted_mode)
378 static int l_set_minimap_modes(lua_State *L);
380 // set_lighting(self, lighting)
381 static int l_set_lighting(lua_State *L);
383 // get_lighting(self)
384 static int l_get_lighting(lua_State *L);
387 static int l_respawn(lua_State *L);