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;
54 static const char className[];
55 static const luaL_Reg methods[];
58 static LuaEntitySAO* getluaobject(ObjectRef *ref);
60 static PlayerSAO* getplayersao(ObjectRef *ref);
62 static RemotePlayer *getplayer(ObjectRef *ref);
67 static int gc_object(lua_State *L);
70 static int l_remove(lua_State *L);
73 // returns: {x=num, y=num, z=num}
74 static int l_get_pos(lua_State *L);
77 static int l_set_pos(lua_State *L);
79 // move_to(self, pos, continuous=false)
80 static int l_move_to(lua_State *L);
82 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
83 static int l_punch(lua_State *L);
85 // right_click(self, clicker); clicker = an another ObjectRef
86 static int l_right_click(lua_State *L);
89 // hp = number of hitpoints (2 * number of hearts)
91 static int l_set_hp(lua_State *L);
94 // returns: number of hitpoints (2 * number of hearts)
95 // 0 if not applicable to this type of object
96 static int l_get_hp(lua_State *L);
98 // get_inventory(self)
99 static int l_get_inventory(lua_State *L);
101 // get_wield_list(self)
102 static int l_get_wield_list(lua_State *L);
104 // get_wield_index(self)
105 static int l_get_wield_index(lua_State *L);
107 // get_wielded_item(self)
108 static int l_get_wielded_item(lua_State *L);
110 // set_wielded_item(self, itemstack or itemstring or table or nil)
111 static int l_set_wielded_item(lua_State *L);
113 // set_armor_groups(self, groups)
114 static int l_set_armor_groups(lua_State *L);
116 // get_armor_groups(self)
117 static int l_get_armor_groups(lua_State *L);
119 // set_physics_override(self, physics_override_speed, physics_override_jump,
120 // physics_override_gravity, sneak, sneak_glitch, new_move)
121 static int l_set_physics_override(lua_State *L);
123 // get_physics_override(self)
124 static int l_get_physics_override(lua_State *L);
126 // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
127 static int l_set_animation(lua_State *L);
129 // set_animation_frame_speed(self, frame_speed)
130 static int l_set_animation_frame_speed(lua_State *L);
132 // get_animation(self)
133 static int l_get_animation(lua_State *L);
135 // set_bone_position(self, std::string bone, v3f position, v3f rotation)
136 static int l_set_bone_position(lua_State *L);
138 // get_bone_position(self, bone)
139 static int l_get_bone_position(lua_State *L);
141 // set_attach(self, parent, bone, position, rotation)
142 static int l_set_attach(lua_State *L);
145 static int l_get_attach(lua_State *L);
148 static int l_set_detach(lua_State *L);
150 // set_properties(self, properties)
151 static int l_set_properties(lua_State *L);
153 // get_properties(self)
154 static int l_get_properties(lua_State *L);
157 static int l_is_player(lua_State *L);
159 /* LuaEntitySAO-only */
161 // set_velocity(self, {x=num, y=num, z=num})
162 static int l_set_velocity(lua_State *L);
164 // add_velocity(self, {x=num, y=num, z=num})
165 static int l_add_velocity(lua_State *L);
167 // get_velocity(self)
168 static int l_get_velocity(lua_State *L);
170 // set_acceleration(self, {x=num, y=num, z=num})
171 static int l_set_acceleration(lua_State *L);
173 // get_acceleration(self)
174 static int l_get_acceleration(lua_State *L);
176 // set_yaw(self, radians)
177 static int l_set_yaw(lua_State *L);
180 static int l_get_yaw(lua_State *L);
182 // set_texture_mod(self, mod)
183 static int l_set_texture_mod(lua_State *L);
185 // l_get_texture_mod(self)
186 static int l_get_texture_mod(lua_State *L);
188 // set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
189 // select_horiz_by_yawpitch=false)
190 static int l_set_sprite(lua_State *L);
193 // get_entity_name(self)
194 static int l_get_entity_name(lua_State *L);
196 // get_luaentity(self)
197 static int l_get_luaentity(lua_State *L);
201 // is_player_connected(self)
202 static int l_is_player_connected(lua_State *L);
204 // get_player_name(self)
205 static int l_get_player_name(lua_State *L);
207 // get_player_velocity(self)
208 static int l_get_player_velocity(lua_State *L);
210 // get_look_dir(self)
211 static int l_get_look_dir(lua_State *L);
214 // get_look_pitch(self)
215 static int l_get_look_pitch(lua_State *L);
218 // get_look_yaw(self)
219 static int l_get_look_yaw(lua_State *L);
221 // get_look_pitch2(self)
222 static int l_get_look_vertical(lua_State *L);
224 // get_look_yaw2(self)
225 static int l_get_look_horizontal(lua_State *L);
227 // set_look_vertical(self, radians)
228 static int l_set_look_vertical(lua_State *L);
230 // set_look_horizontal(self, radians)
231 static int l_set_look_horizontal(lua_State *L);
234 // set_look_pitch(self, radians)
235 static int l_set_look_pitch(lua_State *L);
238 // set_look_yaw(self, radians)
239 static int l_set_look_yaw(lua_State *L);
241 // set_breath(self, breath)
242 static int l_set_breath(lua_State *L);
244 // get_breath(self, breath)
245 static int l_get_breath(lua_State *L);
247 // set_attribute(self, attribute, value)
248 static int l_set_attribute(lua_State *L);
250 // get_attribute(self, attribute)
251 static int l_get_attribute(lua_State *L);
254 static int l_get_meta(lua_State *L);
256 // set_inventory_formspec(self, formspec)
257 static int l_set_inventory_formspec(lua_State *L);
259 // get_inventory_formspec(self) -> formspec
260 static int l_get_inventory_formspec(lua_State *L);
262 // set_formspec_prepend(self, formspec)
263 static int l_set_formspec_prepend(lua_State *L);
265 // get_formspec_prepend(self) -> formspec
266 static int l_get_formspec_prepend(lua_State *L);
268 // get_player_control(self)
269 static int l_get_player_control(lua_State *L);
271 // get_player_control_bits(self)
272 static int l_get_player_control_bits(lua_State *L);
274 // hud_add(self, id, form)
275 static int l_hud_add(lua_State *L);
278 static int l_hud_remove(lua_State *L);
280 // hud_change(self, id, stat, data)
281 static int l_hud_change(lua_State *L);
283 // hud_get_next_id(self)
284 static u32 hud_get_next_id(lua_State *L);
287 static int l_hud_get(lua_State *L);
289 // hud_set_flags(self, flags)
290 static int l_hud_set_flags(lua_State *L);
293 static int l_hud_get_flags(lua_State *L);
295 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
296 static int l_hud_set_hotbar_itemcount(lua_State *L);
298 // hud_get_hotbar_itemcount(self)
299 static int l_hud_get_hotbar_itemcount(lua_State *L);
301 // hud_set_hotbar_image(self, name)
302 static int l_hud_set_hotbar_image(lua_State *L);
304 // hud_get_hotbar_image(self)
305 static int l_hud_get_hotbar_image(lua_State *L);
307 // hud_set_hotbar_selected_image(self, name)
308 static int l_hud_set_hotbar_selected_image(lua_State *L);
310 // hud_get_hotbar_selected_image(self)
311 static int l_hud_get_hotbar_selected_image(lua_State *L);
313 // set_sky(self, bgcolor, type, list, clouds = true)
314 static int l_set_sky(lua_State *L);
317 static int l_get_sky(lua_State *L);
319 // set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})
320 static int l_set_clouds(lua_State *L);
323 static int l_get_clouds(lua_State *L);
325 // override_day_night_ratio(self, type)
326 static int l_override_day_night_ratio(lua_State *L);
328 // get_day_night_ratio(self)
329 static int l_get_day_night_ratio(lua_State *L);
331 // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
332 static int l_set_local_animation(lua_State *L);
334 // get_local_animation(self)
335 static int l_get_local_animation(lua_State *L);
337 // set_eye_offset(self, v3f first pv, v3f third pv)
338 static int l_set_eye_offset(lua_State *L);
340 // get_eye_offset(self)
341 static int l_get_eye_offset(lua_State *L);
343 // set_nametag_attributes(self, attributes)
344 static int l_set_nametag_attributes(lua_State *L);
346 // get_nametag_attributes(self)
347 static int l_get_nametag_attributes(lua_State *L);