SAO work: ActiveObject types & SAO cleanup * Replace u8 types with ActiveObjectType...
[oweals/minetest.git] / src / script / lua_api / l_object.cpp
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 #include "lua_api/l_object.h"
21 #include "lua_api/l_internal.h"
22 #include "lua_api/l_inventory.h"
23 #include "lua_api/l_item.h"
24 #include "common/c_converter.h"
25 #include "common/c_content.h"
26 #include "log.h"
27 #include "tool.h"
28 #include "serverobject.h"
29 #include "content_sao.h"
30 #include "server.h"
31 #include "hud.h"
32
33
34 struct EnumString es_HudElementType[] =
35 {
36         {HUD_ELEM_IMAGE,     "image"},
37         {HUD_ELEM_TEXT,      "text"},
38         {HUD_ELEM_STATBAR,   "statbar"},
39         {HUD_ELEM_INVENTORY, "inventory"},
40         {HUD_ELEM_WAYPOINT,  "waypoint"},
41 {0, NULL},
42 };
43
44 struct EnumString es_HudElementStat[] =
45 {
46         {HUD_STAT_POS,    "position"},
47         {HUD_STAT_POS,    "pos"}, /* Deprecated, only for compatibility's sake */
48         {HUD_STAT_NAME,   "name"},
49         {HUD_STAT_SCALE,  "scale"},
50         {HUD_STAT_TEXT,   "text"},
51         {HUD_STAT_NUMBER, "number"},
52         {HUD_STAT_ITEM,   "item"},
53         {HUD_STAT_DIR,    "direction"},
54         {HUD_STAT_ALIGN,  "alignment"},
55         {HUD_STAT_OFFSET, "offset"},
56         {HUD_STAT_WORLD_POS, "world_pos"},
57         {0, NULL},
58 };
59
60 struct EnumString es_HudBuiltinElement[] =
61 {
62         {HUD_FLAG_HOTBAR_VISIBLE,    "hotbar"},
63         {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"},
64         {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
65         {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
66         {HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
67         {0, NULL},
68 };
69
70 /*
71         ObjectRef
72 */
73
74
75 ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
76 {
77         luaL_checktype(L, narg, LUA_TUSERDATA);
78         void *ud = luaL_checkudata(L, narg, className);
79         if(!ud) luaL_typerror(L, narg, className);
80         return *(ObjectRef**)ud;  // unbox pointer
81 }
82
83 ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
84 {
85         ServerActiveObject *co = ref->m_object;
86         return co;
87 }
88
89 LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
90 {
91         ServerActiveObject *obj = getobject(ref);
92         if(obj == NULL)
93                 return NULL;
94         if(obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
95                 return NULL;
96         return (LuaEntitySAO*)obj;
97 }
98
99 PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
100 {
101         ServerActiveObject *obj = getobject(ref);
102         if(obj == NULL)
103                 return NULL;
104         if(obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
105                 return NULL;
106         return (PlayerSAO*)obj;
107 }
108
109 Player* ObjectRef::getplayer(ObjectRef *ref)
110 {
111         PlayerSAO *playersao = getplayersao(ref);
112         if(playersao == NULL)
113                 return NULL;
114         return playersao->getPlayer();
115 }
116
117 // Exported functions
118
119 // garbage collector
120 int ObjectRef::gc_object(lua_State *L) {
121         ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1));
122         //infostream<<"ObjectRef::gc_object: o="<<o<<std::endl;
123         delete o;
124         return 0;
125 }
126
127 // remove(self)
128 int ObjectRef::l_remove(lua_State *L)
129 {
130         NO_MAP_LOCK_REQUIRED;
131         ObjectRef *ref = checkobject(L, 1);
132         ServerActiveObject *co = getobject(ref);
133         if(co == NULL) return 0;
134         verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl;
135         co->m_removed = true;
136         return 0;
137 }
138
139 // getpos(self)
140 // returns: {x=num, y=num, z=num}
141 int ObjectRef::l_getpos(lua_State *L)
142 {
143         NO_MAP_LOCK_REQUIRED;
144         ObjectRef *ref = checkobject(L, 1);
145         ServerActiveObject *co = getobject(ref);
146         if(co == NULL) return 0;
147         v3f pos = co->getBasePosition() / BS;
148         lua_newtable(L);
149         lua_pushnumber(L, pos.X);
150         lua_setfield(L, -2, "x");
151         lua_pushnumber(L, pos.Y);
152         lua_setfield(L, -2, "y");
153         lua_pushnumber(L, pos.Z);
154         lua_setfield(L, -2, "z");
155         return 1;
156 }
157
158 // setpos(self, pos)
159 int ObjectRef::l_setpos(lua_State *L)
160 {
161         NO_MAP_LOCK_REQUIRED;
162         ObjectRef *ref = checkobject(L, 1);
163         //LuaEntitySAO *co = getluaobject(ref);
164         ServerActiveObject *co = getobject(ref);
165         if(co == NULL) return 0;
166         // pos
167         v3f pos = checkFloatPos(L, 2);
168         // Do it
169         co->setPos(pos);
170         return 0;
171 }
172
173 // moveto(self, pos, continuous=false)
174 int ObjectRef::l_moveto(lua_State *L)
175 {
176         NO_MAP_LOCK_REQUIRED;
177         ObjectRef *ref = checkobject(L, 1);
178         //LuaEntitySAO *co = getluaobject(ref);
179         ServerActiveObject *co = getobject(ref);
180         if(co == NULL) return 0;
181         // pos
182         v3f pos = checkFloatPos(L, 2);
183         // continuous
184         bool continuous = lua_toboolean(L, 3);
185         // Do it
186         co->moveTo(pos, continuous);
187         return 0;
188 }
189
190 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
191 int ObjectRef::l_punch(lua_State *L)
192 {
193         NO_MAP_LOCK_REQUIRED;
194         ObjectRef *ref = checkobject(L, 1);
195         ObjectRef *puncher_ref = checkobject(L, 2);
196         ServerActiveObject *co = getobject(ref);
197         ServerActiveObject *puncher = getobject(puncher_ref);
198         if(co == NULL) return 0;
199         if(puncher == NULL) return 0;
200         v3f dir;
201         if(lua_type(L, 5) != LUA_TTABLE)
202                 dir = co->getBasePosition() - puncher->getBasePosition();
203         else
204                 dir = read_v3f(L, 5);
205         float time_from_last_punch = 1000000;
206         if(lua_isnumber(L, 3))
207                 time_from_last_punch = lua_tonumber(L, 3);
208         ToolCapabilities toolcap = read_tool_capabilities(L, 4);
209         dir.normalize();
210         // Do it
211         co->punch(dir, &toolcap, puncher, time_from_last_punch);
212         return 0;
213 }
214
215 // right_click(self, clicker); clicker = an another ObjectRef
216 int ObjectRef::l_right_click(lua_State *L)
217 {
218         NO_MAP_LOCK_REQUIRED;
219         ObjectRef *ref = checkobject(L, 1);
220         ObjectRef *ref2 = checkobject(L, 2);
221         ServerActiveObject *co = getobject(ref);
222         ServerActiveObject *co2 = getobject(ref2);
223         if(co == NULL) return 0;
224         if(co2 == NULL) return 0;
225         // Do it
226         co->rightClick(co2);
227         return 0;
228 }
229
230 // set_hp(self, hp)
231 // hp = number of hitpoints (2 * number of hearts)
232 // returns: nil
233 int ObjectRef::l_set_hp(lua_State *L)
234 {
235         NO_MAP_LOCK_REQUIRED;
236         ObjectRef *ref = checkobject(L, 1);
237         luaL_checknumber(L, 2);
238         ServerActiveObject *co = getobject(ref);
239         if(co == NULL) return 0;
240         int hp = lua_tonumber(L, 2);
241         /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId()
242                         <<" hp="<<hp<<std::endl;*/
243         // Do it
244         co->setHP(hp);
245         // Return
246         return 0;
247 }
248
249 // get_hp(self)
250 // returns: number of hitpoints (2 * number of hearts)
251 // 0 if not applicable to this type of object
252 int ObjectRef::l_get_hp(lua_State *L)
253 {
254         NO_MAP_LOCK_REQUIRED;
255         ObjectRef *ref = checkobject(L, 1);
256         ServerActiveObject *co = getobject(ref);
257         if(co == NULL){
258                 // Default hp is 1
259                 lua_pushnumber(L, 1);
260                 return 1;
261         }
262         int hp = co->getHP();
263         /*infostream<<"ObjectRef::l_get_hp(): id="<<co->getId()
264                         <<" hp="<<hp<<std::endl;*/
265         // Return
266         lua_pushnumber(L, hp);
267         return 1;
268 }
269
270 // get_inventory(self)
271 int ObjectRef::l_get_inventory(lua_State *L)
272 {
273         NO_MAP_LOCK_REQUIRED;
274         ObjectRef *ref = checkobject(L, 1);
275         ServerActiveObject *co = getobject(ref);
276         if(co == NULL) return 0;
277         // Do it
278         InventoryLocation loc = co->getInventoryLocation();
279         if(getServer(L)->getInventory(loc) != NULL)
280                 InvRef::create(L, loc);
281         else
282                 lua_pushnil(L); // An object may have no inventory (nil)
283         return 1;
284 }
285
286 // get_wield_list(self)
287 int ObjectRef::l_get_wield_list(lua_State *L)
288 {
289         NO_MAP_LOCK_REQUIRED;
290         ObjectRef *ref = checkobject(L, 1);
291         ServerActiveObject *co = getobject(ref);
292         if(co == NULL) return 0;
293         // Do it
294         lua_pushstring(L, co->getWieldList().c_str());
295         return 1;
296 }
297
298 // get_wield_index(self)
299 int ObjectRef::l_get_wield_index(lua_State *L)
300 {
301         NO_MAP_LOCK_REQUIRED;
302         ObjectRef *ref = checkobject(L, 1);
303         ServerActiveObject *co = getobject(ref);
304         if(co == NULL) return 0;
305         // Do it
306         lua_pushinteger(L, co->getWieldIndex() + 1);
307         return 1;
308 }
309
310 // get_wielded_item(self)
311 int ObjectRef::l_get_wielded_item(lua_State *L)
312 {
313         NO_MAP_LOCK_REQUIRED;
314         ObjectRef *ref = checkobject(L, 1);
315         ServerActiveObject *co = getobject(ref);
316         if(co == NULL){
317                 // Empty ItemStack
318                 LuaItemStack::create(L, ItemStack());
319                 return 1;
320         }
321         // Do it
322         LuaItemStack::create(L, co->getWieldedItem());
323         return 1;
324 }
325
326 // set_wielded_item(self, itemstack or itemstring or table or nil)
327 int ObjectRef::l_set_wielded_item(lua_State *L)
328 {
329         NO_MAP_LOCK_REQUIRED;
330         ObjectRef *ref = checkobject(L, 1);
331         ServerActiveObject *co = getobject(ref);
332         if(co == NULL) return 0;
333         // Do it
334         ItemStack item = read_item(L, 2, getServer(L));
335         bool success = co->setWieldedItem(item);
336         lua_pushboolean(L, success);
337         return 1;
338 }
339
340 // set_armor_groups(self, groups)
341 int ObjectRef::l_set_armor_groups(lua_State *L)
342 {
343         NO_MAP_LOCK_REQUIRED;
344         ObjectRef *ref = checkobject(L, 1);
345         ServerActiveObject *co = getobject(ref);
346         if(co == NULL) return 0;
347         // Do it
348         ItemGroupList groups;
349         read_groups(L, 2, groups);
350         co->setArmorGroups(groups);
351         return 0;
352 }
353
354 // set_physics_override(self, physics_override_speed, physics_override_jump,
355 //                      physics_override_gravity, sneak, sneak_glitch)
356 int ObjectRef::l_set_physics_override(lua_State *L)
357 {
358         ObjectRef *ref = checkobject(L, 1);
359         PlayerSAO *co = (PlayerSAO *) getobject(ref);
360         if(co == NULL) return 0;
361         // Do it
362         if (lua_istable(L, 2)) {
363                 co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
364                 co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
365                 co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
366                 co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
367                 co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
368                 co->m_physics_override_sent = false;
369         } else {
370                 // old, non-table format
371                 if(!lua_isnil(L, 2)){
372                         co->m_physics_override_speed = lua_tonumber(L, 2);
373                         co->m_physics_override_sent = false;
374                 }
375                 if(!lua_isnil(L, 3)){
376                         co->m_physics_override_jump = lua_tonumber(L, 3);
377                         co->m_physics_override_sent = false;
378                 }
379                 if(!lua_isnil(L, 4)){
380                         co->m_physics_override_gravity = lua_tonumber(L, 4);
381                         co->m_physics_override_sent = false;
382                 }
383         }
384         return 0;
385 }
386
387 // set_animation(self, frame_range, frame_speed, frame_blend)
388 int ObjectRef::l_set_animation(lua_State *L)
389 {
390         NO_MAP_LOCK_REQUIRED;
391         ObjectRef *ref = checkobject(L, 1);
392         ServerActiveObject *co = getobject(ref);
393         if(co == NULL) return 0;
394         // Do it
395         v2f frames = v2f(1, 1);
396         if(!lua_isnil(L, 2))
397                 frames = read_v2f(L, 2);
398         float frame_speed = 15;
399         if(!lua_isnil(L, 3))
400                 frame_speed = lua_tonumber(L, 3);
401         float frame_blend = 0;
402         if(!lua_isnil(L, 4))
403                 frame_blend = lua_tonumber(L, 4);
404         co->setAnimation(frames, frame_speed, frame_blend);
405         return 0;
406 }
407
408 // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
409 int ObjectRef::l_set_local_animation(lua_State *L)
410 {
411         //NO_MAP_LOCK_REQUIRED;
412         ObjectRef *ref = checkobject(L, 1);
413         Player *player = getplayer(ref);
414         if (player == NULL)
415                 return 0;
416         // Do it
417         v2s32 frames[4];
418         for (int i=0;i<4;i++) {
419                 if(!lua_isnil(L, 2+1))
420                         frames[i] = read_v2s32(L, 2+i);
421         }
422         float frame_speed = 30;
423         if(!lua_isnil(L, 6))
424                 frame_speed = lua_tonumber(L, 6);
425
426         if (!getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed))
427                 return 0;
428
429         lua_pushboolean(L, true);
430         return 0;
431 }
432
433 // set_eye_offset(self, v3f first pv, v3f third pv)
434 int ObjectRef::l_set_eye_offset(lua_State *L)
435 {
436         //NO_MAP_LOCK_REQUIRED;
437         ObjectRef *ref = checkobject(L, 1);
438         Player *player = getplayer(ref);
439         if (player == NULL)
440                 return 0;
441         // Do it
442         v3f offset_first = v3f(0, 0, 0);
443         v3f offset_third = v3f(0, 0, 0);
444
445         if(!lua_isnil(L, 2))
446                 offset_first = read_v3f(L, 2);
447         if(!lua_isnil(L, 3))
448                 offset_third = read_v3f(L, 3);
449
450         // Prevent abuse of offset values (keep player always visible)
451         offset_third.X = rangelim(offset_third.X,-10,10);
452         offset_third.Z = rangelim(offset_third.Z,-5,5);
453         /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
454         offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
455
456         if (!getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third))
457                 return 0;
458
459         lua_pushboolean(L, true);
460         return 0;
461 }
462
463 // set_bone_position(self, std::string bone, v3f position, v3f rotation)
464 int ObjectRef::l_set_bone_position(lua_State *L)
465 {
466         NO_MAP_LOCK_REQUIRED;
467         ObjectRef *ref = checkobject(L, 1);
468         ServerActiveObject *co = getobject(ref);
469         if(co == NULL) return 0;
470         // Do it
471         std::string bone = "";
472         if(!lua_isnil(L, 2))
473                 bone = lua_tostring(L, 2);
474         v3f position = v3f(0, 0, 0);
475         if(!lua_isnil(L, 3))
476                 position = read_v3f(L, 3);
477         v3f rotation = v3f(0, 0, 0);
478         if(!lua_isnil(L, 4))
479                 rotation = read_v3f(L, 4);
480         co->setBonePosition(bone, position, rotation);
481         return 0;
482 }
483
484 // set_attach(self, parent, bone, position, rotation)
485 int ObjectRef::l_set_attach(lua_State *L)
486 {
487         NO_MAP_LOCK_REQUIRED;
488         ObjectRef *ref = checkobject(L, 1);
489         ObjectRef *parent_ref = checkobject(L, 2);
490         ServerActiveObject *co = getobject(ref);
491         ServerActiveObject *parent = getobject(parent_ref);
492         if(co == NULL) return 0;
493         if(parent == NULL) return 0;
494         // Do it
495         std::string bone = "";
496         if(!lua_isnil(L, 3))
497                 bone = lua_tostring(L, 3);
498         v3f position = v3f(0, 0, 0);
499         if(!lua_isnil(L, 4))
500                 position = read_v3f(L, 4);
501         v3f rotation = v3f(0, 0, 0);
502         if(!lua_isnil(L, 5))
503                 rotation = read_v3f(L, 5);
504         co->setAttachment(parent->getId(), bone, position, rotation);
505         return 0;
506 }
507
508 // set_detach(self)
509 int ObjectRef::l_set_detach(lua_State *L)
510 {
511         NO_MAP_LOCK_REQUIRED;
512         ObjectRef *ref = checkobject(L, 1);
513         ServerActiveObject *co = getobject(ref);
514         if(co == NULL) return 0;
515         // Do it
516         co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
517         return 0;
518 }
519
520 // set_properties(self, properties)
521 int ObjectRef::l_set_properties(lua_State *L)
522 {
523         NO_MAP_LOCK_REQUIRED;
524         ObjectRef *ref = checkobject(L, 1);
525         ServerActiveObject *co = getobject(ref);
526         if(co == NULL) return 0;
527         ObjectProperties *prop = co->accessObjectProperties();
528         if(!prop)
529                 return 0;
530         read_object_properties(L, 2, prop);
531         co->notifyObjectPropertiesModified();
532         return 0;
533 }
534
535 /* LuaEntitySAO-only */
536
537 // setvelocity(self, {x=num, y=num, z=num})
538 int ObjectRef::l_setvelocity(lua_State *L)
539 {
540         NO_MAP_LOCK_REQUIRED;
541         ObjectRef *ref = checkobject(L, 1);
542         LuaEntitySAO *co = getluaobject(ref);
543         if(co == NULL) return 0;
544         v3f pos = checkFloatPos(L, 2);
545         // Do it
546         co->setVelocity(pos);
547         return 0;
548 }
549
550 // getvelocity(self)
551 int ObjectRef::l_getvelocity(lua_State *L)
552 {
553         NO_MAP_LOCK_REQUIRED;
554         ObjectRef *ref = checkobject(L, 1);
555         LuaEntitySAO *co = getluaobject(ref);
556         if(co == NULL) return 0;
557         // Do it
558         v3f v = co->getVelocity();
559         pushFloatPos(L, v);
560         return 1;
561 }
562
563 // setacceleration(self, {x=num, y=num, z=num})
564 int ObjectRef::l_setacceleration(lua_State *L)
565 {
566         NO_MAP_LOCK_REQUIRED;
567         ObjectRef *ref = checkobject(L, 1);
568         LuaEntitySAO *co = getluaobject(ref);
569         if(co == NULL) return 0;
570         // pos
571         v3f pos = checkFloatPos(L, 2);
572         // Do it
573         co->setAcceleration(pos);
574         return 0;
575 }
576
577 // getacceleration(self)
578 int ObjectRef::l_getacceleration(lua_State *L)
579 {
580         NO_MAP_LOCK_REQUIRED;
581         ObjectRef *ref = checkobject(L, 1);
582         LuaEntitySAO *co = getluaobject(ref);
583         if(co == NULL) return 0;
584         // Do it
585         v3f v = co->getAcceleration();
586         pushFloatPos(L, v);
587         return 1;
588 }
589
590 // setyaw(self, radians)
591 int ObjectRef::l_setyaw(lua_State *L)
592 {
593         NO_MAP_LOCK_REQUIRED;
594         ObjectRef *ref = checkobject(L, 1);
595         LuaEntitySAO *co = getluaobject(ref);
596         if(co == NULL) return 0;
597         float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
598         // Do it
599         co->setYaw(yaw);
600         return 0;
601 }
602
603 // getyaw(self)
604 int ObjectRef::l_getyaw(lua_State *L)
605 {
606         NO_MAP_LOCK_REQUIRED;
607         ObjectRef *ref = checkobject(L, 1);
608         LuaEntitySAO *co = getluaobject(ref);
609         if(co == NULL) return 0;
610         // Do it
611         float yaw = co->getYaw() * core::DEGTORAD;
612         lua_pushnumber(L, yaw);
613         return 1;
614 }
615
616 // settexturemod(self, mod)
617 int ObjectRef::l_settexturemod(lua_State *L)
618 {
619         NO_MAP_LOCK_REQUIRED;
620         ObjectRef *ref = checkobject(L, 1);
621         LuaEntitySAO *co = getluaobject(ref);
622         if(co == NULL) return 0;
623         // Do it
624         std::string mod = luaL_checkstring(L, 2);
625         co->setTextureMod(mod);
626         return 0;
627 }
628
629 // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
630 //           select_horiz_by_yawpitch=false)
631 int ObjectRef::l_setsprite(lua_State *L)
632 {
633         NO_MAP_LOCK_REQUIRED;
634         ObjectRef *ref = checkobject(L, 1);
635         LuaEntitySAO *co = getluaobject(ref);
636         if(co == NULL) return 0;
637         // Do it
638         v2s16 p(0,0);
639         if(!lua_isnil(L, 2))
640                 p = read_v2s16(L, 2);
641         int num_frames = 1;
642         if(!lua_isnil(L, 3))
643                 num_frames = lua_tonumber(L, 3);
644         float framelength = 0.2;
645         if(!lua_isnil(L, 4))
646                 framelength = lua_tonumber(L, 4);
647         bool select_horiz_by_yawpitch = false;
648         if(!lua_isnil(L, 5))
649                 select_horiz_by_yawpitch = lua_toboolean(L, 5);
650         co->setSprite(p, num_frames, framelength, select_horiz_by_yawpitch);
651         return 0;
652 }
653
654 // DEPRECATED
655 // get_entity_name(self)
656 int ObjectRef::l_get_entity_name(lua_State *L)
657 {
658         NO_MAP_LOCK_REQUIRED;
659         ObjectRef *ref = checkobject(L, 1);
660         LuaEntitySAO *co = getluaobject(ref);
661         log_deprecated(L,"Deprecated call to \"get_entity_name");
662         if(co == NULL) return 0;
663         // Do it
664         std::string name = co->getName();
665         lua_pushstring(L, name.c_str());
666         return 1;
667 }
668
669 // get_luaentity(self)
670 int ObjectRef::l_get_luaentity(lua_State *L)
671 {
672         NO_MAP_LOCK_REQUIRED;
673         ObjectRef *ref = checkobject(L, 1);
674         LuaEntitySAO *co = getluaobject(ref);
675         if(co == NULL) return 0;
676         // Do it
677         luaentity_get(L, co->getId());
678         return 1;
679 }
680
681 /* Player-only */
682
683 // is_player(self)
684 int ObjectRef::l_is_player(lua_State *L)
685 {
686         NO_MAP_LOCK_REQUIRED;
687         ObjectRef *ref = checkobject(L, 1);
688         Player *player = getplayer(ref);
689         lua_pushboolean(L, (player != NULL));
690         return 1;
691 }
692
693 // is_player_connected(self)
694 int ObjectRef::l_is_player_connected(lua_State *L)
695 {
696         NO_MAP_LOCK_REQUIRED;
697         ObjectRef *ref = checkobject(L, 1);
698         Player *player = getplayer(ref);
699         lua_pushboolean(L, (player != NULL && player->peer_id != 0));
700         return 1;
701 }
702
703 // get_player_name(self)
704 int ObjectRef::l_get_player_name(lua_State *L)
705 {
706         NO_MAP_LOCK_REQUIRED;
707         ObjectRef *ref = checkobject(L, 1);
708         Player *player = getplayer(ref);
709         if(player == NULL){
710                 lua_pushlstring(L, "", 0);
711                 return 1;
712         }
713         // Do it
714         lua_pushstring(L, player->getName());
715         return 1;
716 }
717
718 // get_look_dir(self)
719 int ObjectRef::l_get_look_dir(lua_State *L)
720 {
721         NO_MAP_LOCK_REQUIRED;
722         ObjectRef *ref = checkobject(L, 1);
723         Player *player = getplayer(ref);
724         if(player == NULL) return 0;
725         // Do it
726         float pitch = player->getRadPitch();
727         float yaw = player->getRadYaw();
728         v3f v(cos(pitch)*cos(yaw), sin(pitch), cos(pitch)*sin(yaw));
729         push_v3f(L, v);
730         return 1;
731 }
732
733 // get_look_pitch(self)
734 int ObjectRef::l_get_look_pitch(lua_State *L)
735 {
736         NO_MAP_LOCK_REQUIRED;
737         ObjectRef *ref = checkobject(L, 1);
738         Player *player = getplayer(ref);
739         if(player == NULL) return 0;
740         // Do it
741         lua_pushnumber(L, player->getRadPitch());
742         return 1;
743 }
744
745 // get_look_yaw(self)
746 int ObjectRef::l_get_look_yaw(lua_State *L)
747 {
748         NO_MAP_LOCK_REQUIRED;
749         ObjectRef *ref = checkobject(L, 1);
750         Player *player = getplayer(ref);
751         if(player == NULL) return 0;
752         // Do it
753         lua_pushnumber(L, player->getRadYaw());
754         return 1;
755 }
756
757 // set_look_pitch(self, radians)
758 int ObjectRef::l_set_look_pitch(lua_State *L)
759 {
760         NO_MAP_LOCK_REQUIRED;
761         ObjectRef *ref = checkobject(L, 1);
762         PlayerSAO* co = getplayersao(ref);
763         if(co == NULL) return 0;
764         float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
765         // Do it
766         co->setPitch(pitch);
767         return 1;
768 }
769
770 // set_look_yaw(self, radians)
771 int ObjectRef::l_set_look_yaw(lua_State *L)
772 {
773         NO_MAP_LOCK_REQUIRED;
774         ObjectRef *ref = checkobject(L, 1);
775         PlayerSAO* co = getplayersao(ref);
776         if(co == NULL) return 0;
777         float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
778         // Do it
779         co->setYaw(yaw);
780         return 1;
781 }
782
783 // set_breath(self, breath)
784 int ObjectRef::l_set_breath(lua_State *L)
785 {
786         NO_MAP_LOCK_REQUIRED;
787         ObjectRef *ref = checkobject(L, 1);
788         PlayerSAO* co = getplayersao(ref);
789         if(co == NULL) return 0;
790         u16 breath = luaL_checknumber(L, 2);
791         // Do it
792         co->setBreath(breath);
793         co->m_breath_not_sent = true;
794         return 0;
795 }
796
797 // get_breath(self)
798 int ObjectRef::l_get_breath(lua_State *L)
799 {
800         NO_MAP_LOCK_REQUIRED;
801         ObjectRef *ref = checkobject(L, 1);
802         PlayerSAO* co = getplayersao(ref);
803         if(co == NULL) return 0;
804         // Do it
805         u16 breath = co->getBreath();
806         lua_pushinteger (L, breath);
807         return 1;
808 }
809
810 // set_inventory_formspec(self, formspec)
811 int ObjectRef::l_set_inventory_formspec(lua_State *L)
812 {
813         NO_MAP_LOCK_REQUIRED;
814         ObjectRef *ref = checkobject(L, 1);
815         Player *player = getplayer(ref);
816         if(player == NULL) return 0;
817         std::string formspec = luaL_checkstring(L, 2);
818
819         player->inventory_formspec = formspec;
820         getServer(L)->reportInventoryFormspecModified(player->getName());
821         lua_pushboolean(L, true);
822         return 1;
823 }
824
825 // get_inventory_formspec(self) -> formspec
826 int ObjectRef::l_get_inventory_formspec(lua_State *L)
827 {
828         NO_MAP_LOCK_REQUIRED;
829         ObjectRef *ref = checkobject(L, 1);
830         Player *player = getplayer(ref);
831         if(player == NULL) return 0;
832
833         std::string formspec = player->inventory_formspec;
834         lua_pushlstring(L, formspec.c_str(), formspec.size());
835         return 1;
836 }
837
838 // get_player_control(self)
839 int ObjectRef::l_get_player_control(lua_State *L)
840 {
841         NO_MAP_LOCK_REQUIRED;
842         ObjectRef *ref = checkobject(L, 1);
843         Player *player = getplayer(ref);
844         if(player == NULL){
845                 lua_pushlstring(L, "", 0);
846                 return 1;
847         }
848         // Do it
849         PlayerControl control = player->getPlayerControl();
850         lua_newtable(L);
851         lua_pushboolean(L, control.up);
852         lua_setfield(L, -2, "up");
853         lua_pushboolean(L, control.down);
854         lua_setfield(L, -2, "down");
855         lua_pushboolean(L, control.left);
856         lua_setfield(L, -2, "left");
857         lua_pushboolean(L, control.right);
858         lua_setfield(L, -2, "right");
859         lua_pushboolean(L, control.jump);
860         lua_setfield(L, -2, "jump");
861         lua_pushboolean(L, control.aux1);
862         lua_setfield(L, -2, "aux1");
863         lua_pushboolean(L, control.sneak);
864         lua_setfield(L, -2, "sneak");
865         lua_pushboolean(L, control.LMB);
866         lua_setfield(L, -2, "LMB");
867         lua_pushboolean(L, control.RMB);
868         lua_setfield(L, -2, "RMB");
869         return 1;
870 }
871
872 // get_player_control_bits(self)
873 int ObjectRef::l_get_player_control_bits(lua_State *L)
874 {
875         NO_MAP_LOCK_REQUIRED;
876         ObjectRef *ref = checkobject(L, 1);
877         Player *player = getplayer(ref);
878         if(player == NULL){
879                 lua_pushlstring(L, "", 0);
880                 return 1;
881         }
882         // Do it
883         lua_pushnumber(L, player->keyPressed);
884         return 1;
885 }
886
887 // hud_add(self, form)
888 int ObjectRef::l_hud_add(lua_State *L)
889 {
890         ObjectRef *ref = checkobject(L, 1);
891         Player *player = getplayer(ref);
892         if (player == NULL)
893                 return 0;
894
895         HudElement *elem = new HudElement;
896
897         elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type",
898                                                                 es_HudElementType, HUD_ELEM_TEXT);
899
900         lua_getfield(L, 2, "position");
901         elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
902         lua_pop(L, 1);
903
904         lua_getfield(L, 2, "scale");
905         elem->scale = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
906         lua_pop(L, 1);
907
908         lua_getfield(L, 2, "size");
909         elem->size = lua_istable(L, -1) ? read_v2s32(L, -1) : v2s32();
910         lua_pop(L, 1);
911
912         elem->name   = getstringfield_default(L, 2, "name", "");
913         elem->text   = getstringfield_default(L, 2, "text", "");
914         elem->number = getintfield_default(L, 2, "number", 0);
915         elem->item   = getintfield_default(L, 2, "item", 0);
916         elem->dir    = getintfield_default(L, 2, "direction", 0);
917
918         // Deprecated, only for compatibility's sake
919         if (elem->dir == 0)
920                 elem->dir = getintfield_default(L, 2, "dir", 0);
921
922         lua_getfield(L, 2, "alignment");
923         elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
924         lua_pop(L, 1);
925
926         lua_getfield(L, 2, "offset");
927         elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
928         lua_pop(L, 1);
929
930         lua_getfield(L, 2, "world_pos");
931         elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
932         lua_pop(L, 1);
933
934         /* check for known deprecated element usage */
935         if ((elem->type  == HUD_ELEM_STATBAR) && (elem->size == v2s32())) {
936                 log_deprecated(L,"Deprecated usage of statbar without size!");
937         }
938
939         u32 id = getServer(L)->hudAdd(player, elem);
940         if (id == (u32)-1) {
941                 delete elem;
942                 return 0;
943         }
944
945         lua_pushnumber(L, id);
946         return 1;
947 }
948
949 // hud_remove(self, id)
950 int ObjectRef::l_hud_remove(lua_State *L)
951 {
952         ObjectRef *ref = checkobject(L, 1);
953         Player *player = getplayer(ref);
954         if (player == NULL)
955                 return 0;
956
957         u32 id = -1;
958         if (!lua_isnil(L, 2))
959                 id = lua_tonumber(L, 2);
960
961         if (!getServer(L)->hudRemove(player, id))
962                 return 0;
963
964         lua_pushboolean(L, true);
965         return 1;
966 }
967
968 // hud_change(self, id, stat, data)
969 int ObjectRef::l_hud_change(lua_State *L)
970 {
971         ObjectRef *ref = checkobject(L, 1);
972         Player *player = getplayer(ref);
973         if (player == NULL)
974                 return 0;
975
976         u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1;
977
978         HudElement *e = player->getHud(id);
979         if (!e)
980                 return 0;
981
982         HudElementStat stat = HUD_STAT_NUMBER;
983         if (lua_isstring(L, 3)) {
984                 int statint;
985                 std::string statstr = lua_tostring(L, 3);
986                 stat = string_to_enum(es_HudElementStat, statint, statstr) ?
987                                 (HudElementStat)statint : HUD_STAT_NUMBER;
988         }
989
990         void *value = NULL;
991         switch (stat) {
992                 case HUD_STAT_POS:
993                         e->pos = read_v2f(L, 4);
994                         value = &e->pos;
995                         break;
996                 case HUD_STAT_NAME:
997                         e->name = luaL_checkstring(L, 4);
998                         value = &e->name;
999                         break;
1000                 case HUD_STAT_SCALE:
1001                         e->scale = read_v2f(L, 4);
1002                         value = &e->scale;
1003                         break;
1004                 case HUD_STAT_TEXT:
1005                         e->text = luaL_checkstring(L, 4);
1006                         value = &e->text;
1007                         break;
1008                 case HUD_STAT_NUMBER:
1009                         e->number = luaL_checknumber(L, 4);
1010                         value = &e->number;
1011                         break;
1012                 case HUD_STAT_ITEM:
1013                         e->item = luaL_checknumber(L, 4);
1014                         value = &e->item;
1015                         break;
1016                 case HUD_STAT_DIR:
1017                         e->dir = luaL_checknumber(L, 4);
1018                         value = &e->dir;
1019                         break;
1020                 case HUD_STAT_ALIGN:
1021                         e->align = read_v2f(L, 4);
1022                         value = &e->align;
1023                         break;
1024                 case HUD_STAT_OFFSET:
1025                         e->offset = read_v2f(L, 4);
1026                         value = &e->offset;
1027                         break;
1028                 case HUD_STAT_WORLD_POS:
1029                         e->world_pos = read_v3f(L, 4);
1030                         value = &e->world_pos;
1031                         break;
1032                 case HUD_STAT_SIZE:
1033                         e->size = read_v2s32(L, 4);
1034                         value = &e->size;
1035                         break;
1036         }
1037
1038         getServer(L)->hudChange(player, id, stat, value);
1039
1040         lua_pushboolean(L, true);
1041         return 1;
1042 }
1043
1044 // hud_get(self, id)
1045 int ObjectRef::l_hud_get(lua_State *L)
1046 {
1047         ObjectRef *ref = checkobject(L, 1);
1048         Player *player = getplayer(ref);
1049         if (player == NULL)
1050                 return 0;
1051
1052         u32 id = lua_tonumber(L, -1);
1053
1054         HudElement *e = player->getHud(id);
1055         if (!e)
1056                 return 0;
1057
1058         lua_newtable(L);
1059
1060         lua_pushstring(L, es_HudElementType[(u8)e->type].str);
1061         lua_setfield(L, -2, "type");
1062
1063         push_v2f(L, e->pos);
1064         lua_setfield(L, -2, "position");
1065
1066         lua_pushstring(L, e->name.c_str());
1067         lua_setfield(L, -2, "name");
1068
1069         push_v2f(L, e->scale);
1070         lua_setfield(L, -2, "scale");
1071
1072         lua_pushstring(L, e->text.c_str());
1073         lua_setfield(L, -2, "text");
1074
1075         lua_pushnumber(L, e->number);
1076         lua_setfield(L, -2, "number");
1077
1078         lua_pushnumber(L, e->item);
1079         lua_setfield(L, -2, "item");
1080
1081         lua_pushnumber(L, e->dir);
1082         lua_setfield(L, -2, "direction");
1083
1084         // Deprecated, only for compatibility's sake
1085         lua_pushnumber(L, e->dir);
1086         lua_setfield(L, -2, "dir");
1087
1088         push_v3f(L, e->world_pos);
1089         lua_setfield(L, -2, "world_pos");
1090
1091         return 1;
1092 }
1093
1094 // hud_set_flags(self, flags)
1095 int ObjectRef::l_hud_set_flags(lua_State *L)
1096 {
1097         ObjectRef *ref = checkobject(L, 1);
1098         Player *player = getplayer(ref);
1099         if (player == NULL)
1100                 return 0;
1101
1102         u32 flags = 0;
1103         u32 mask  = 0;
1104         bool flag;
1105
1106         const EnumString *esp = es_HudBuiltinElement;
1107         for (int i = 0; esp[i].str; i++) {
1108                 if (getboolfield(L, 2, esp[i].str, flag)) {
1109                         flags |= esp[i].num * flag;
1110                         mask  |= esp[i].num;
1111                 }
1112         }
1113         if (!getServer(L)->hudSetFlags(player, flags, mask))
1114                 return 0;
1115
1116         lua_pushboolean(L, true);
1117         return 1;
1118 }
1119
1120 int ObjectRef::l_hud_get_flags(lua_State *L)
1121 {
1122         ObjectRef *ref = checkobject(L, 1);
1123         Player *player = getplayer(ref);
1124         if (player == NULL)
1125                 return 0;
1126
1127         lua_newtable(L);
1128         lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
1129         lua_setfield(L, -2, "hotbar");
1130         lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
1131         lua_setfield(L, -2, "healthbar");
1132         lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
1133         lua_setfield(L, -2, "crosshair");
1134         lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
1135         lua_setfield(L, -2, "wielditem");
1136         lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
1137         lua_setfield(L, -2, "breathbar");
1138
1139         return 1;
1140 }
1141
1142 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
1143 int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
1144 {
1145         ObjectRef *ref = checkobject(L, 1);
1146         Player *player = getplayer(ref);
1147         if (player == NULL)
1148                 return 0;
1149
1150         s32 hotbar_itemcount = lua_tonumber(L, 2);
1151
1152         if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
1153                 return 0;
1154
1155         lua_pushboolean(L, true);
1156         return 1;
1157 }
1158
1159 // hud_set_hotbar_image(self, name)
1160 int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
1161 {
1162         ObjectRef *ref = checkobject(L, 1);
1163         Player *player = getplayer(ref);
1164         if (player == NULL)
1165                 return 0;
1166
1167         std::string name = lua_tostring(L, 2);
1168
1169         getServer(L)->hudSetHotbarImage(player, name);
1170         return 1;
1171 }
1172
1173 // hud_set_hotbar_selected_image(self, name)
1174 int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
1175 {
1176         ObjectRef *ref = checkobject(L, 1);
1177         Player *player = getplayer(ref);
1178         if (player == NULL)
1179                 return 0;
1180
1181         std::string name = lua_tostring(L, 2);
1182
1183         getServer(L)->hudSetHotbarSelectedImage(player, name);
1184         return 1;
1185 }
1186
1187 // set_sky(self, bgcolor, type, list)
1188 int ObjectRef::l_set_sky(lua_State *L)
1189 {
1190         ObjectRef *ref = checkobject(L, 1);
1191         Player *player = getplayer(ref);
1192         if (player == NULL)
1193                 return 0;
1194
1195         video::SColor bgcolor(255,255,255,255);
1196         if (!lua_isnil(L, 2))
1197                 bgcolor = readARGB8(L, 2);
1198
1199         std::string type = luaL_checkstring(L, 3);
1200
1201         std::vector<std::string> params;
1202         if (lua_istable(L, 4)) {
1203                 int table = lua_gettop(L);
1204                 lua_pushnil(L);
1205                 while (lua_next(L, table) != 0) {
1206                         // key at index -2 and value at index -1
1207                         if (lua_isstring(L, -1))
1208                                 params.push_back(lua_tostring(L, -1));
1209                         else
1210                                 params.push_back("");
1211                         // removes value, keeps key for next iteration
1212                         lua_pop(L, 1);
1213                 }
1214         }
1215
1216         if (type == "skybox" && params.size() != 6)
1217                 throw LuaError("skybox expects 6 textures");
1218
1219         if (!getServer(L)->setSky(player, bgcolor, type, params))
1220                 return 0;
1221
1222         lua_pushboolean(L, true);
1223         return 1;
1224 }
1225
1226 // override_day_night_ratio(self, brightness=0...1)
1227 int ObjectRef::l_override_day_night_ratio(lua_State *L)
1228 {
1229         ObjectRef *ref = checkobject(L, 1);
1230         Player *player = getplayer(ref);
1231         if (player == NULL)
1232                 return 0;
1233
1234         bool do_override = false;
1235         float ratio = 0.0f;
1236         if (!lua_isnil(L, 2)){
1237                 do_override = true;
1238                 ratio = luaL_checknumber(L, 2);
1239         }
1240
1241         if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio))
1242                 return 0;
1243
1244         lua_pushboolean(L, true);
1245         return 1;
1246 }
1247
1248 ObjectRef::ObjectRef(ServerActiveObject *object):
1249         m_object(object)
1250 {
1251         //infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl;
1252 }
1253
1254 ObjectRef::~ObjectRef()
1255 {
1256         /*if(m_object)
1257                 infostream<<"ObjectRef destructing for id="
1258                                 <<m_object->getId()<<std::endl;
1259         else
1260                 infostream<<"ObjectRef destructing for id=unknown"<<std::endl;*/
1261 }
1262
1263 // Creates an ObjectRef and leaves it on top of stack
1264 // Not callable from Lua; all references are created on the C side.
1265 void ObjectRef::create(lua_State *L, ServerActiveObject *object)
1266 {
1267         ObjectRef *o = new ObjectRef(object);
1268         //infostream<<"ObjectRef::create: o="<<o<<std::endl;
1269         *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
1270         luaL_getmetatable(L, className);
1271         lua_setmetatable(L, -2);
1272 }
1273
1274 void ObjectRef::set_null(lua_State *L)
1275 {
1276         ObjectRef *o = checkobject(L, -1);
1277         o->m_object = NULL;
1278 }
1279
1280 void ObjectRef::Register(lua_State *L)
1281 {
1282         lua_newtable(L);
1283         int methodtable = lua_gettop(L);
1284         luaL_newmetatable(L, className);
1285         int metatable = lua_gettop(L);
1286
1287         lua_pushliteral(L, "__metatable");
1288         lua_pushvalue(L, methodtable);
1289         lua_settable(L, metatable);  // hide metatable from Lua getmetatable()
1290
1291         lua_pushliteral(L, "__index");
1292         lua_pushvalue(L, methodtable);
1293         lua_settable(L, metatable);
1294
1295         lua_pushliteral(L, "__gc");
1296         lua_pushcfunction(L, gc_object);
1297         lua_settable(L, metatable);
1298
1299         lua_pop(L, 1);  // drop metatable
1300
1301         luaL_openlib(L, 0, methods, 0);  // fill methodtable
1302         lua_pop(L, 1);  // drop methodtable
1303
1304         // Cannot be created from Lua
1305         //lua_register(L, className, create_object);
1306 }
1307
1308 const char ObjectRef::className[] = "ObjectRef";
1309 const luaL_reg ObjectRef::methods[] = {
1310         // ServerActiveObject
1311         luamethod(ObjectRef, remove),
1312         luamethod(ObjectRef, getpos),
1313         luamethod(ObjectRef, setpos),
1314         luamethod(ObjectRef, moveto),
1315         luamethod(ObjectRef, punch),
1316         luamethod(ObjectRef, right_click),
1317         luamethod(ObjectRef, set_hp),
1318         luamethod(ObjectRef, get_hp),
1319         luamethod(ObjectRef, get_inventory),
1320         luamethod(ObjectRef, get_wield_list),
1321         luamethod(ObjectRef, get_wield_index),
1322         luamethod(ObjectRef, get_wielded_item),
1323         luamethod(ObjectRef, set_wielded_item),
1324         luamethod(ObjectRef, set_armor_groups),
1325         luamethod(ObjectRef, set_physics_override),
1326         luamethod(ObjectRef, set_animation),
1327         luamethod(ObjectRef, set_bone_position),
1328         luamethod(ObjectRef, set_attach),
1329         luamethod(ObjectRef, set_detach),
1330         luamethod(ObjectRef, set_properties),
1331         // LuaEntitySAO-only
1332         luamethod(ObjectRef, setvelocity),
1333         luamethod(ObjectRef, getvelocity),
1334         luamethod(ObjectRef, setacceleration),
1335         luamethod(ObjectRef, getacceleration),
1336         luamethod(ObjectRef, setyaw),
1337         luamethod(ObjectRef, getyaw),
1338         luamethod(ObjectRef, settexturemod),
1339         luamethod(ObjectRef, setsprite),
1340         luamethod(ObjectRef, get_entity_name),
1341         luamethod(ObjectRef, get_luaentity),
1342         // Player-only
1343         luamethod(ObjectRef, is_player),
1344         luamethod(ObjectRef, is_player_connected),
1345         luamethod(ObjectRef, get_player_name),
1346         luamethod(ObjectRef, get_look_dir),
1347         luamethod(ObjectRef, get_look_pitch),
1348         luamethod(ObjectRef, get_look_yaw),
1349         luamethod(ObjectRef, set_look_yaw),
1350         luamethod(ObjectRef, set_look_pitch),
1351         luamethod(ObjectRef, get_breath),
1352         luamethod(ObjectRef, set_breath),
1353         luamethod(ObjectRef, set_inventory_formspec),
1354         luamethod(ObjectRef, get_inventory_formspec),
1355         luamethod(ObjectRef, get_player_control),
1356         luamethod(ObjectRef, get_player_control_bits),
1357         luamethod(ObjectRef, hud_add),
1358         luamethod(ObjectRef, hud_remove),
1359         luamethod(ObjectRef, hud_change),
1360         luamethod(ObjectRef, hud_get),
1361         luamethod(ObjectRef, hud_set_flags),
1362         luamethod(ObjectRef, hud_get_flags),
1363         luamethod(ObjectRef, hud_set_hotbar_itemcount),
1364         luamethod(ObjectRef, hud_set_hotbar_image),
1365         luamethod(ObjectRef, hud_set_hotbar_selected_image),
1366         luamethod(ObjectRef, set_sky),
1367         luamethod(ObjectRef, override_day_night_ratio),
1368         luamethod(ObjectRef, set_local_animation),
1369         luamethod(ObjectRef, set_eye_offset),
1370         {0,0}
1371 };