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.
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"
28 #include "serverobject.h"
29 #include "content_sao.h"
32 #include "scripting_game.h"
34 #define GET_ENV_PTR ServerEnvironment* env = \
35 dynamic_cast<ServerEnvironment*>(getEnv(L)); \
36 if (env == NULL) return 0
38 struct EnumString es_HudElementType[] =
40 {HUD_ELEM_IMAGE, "image"},
41 {HUD_ELEM_TEXT, "text"},
42 {HUD_ELEM_STATBAR, "statbar"},
43 {HUD_ELEM_INVENTORY, "inventory"},
44 {HUD_ELEM_WAYPOINT, "waypoint"},
48 struct EnumString es_HudElementStat[] =
50 {HUD_STAT_POS, "position"},
51 {HUD_STAT_POS, "pos"}, /* Deprecated, only for compatibility's sake */
52 {HUD_STAT_NAME, "name"},
53 {HUD_STAT_SCALE, "scale"},
54 {HUD_STAT_TEXT, "text"},
55 {HUD_STAT_NUMBER, "number"},
56 {HUD_STAT_ITEM, "item"},
57 {HUD_STAT_DIR, "direction"},
58 {HUD_STAT_ALIGN, "alignment"},
59 {HUD_STAT_OFFSET, "offset"},
60 {HUD_STAT_WORLD_POS, "world_pos"},
64 struct EnumString es_HudBuiltinElement[] =
66 {HUD_FLAG_HOTBAR_VISIBLE, "hotbar"},
67 {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"},
68 {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
69 {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
70 {HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
79 ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
81 luaL_checktype(L, narg, LUA_TUSERDATA);
82 void *ud = luaL_checkudata(L, narg, className);
83 if(!ud) luaL_typerror(L, narg, className);
84 return *(ObjectRef**)ud; // unbox pointer
87 ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
89 ServerActiveObject *co = ref->m_object;
93 LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
95 ServerActiveObject *obj = getobject(ref);
98 if(obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
100 return (LuaEntitySAO*)obj;
103 PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
105 ServerActiveObject *obj = getobject(ref);
108 if(obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
110 return (PlayerSAO*)obj;
113 Player* ObjectRef::getplayer(ObjectRef *ref)
115 PlayerSAO *playersao = getplayersao(ref);
116 if(playersao == NULL)
118 return playersao->getPlayer();
121 // Exported functions
124 int ObjectRef::gc_object(lua_State *L) {
125 ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1));
126 //infostream<<"ObjectRef::gc_object: o="<<o<<std::endl;
132 int ObjectRef::l_remove(lua_State *L)
134 NO_MAP_LOCK_REQUIRED;
135 ObjectRef *ref = checkobject(L, 1);
136 ServerActiveObject *co = getobject(ref);
137 if(co == NULL) return 0;
138 if(co->getType() == ACTIVEOBJECT_TYPE_PLAYER) return 0;
139 verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl;
140 co->m_removed = true;
145 // returns: {x=num, y=num, z=num}
146 int ObjectRef::l_getpos(lua_State *L)
148 NO_MAP_LOCK_REQUIRED;
149 ObjectRef *ref = checkobject(L, 1);
150 ServerActiveObject *co = getobject(ref);
151 if(co == NULL) return 0;
152 v3f pos = co->getBasePosition() / BS;
154 lua_pushnumber(L, pos.X);
155 lua_setfield(L, -2, "x");
156 lua_pushnumber(L, pos.Y);
157 lua_setfield(L, -2, "y");
158 lua_pushnumber(L, pos.Z);
159 lua_setfield(L, -2, "z");
164 int ObjectRef::l_setpos(lua_State *L)
166 NO_MAP_LOCK_REQUIRED;
167 ObjectRef *ref = checkobject(L, 1);
168 //LuaEntitySAO *co = getluaobject(ref);
169 ServerActiveObject *co = getobject(ref);
170 if(co == NULL) return 0;
172 v3f pos = checkFloatPos(L, 2);
178 // moveto(self, pos, continuous=false)
179 int ObjectRef::l_moveto(lua_State *L)
181 NO_MAP_LOCK_REQUIRED;
182 ObjectRef *ref = checkobject(L, 1);
183 //LuaEntitySAO *co = getluaobject(ref);
184 ServerActiveObject *co = getobject(ref);
185 if(co == NULL) return 0;
187 v3f pos = checkFloatPos(L, 2);
189 bool continuous = lua_toboolean(L, 3);
191 co->moveTo(pos, continuous);
195 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
196 int ObjectRef::l_punch(lua_State *L)
198 NO_MAP_LOCK_REQUIRED;
199 ObjectRef *ref = checkobject(L, 1);
200 ObjectRef *puncher_ref = checkobject(L, 2);
201 ServerActiveObject *co = getobject(ref);
202 ServerActiveObject *puncher = getobject(puncher_ref);
203 if(co == NULL) return 0;
204 if(puncher == NULL) return 0;
206 if(lua_type(L, 5) != LUA_TTABLE)
207 dir = co->getBasePosition() - puncher->getBasePosition();
209 dir = read_v3f(L, 5);
210 float time_from_last_punch = 1000000;
211 if(lua_isnumber(L, 3))
212 time_from_last_punch = lua_tonumber(L, 3);
213 ToolCapabilities toolcap = read_tool_capabilities(L, 4);
216 s16 src_original_hp = co->getHP();
217 s16 dst_origin_hp = puncher->getHP();
220 co->punch(dir, &toolcap, puncher, time_from_last_punch);
222 // If the punched is a player, and its HP changed
223 if (src_original_hp != co->getHP() &&
224 co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
225 getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(),
229 // If the puncher is a player, and its HP changed
230 if (dst_origin_hp != puncher->getHP() &&
231 puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
232 getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)puncher)->getPeerID(),
233 puncher->getHP() == 0);
238 // right_click(self, clicker); clicker = an another ObjectRef
239 int ObjectRef::l_right_click(lua_State *L)
241 NO_MAP_LOCK_REQUIRED;
242 ObjectRef *ref = checkobject(L, 1);
243 ObjectRef *ref2 = checkobject(L, 2);
244 ServerActiveObject *co = getobject(ref);
245 ServerActiveObject *co2 = getobject(ref2);
246 if(co == NULL) return 0;
247 if(co2 == NULL) return 0;
254 // hp = number of hitpoints (2 * number of hearts)
256 int ObjectRef::l_set_hp(lua_State *L)
258 NO_MAP_LOCK_REQUIRED;
259 ObjectRef *ref = checkobject(L, 1);
260 luaL_checknumber(L, 2);
261 ServerActiveObject *co = getobject(ref);
262 if(co == NULL) return 0;
263 int hp = lua_tonumber(L, 2);
264 /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId()
265 <<" hp="<<hp<<std::endl;*/
268 if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
269 getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), co->getHP() == 0);
276 // returns: number of hitpoints (2 * number of hearts)
277 // 0 if not applicable to this type of object
278 int ObjectRef::l_get_hp(lua_State *L)
280 NO_MAP_LOCK_REQUIRED;
281 ObjectRef *ref = checkobject(L, 1);
282 ServerActiveObject *co = getobject(ref);
285 lua_pushnumber(L, 1);
288 int hp = co->getHP();
289 /*infostream<<"ObjectRef::l_get_hp(): id="<<co->getId()
290 <<" hp="<<hp<<std::endl;*/
292 lua_pushnumber(L, hp);
296 // get_inventory(self)
297 int ObjectRef::l_get_inventory(lua_State *L)
299 NO_MAP_LOCK_REQUIRED;
300 ObjectRef *ref = checkobject(L, 1);
301 ServerActiveObject *co = getobject(ref);
302 if(co == NULL) return 0;
304 InventoryLocation loc = co->getInventoryLocation();
305 if(getServer(L)->getInventory(loc) != NULL)
306 InvRef::create(L, loc);
308 lua_pushnil(L); // An object may have no inventory (nil)
312 // get_wield_list(self)
313 int ObjectRef::l_get_wield_list(lua_State *L)
315 NO_MAP_LOCK_REQUIRED;
316 ObjectRef *ref = checkobject(L, 1);
317 ServerActiveObject *co = getobject(ref);
318 if(co == NULL) return 0;
320 lua_pushstring(L, co->getWieldList().c_str());
324 // get_wield_index(self)
325 int ObjectRef::l_get_wield_index(lua_State *L)
327 NO_MAP_LOCK_REQUIRED;
328 ObjectRef *ref = checkobject(L, 1);
329 ServerActiveObject *co = getobject(ref);
330 if(co == NULL) return 0;
332 lua_pushinteger(L, co->getWieldIndex() + 1);
336 // get_wielded_item(self)
337 int ObjectRef::l_get_wielded_item(lua_State *L)
339 NO_MAP_LOCK_REQUIRED;
340 ObjectRef *ref = checkobject(L, 1);
341 ServerActiveObject *co = getobject(ref);
344 LuaItemStack::create(L, ItemStack());
348 LuaItemStack::create(L, co->getWieldedItem());
352 // set_wielded_item(self, itemstack or itemstring or table or nil)
353 int ObjectRef::l_set_wielded_item(lua_State *L)
355 NO_MAP_LOCK_REQUIRED;
356 ObjectRef *ref = checkobject(L, 1);
357 ServerActiveObject *co = getobject(ref);
358 if(co == NULL) return 0;
360 ItemStack item = read_item(L, 2, getServer(L));
361 bool success = co->setWieldedItem(item);
362 if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
363 getServer(L)->SendInventory(((PlayerSAO*)co));
365 lua_pushboolean(L, success);
369 // set_armor_groups(self, groups)
370 int ObjectRef::l_set_armor_groups(lua_State *L)
372 NO_MAP_LOCK_REQUIRED;
373 ObjectRef *ref = checkobject(L, 1);
374 ServerActiveObject *co = getobject(ref);
375 if(co == NULL) return 0;
377 ItemGroupList groups;
378 read_groups(L, 2, groups);
379 co->setArmorGroups(groups);
383 // get_armor_groups(self)
384 int ObjectRef::l_get_armor_groups(lua_State *L)
386 NO_MAP_LOCK_REQUIRED;
387 ObjectRef *ref = checkobject(L, 1);
388 ServerActiveObject *co = getobject(ref);
392 ItemGroupList groups = co->getArmorGroups();
393 push_groups(L, groups);
397 // set_physics_override(self, physics_override_speed, physics_override_jump,
398 // physics_override_gravity, sneak, sneak_glitch)
399 int ObjectRef::l_set_physics_override(lua_State *L)
401 ObjectRef *ref = checkobject(L, 1);
402 PlayerSAO *co = (PlayerSAO *) getobject(ref);
403 if(co == NULL) return 0;
405 if (lua_istable(L, 2)) {
406 co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
407 co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
408 co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
409 co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
410 co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
411 co->m_physics_override_sent = false;
413 // old, non-table format
414 if(!lua_isnil(L, 2)){
415 co->m_physics_override_speed = lua_tonumber(L, 2);
416 co->m_physics_override_sent = false;
418 if(!lua_isnil(L, 3)){
419 co->m_physics_override_jump = lua_tonumber(L, 3);
420 co->m_physics_override_sent = false;
422 if(!lua_isnil(L, 4)){
423 co->m_physics_override_gravity = lua_tonumber(L, 4);
424 co->m_physics_override_sent = false;
430 // get_physics_override(self)
431 int ObjectRef::l_get_physics_override(lua_State *L)
433 ObjectRef *ref = checkobject(L, 1);
434 PlayerSAO *co = (PlayerSAO *)getobject(ref);
439 lua_pushnumber(L, co->m_physics_override_speed);
440 lua_setfield(L, -2, "speed");
441 lua_pushnumber(L, co->m_physics_override_jump);
442 lua_setfield(L, -2, "jump");
443 lua_pushnumber(L, co->m_physics_override_gravity);
444 lua_setfield(L, -2, "gravity");
445 lua_pushboolean(L, co->m_physics_override_sneak);
446 lua_setfield(L, -2, "sneak");
447 lua_pushboolean(L, co->m_physics_override_sneak_glitch);
448 lua_setfield(L, -2, "sneak_glitch");
452 // set_animation(self, frame_range, frame_speed, frame_blend)
453 int ObjectRef::l_set_animation(lua_State *L)
455 NO_MAP_LOCK_REQUIRED;
456 ObjectRef *ref = checkobject(L, 1);
457 ServerActiveObject *co = getobject(ref);
458 if(co == NULL) return 0;
460 v2f frames = v2f(1, 1);
462 frames = read_v2f(L, 2);
463 float frame_speed = 15;
465 frame_speed = lua_tonumber(L, 3);
466 float frame_blend = 0;
468 frame_blend = lua_tonumber(L, 4);
469 co->setAnimation(frames, frame_speed, frame_blend);
473 // get_animation(self)
474 int ObjectRef::l_get_animation(lua_State *L)
476 NO_MAP_LOCK_REQUIRED;
477 ObjectRef *ref = checkobject(L, 1);
478 ServerActiveObject *co = getobject(ref);
482 v2f frames = v2f(1,1);
483 float frame_speed = 15;
484 float frame_blend = 0;
485 co->getAnimation(&frames, &frame_speed, &frame_blend);
488 lua_pushnumber(L, frame_speed);
489 lua_pushnumber(L, frame_blend);
493 // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
494 int ObjectRef::l_set_local_animation(lua_State *L)
496 //NO_MAP_LOCK_REQUIRED;
497 ObjectRef *ref = checkobject(L, 1);
498 Player *player = getplayer(ref);
503 for (int i=0;i<4;i++) {
504 if(!lua_isnil(L, 2+1))
505 frames[i] = read_v2s32(L, 2+i);
507 float frame_speed = 30;
509 frame_speed = lua_tonumber(L, 6);
511 if (!getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed))
514 lua_pushboolean(L, true);
518 // get_local_animation(self)
519 int ObjectRef::l_get_local_animation(lua_State *L)
521 //NO_MAP_LOCK_REQUIRED
522 ObjectRef *ref = checkobject(L, 1);
523 Player *player = getplayer(ref);
529 player->getLocalAnimations(frames, &frame_speed);
531 for (int i = 0; i < 4; i++) {
532 push_v2s32(L, frames[i]);
535 lua_pushnumber(L, frame_speed);
539 // set_eye_offset(self, v3f first pv, v3f third pv)
540 int ObjectRef::l_set_eye_offset(lua_State *L)
542 //NO_MAP_LOCK_REQUIRED;
543 ObjectRef *ref = checkobject(L, 1);
544 Player *player = getplayer(ref);
548 v3f offset_first = v3f(0, 0, 0);
549 v3f offset_third = v3f(0, 0, 0);
552 offset_first = read_v3f(L, 2);
554 offset_third = read_v3f(L, 3);
556 // Prevent abuse of offset values (keep player always visible)
557 offset_third.X = rangelim(offset_third.X,-10,10);
558 offset_third.Z = rangelim(offset_third.Z,-5,5);
559 /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
560 offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
562 if (!getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third))
565 lua_pushboolean(L, true);
569 // get_eye_offset(self)
570 int ObjectRef::l_get_eye_offset(lua_State *L)
572 //NO_MAP_LOCK_REQUIRED;
573 ObjectRef *ref = checkobject(L, 1);
574 Player *player = getplayer(ref);
578 push_v3f(L, player->eye_offset_first);
579 push_v3f(L, player->eye_offset_third);
583 // set_bone_position(self, std::string bone, v3f position, v3f rotation)
584 int ObjectRef::l_set_bone_position(lua_State *L)
586 NO_MAP_LOCK_REQUIRED;
587 ObjectRef *ref = checkobject(L, 1);
588 ServerActiveObject *co = getobject(ref);
589 if(co == NULL) return 0;
591 std::string bone = "";
593 bone = lua_tostring(L, 2);
594 v3f position = v3f(0, 0, 0);
596 position = read_v3f(L, 3);
597 v3f rotation = v3f(0, 0, 0);
599 rotation = read_v3f(L, 4);
600 co->setBonePosition(bone, position, rotation);
604 // get_bone_position(self, bone)
605 int ObjectRef::l_get_bone_position(lua_State *L)
607 NO_MAP_LOCK_REQUIRED;
608 ObjectRef *ref = checkobject(L, 1);
609 ServerActiveObject *co = getobject(ref);
613 std::string bone = "";
615 bone = lua_tostring(L, 2);
617 v3f position = v3f(0, 0, 0);
618 v3f rotation = v3f(0, 0, 0);
619 co->getBonePosition(bone, &position, &rotation);
621 push_v3f(L, position);
622 push_v3f(L, rotation);
626 // set_attach(self, parent, bone, position, rotation)
627 int ObjectRef::l_set_attach(lua_State *L)
629 NO_MAP_LOCK_REQUIRED;
630 ObjectRef *ref = checkobject(L, 1);
631 ObjectRef *parent_ref = checkobject(L, 2);
632 ServerActiveObject *co = getobject(ref);
633 ServerActiveObject *parent = getobject(parent_ref);
634 if(co == NULL) return 0;
635 if(parent == NULL) return 0;
637 std::string bone = "";
639 bone = lua_tostring(L, 3);
640 v3f position = v3f(0, 0, 0);
642 position = read_v3f(L, 4);
643 v3f rotation = v3f(0, 0, 0);
645 rotation = read_v3f(L, 5);
646 co->setAttachment(parent->getId(), bone, position, rotation);
651 int ObjectRef::l_get_attach(lua_State *L)
653 NO_MAP_LOCK_REQUIRED;
656 ObjectRef *ref = checkobject(L, 1);
657 ServerActiveObject *co = getobject(ref);
663 std::string bone = "";
664 v3f position = v3f(0, 0, 0);
665 v3f rotation = v3f(0, 0, 0);
666 co->getAttachment(&parent_id, &bone, &position, &rotation);
669 ServerActiveObject *parent = env->getActiveObject(parent_id);
671 getScriptApiBase(L)->objectrefGetOrCreate(L, parent);
672 lua_pushlstring(L, bone.c_str(), bone.size());
673 push_v3f(L, position);
674 push_v3f(L, rotation);
679 int ObjectRef::l_set_detach(lua_State *L)
681 NO_MAP_LOCK_REQUIRED;
682 ObjectRef *ref = checkobject(L, 1);
683 ServerActiveObject *co = getobject(ref);
684 if(co == NULL) return 0;
686 co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
690 // set_properties(self, properties)
691 int ObjectRef::l_set_properties(lua_State *L)
693 NO_MAP_LOCK_REQUIRED;
694 ObjectRef *ref = checkobject(L, 1);
695 ServerActiveObject *co = getobject(ref);
696 if(co == NULL) return 0;
697 ObjectProperties *prop = co->accessObjectProperties();
700 read_object_properties(L, 2, prop);
701 co->notifyObjectPropertiesModified();
705 // get_properties(self)
706 int ObjectRef::l_get_properties(lua_State *L)
708 NO_MAP_LOCK_REQUIRED;
709 ObjectRef *ref = checkobject(L, 1);
710 ServerActiveObject *co = getobject(ref);
713 ObjectProperties *prop = co->accessObjectProperties();
716 push_object_properties(L, prop);
721 int ObjectRef::l_is_player(lua_State *L)
723 NO_MAP_LOCK_REQUIRED;
724 ObjectRef *ref = checkobject(L, 1);
725 Player *player = getplayer(ref);
726 lua_pushboolean(L, (player != NULL));
730 /* LuaEntitySAO-only */
732 // setvelocity(self, {x=num, y=num, z=num})
733 int ObjectRef::l_setvelocity(lua_State *L)
735 NO_MAP_LOCK_REQUIRED;
736 ObjectRef *ref = checkobject(L, 1);
737 LuaEntitySAO *co = getluaobject(ref);
738 if(co == NULL) return 0;
739 v3f pos = checkFloatPos(L, 2);
741 co->setVelocity(pos);
746 int ObjectRef::l_getvelocity(lua_State *L)
748 NO_MAP_LOCK_REQUIRED;
749 ObjectRef *ref = checkobject(L, 1);
750 LuaEntitySAO *co = getluaobject(ref);
751 if(co == NULL) return 0;
753 v3f v = co->getVelocity();
758 // setacceleration(self, {x=num, y=num, z=num})
759 int ObjectRef::l_setacceleration(lua_State *L)
761 NO_MAP_LOCK_REQUIRED;
762 ObjectRef *ref = checkobject(L, 1);
763 LuaEntitySAO *co = getluaobject(ref);
764 if(co == NULL) return 0;
766 v3f pos = checkFloatPos(L, 2);
768 co->setAcceleration(pos);
772 // getacceleration(self)
773 int ObjectRef::l_getacceleration(lua_State *L)
775 NO_MAP_LOCK_REQUIRED;
776 ObjectRef *ref = checkobject(L, 1);
777 LuaEntitySAO *co = getluaobject(ref);
778 if(co == NULL) return 0;
780 v3f v = co->getAcceleration();
785 // setyaw(self, radians)
786 int ObjectRef::l_setyaw(lua_State *L)
788 NO_MAP_LOCK_REQUIRED;
789 ObjectRef *ref = checkobject(L, 1);
790 LuaEntitySAO *co = getluaobject(ref);
791 if(co == NULL) return 0;
792 float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
799 int ObjectRef::l_getyaw(lua_State *L)
801 NO_MAP_LOCK_REQUIRED;
802 ObjectRef *ref = checkobject(L, 1);
803 LuaEntitySAO *co = getluaobject(ref);
804 if(co == NULL) return 0;
806 float yaw = co->getYaw() * core::DEGTORAD;
807 lua_pushnumber(L, yaw);
811 // settexturemod(self, mod)
812 int ObjectRef::l_settexturemod(lua_State *L)
814 NO_MAP_LOCK_REQUIRED;
815 ObjectRef *ref = checkobject(L, 1);
816 LuaEntitySAO *co = getluaobject(ref);
817 if(co == NULL) return 0;
819 std::string mod = luaL_checkstring(L, 2);
820 co->setTextureMod(mod);
824 // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
825 // select_horiz_by_yawpitch=false)
826 int ObjectRef::l_setsprite(lua_State *L)
828 NO_MAP_LOCK_REQUIRED;
829 ObjectRef *ref = checkobject(L, 1);
830 LuaEntitySAO *co = getluaobject(ref);
831 if(co == NULL) return 0;
835 p = read_v2s16(L, 2);
838 num_frames = lua_tonumber(L, 3);
839 float framelength = 0.2;
841 framelength = lua_tonumber(L, 4);
842 bool select_horiz_by_yawpitch = false;
844 select_horiz_by_yawpitch = lua_toboolean(L, 5);
845 co->setSprite(p, num_frames, framelength, select_horiz_by_yawpitch);
850 // get_entity_name(self)
851 int ObjectRef::l_get_entity_name(lua_State *L)
853 NO_MAP_LOCK_REQUIRED;
854 ObjectRef *ref = checkobject(L, 1);
855 LuaEntitySAO *co = getluaobject(ref);
856 log_deprecated(L,"Deprecated call to \"get_entity_name");
857 if(co == NULL) return 0;
859 std::string name = co->getName();
860 lua_pushstring(L, name.c_str());
864 // get_luaentity(self)
865 int ObjectRef::l_get_luaentity(lua_State *L)
867 NO_MAP_LOCK_REQUIRED;
868 ObjectRef *ref = checkobject(L, 1);
869 LuaEntitySAO *co = getluaobject(ref);
870 if(co == NULL) return 0;
872 luaentity_get(L, co->getId());
878 // is_player_connected(self)
879 int ObjectRef::l_is_player_connected(lua_State *L)
881 NO_MAP_LOCK_REQUIRED;
882 ObjectRef *ref = checkobject(L, 1);
883 Player *player = getplayer(ref);
884 lua_pushboolean(L, (player != NULL && player->peer_id != 0));
888 // get_player_name(self)
889 int ObjectRef::l_get_player_name(lua_State *L)
891 NO_MAP_LOCK_REQUIRED;
892 ObjectRef *ref = checkobject(L, 1);
893 Player *player = getplayer(ref);
895 lua_pushlstring(L, "", 0);
899 lua_pushstring(L, player->getName());
903 // get_look_dir(self)
904 int ObjectRef::l_get_look_dir(lua_State *L)
906 NO_MAP_LOCK_REQUIRED;
907 ObjectRef *ref = checkobject(L, 1);
908 Player *player = getplayer(ref);
909 if(player == NULL) return 0;
911 float pitch = player->getRadPitch();
912 float yaw = player->getRadYaw();
913 v3f v(cos(pitch)*cos(yaw), sin(pitch), cos(pitch)*sin(yaw));
918 // get_look_pitch(self)
919 int ObjectRef::l_get_look_pitch(lua_State *L)
921 NO_MAP_LOCK_REQUIRED;
922 ObjectRef *ref = checkobject(L, 1);
923 Player *player = getplayer(ref);
924 if(player == NULL) return 0;
926 lua_pushnumber(L, player->getRadPitch());
930 // get_look_yaw(self)
931 int ObjectRef::l_get_look_yaw(lua_State *L)
933 NO_MAP_LOCK_REQUIRED;
934 ObjectRef *ref = checkobject(L, 1);
935 Player *player = getplayer(ref);
936 if(player == NULL) return 0;
938 lua_pushnumber(L, player->getRadYaw());
942 // set_look_pitch(self, radians)
943 int ObjectRef::l_set_look_pitch(lua_State *L)
945 NO_MAP_LOCK_REQUIRED;
946 ObjectRef *ref = checkobject(L, 1);
947 PlayerSAO* co = getplayersao(ref);
948 if(co == NULL) return 0;
949 float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
955 // set_look_yaw(self, radians)
956 int ObjectRef::l_set_look_yaw(lua_State *L)
958 NO_MAP_LOCK_REQUIRED;
959 ObjectRef *ref = checkobject(L, 1);
960 PlayerSAO* co = getplayersao(ref);
961 if(co == NULL) return 0;
962 float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
968 // set_breath(self, breath)
969 int ObjectRef::l_set_breath(lua_State *L)
971 NO_MAP_LOCK_REQUIRED;
972 ObjectRef *ref = checkobject(L, 1);
973 PlayerSAO* co = getplayersao(ref);
974 if(co == NULL) return 0;
975 u16 breath = luaL_checknumber(L, 2);
977 co->setBreath(breath);
979 // If the object is a player sent the breath to client
980 if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
981 getServer(L)->SendPlayerBreath(((PlayerSAO*)co)->getPeerID());
987 int ObjectRef::l_get_breath(lua_State *L)
989 NO_MAP_LOCK_REQUIRED;
990 ObjectRef *ref = checkobject(L, 1);
991 PlayerSAO* co = getplayersao(ref);
992 if(co == NULL) return 0;
994 u16 breath = co->getBreath();
995 lua_pushinteger (L, breath);
999 // set_inventory_formspec(self, formspec)
1000 int ObjectRef::l_set_inventory_formspec(lua_State *L)
1002 NO_MAP_LOCK_REQUIRED;
1003 ObjectRef *ref = checkobject(L, 1);
1004 Player *player = getplayer(ref);
1005 if(player == NULL) return 0;
1006 std::string formspec = luaL_checkstring(L, 2);
1008 player->inventory_formspec = formspec;
1009 getServer(L)->reportInventoryFormspecModified(player->getName());
1010 lua_pushboolean(L, true);
1014 // get_inventory_formspec(self) -> formspec
1015 int ObjectRef::l_get_inventory_formspec(lua_State *L)
1017 NO_MAP_LOCK_REQUIRED;
1018 ObjectRef *ref = checkobject(L, 1);
1019 Player *player = getplayer(ref);
1020 if(player == NULL) return 0;
1022 std::string formspec = player->inventory_formspec;
1023 lua_pushlstring(L, formspec.c_str(), formspec.size());
1027 // get_player_control(self)
1028 int ObjectRef::l_get_player_control(lua_State *L)
1030 NO_MAP_LOCK_REQUIRED;
1031 ObjectRef *ref = checkobject(L, 1);
1032 Player *player = getplayer(ref);
1034 lua_pushlstring(L, "", 0);
1038 PlayerControl control = player->getPlayerControl();
1040 lua_pushboolean(L, control.up);
1041 lua_setfield(L, -2, "up");
1042 lua_pushboolean(L, control.down);
1043 lua_setfield(L, -2, "down");
1044 lua_pushboolean(L, control.left);
1045 lua_setfield(L, -2, "left");
1046 lua_pushboolean(L, control.right);
1047 lua_setfield(L, -2, "right");
1048 lua_pushboolean(L, control.jump);
1049 lua_setfield(L, -2, "jump");
1050 lua_pushboolean(L, control.aux1);
1051 lua_setfield(L, -2, "aux1");
1052 lua_pushboolean(L, control.sneak);
1053 lua_setfield(L, -2, "sneak");
1054 lua_pushboolean(L, control.LMB);
1055 lua_setfield(L, -2, "LMB");
1056 lua_pushboolean(L, control.RMB);
1057 lua_setfield(L, -2, "RMB");
1061 // get_player_control_bits(self)
1062 int ObjectRef::l_get_player_control_bits(lua_State *L)
1064 NO_MAP_LOCK_REQUIRED;
1065 ObjectRef *ref = checkobject(L, 1);
1066 Player *player = getplayer(ref);
1068 lua_pushlstring(L, "", 0);
1072 lua_pushnumber(L, player->keyPressed);
1076 // hud_add(self, form)
1077 int ObjectRef::l_hud_add(lua_State *L)
1079 ObjectRef *ref = checkobject(L, 1);
1080 Player *player = getplayer(ref);
1084 HudElement *elem = new HudElement;
1086 elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type",
1087 es_HudElementType, HUD_ELEM_TEXT);
1089 lua_getfield(L, 2, "position");
1090 elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
1093 lua_getfield(L, 2, "scale");
1094 elem->scale = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
1097 lua_getfield(L, 2, "size");
1098 elem->size = lua_istable(L, -1) ? read_v2s32(L, -1) : v2s32();
1101 elem->name = getstringfield_default(L, 2, "name", "");
1102 elem->text = getstringfield_default(L, 2, "text", "");
1103 elem->number = getintfield_default(L, 2, "number", 0);
1104 elem->item = getintfield_default(L, 2, "item", 0);
1105 elem->dir = getintfield_default(L, 2, "direction", 0);
1107 // Deprecated, only for compatibility's sake
1109 elem->dir = getintfield_default(L, 2, "dir", 0);
1111 lua_getfield(L, 2, "alignment");
1112 elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
1115 lua_getfield(L, 2, "offset");
1116 elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
1119 lua_getfield(L, 2, "world_pos");
1120 elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
1123 /* check for known deprecated element usage */
1124 if ((elem->type == HUD_ELEM_STATBAR) && (elem->size == v2s32())) {
1125 log_deprecated(L,"Deprecated usage of statbar without size!");
1128 u32 id = getServer(L)->hudAdd(player, elem);
1129 if (id == (u32)-1) {
1134 lua_pushnumber(L, id);
1138 // hud_remove(self, id)
1139 int ObjectRef::l_hud_remove(lua_State *L)
1141 ObjectRef *ref = checkobject(L, 1);
1142 Player *player = getplayer(ref);
1147 if (!lua_isnil(L, 2))
1148 id = lua_tonumber(L, 2);
1150 if (!getServer(L)->hudRemove(player, id))
1153 lua_pushboolean(L, true);
1157 // hud_change(self, id, stat, data)
1158 int ObjectRef::l_hud_change(lua_State *L)
1160 ObjectRef *ref = checkobject(L, 1);
1161 Player *player = getplayer(ref);
1165 u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1;
1167 HudElement *e = player->getHud(id);
1171 HudElementStat stat = HUD_STAT_NUMBER;
1172 if (lua_isstring(L, 3)) {
1174 std::string statstr = lua_tostring(L, 3);
1175 stat = string_to_enum(es_HudElementStat, statint, statstr) ?
1176 (HudElementStat)statint : HUD_STAT_NUMBER;
1182 e->pos = read_v2f(L, 4);
1186 e->name = luaL_checkstring(L, 4);
1189 case HUD_STAT_SCALE:
1190 e->scale = read_v2f(L, 4);
1194 e->text = luaL_checkstring(L, 4);
1197 case HUD_STAT_NUMBER:
1198 e->number = luaL_checknumber(L, 4);
1202 e->item = luaL_checknumber(L, 4);
1206 e->dir = luaL_checknumber(L, 4);
1209 case HUD_STAT_ALIGN:
1210 e->align = read_v2f(L, 4);
1213 case HUD_STAT_OFFSET:
1214 e->offset = read_v2f(L, 4);
1217 case HUD_STAT_WORLD_POS:
1218 e->world_pos = read_v3f(L, 4);
1219 value = &e->world_pos;
1222 e->size = read_v2s32(L, 4);
1227 getServer(L)->hudChange(player, id, stat, value);
1229 lua_pushboolean(L, true);
1233 // hud_get(self, id)
1234 int ObjectRef::l_hud_get(lua_State *L)
1236 ObjectRef *ref = checkobject(L, 1);
1237 Player *player = getplayer(ref);
1241 u32 id = lua_tonumber(L, -1);
1243 HudElement *e = player->getHud(id);
1249 lua_pushstring(L, es_HudElementType[(u8)e->type].str);
1250 lua_setfield(L, -2, "type");
1252 push_v2f(L, e->pos);
1253 lua_setfield(L, -2, "position");
1255 lua_pushstring(L, e->name.c_str());
1256 lua_setfield(L, -2, "name");
1258 push_v2f(L, e->scale);
1259 lua_setfield(L, -2, "scale");
1261 lua_pushstring(L, e->text.c_str());
1262 lua_setfield(L, -2, "text");
1264 lua_pushnumber(L, e->number);
1265 lua_setfield(L, -2, "number");
1267 lua_pushnumber(L, e->item);
1268 lua_setfield(L, -2, "item");
1270 lua_pushnumber(L, e->dir);
1271 lua_setfield(L, -2, "direction");
1273 // Deprecated, only for compatibility's sake
1274 lua_pushnumber(L, e->dir);
1275 lua_setfield(L, -2, "dir");
1277 push_v3f(L, e->world_pos);
1278 lua_setfield(L, -2, "world_pos");
1283 // hud_set_flags(self, flags)
1284 int ObjectRef::l_hud_set_flags(lua_State *L)
1286 ObjectRef *ref = checkobject(L, 1);
1287 Player *player = getplayer(ref);
1295 const EnumString *esp = es_HudBuiltinElement;
1296 for (int i = 0; esp[i].str; i++) {
1297 if (getboolfield(L, 2, esp[i].str, flag)) {
1298 flags |= esp[i].num * flag;
1302 if (!getServer(L)->hudSetFlags(player, flags, mask))
1305 lua_pushboolean(L, true);
1309 int ObjectRef::l_hud_get_flags(lua_State *L)
1311 ObjectRef *ref = checkobject(L, 1);
1312 Player *player = getplayer(ref);
1317 lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
1318 lua_setfield(L, -2, "hotbar");
1319 lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
1320 lua_setfield(L, -2, "healthbar");
1321 lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
1322 lua_setfield(L, -2, "crosshair");
1323 lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
1324 lua_setfield(L, -2, "wielditem");
1325 lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
1326 lua_setfield(L, -2, "breathbar");
1331 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
1332 int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
1334 ObjectRef *ref = checkobject(L, 1);
1335 Player *player = getplayer(ref);
1339 s32 hotbar_itemcount = lua_tonumber(L, 2);
1341 if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
1344 lua_pushboolean(L, true);
1348 // hud_get_hotbar_itemcount(self)
1349 int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
1351 ObjectRef *ref = checkobject(L, 1);
1352 Player *player = getplayer(ref);
1356 s32 hotbar_itemcount = getServer(L)->hudGetHotbarItemcount(player);
1358 lua_pushnumber(L, hotbar_itemcount);
1362 // hud_set_hotbar_image(self, name)
1363 int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
1365 ObjectRef *ref = checkobject(L, 1);
1366 Player *player = getplayer(ref);
1370 std::string name = lua_tostring(L, 2);
1372 getServer(L)->hudSetHotbarImage(player, name);
1376 // hud_get_hotbar_image(self)
1377 int ObjectRef::l_hud_get_hotbar_image(lua_State *L)
1379 ObjectRef *ref = checkobject(L, 1);
1380 Player *player = getplayer(ref);
1384 std::string name = getServer(L)->hudGetHotbarImage(player);
1385 lua_pushlstring(L, name.c_str(), name.size());
1389 // hud_set_hotbar_selected_image(self, name)
1390 int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
1392 ObjectRef *ref = checkobject(L, 1);
1393 Player *player = getplayer(ref);
1397 std::string name = lua_tostring(L, 2);
1399 getServer(L)->hudSetHotbarSelectedImage(player, name);
1403 // hud_get_hotbar_selected_image(self)
1404 int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
1406 ObjectRef *ref = checkobject(L, 1);
1407 Player *player = getplayer(ref);
1411 std::string name = getServer(L)->hudGetHotbarSelectedImage(player);
1412 lua_pushlstring(L, name.c_str(), name.size());
1416 // set_sky(self, bgcolor, type, list)
1417 int ObjectRef::l_set_sky(lua_State *L)
1419 ObjectRef *ref = checkobject(L, 1);
1420 Player *player = getplayer(ref);
1424 video::SColor bgcolor(255,255,255,255);
1425 read_color(L, 2, &bgcolor);
1427 std::string type = luaL_checkstring(L, 3);
1429 std::vector<std::string> params;
1430 if (lua_istable(L, 4)) {
1431 int table = lua_gettop(L);
1433 while (lua_next(L, table) != 0) {
1434 // key at index -2 and value at index -1
1435 if (lua_isstring(L, -1))
1436 params.push_back(lua_tostring(L, -1));
1438 params.push_back("");
1439 // removes value, keeps key for next iteration
1444 if (type == "skybox" && params.size() != 6)
1445 throw LuaError("skybox expects 6 textures");
1447 if (!getServer(L)->setSky(player, bgcolor, type, params))
1450 lua_pushboolean(L, true);
1455 int ObjectRef::l_get_sky(lua_State *L)
1457 ObjectRef *ref = checkobject(L, 1);
1458 Player *player = getplayer(ref);
1461 video::SColor bgcolor(255, 255, 255, 255);
1463 std::vector<std::string> params;
1465 player->getSky(&bgcolor, &type, ¶ms);
1466 type = type == "" ? "regular" : type;
1468 push_ARGB8(L, bgcolor);
1469 lua_pushlstring(L, type.c_str(), type.size());
1472 for (std::vector<std::string>::iterator it = params.begin();
1473 it != params.end(); ++it) {
1474 lua_pushlstring(L, it->c_str(), it->size());
1475 lua_rawseti(L, -2, i);
1481 // override_day_night_ratio(self, brightness=0...1)
1482 int ObjectRef::l_override_day_night_ratio(lua_State *L)
1484 ObjectRef *ref = checkobject(L, 1);
1485 Player *player = getplayer(ref);
1489 bool do_override = false;
1491 if (!lua_isnil(L, 2)){
1493 ratio = luaL_checknumber(L, 2);
1496 if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio))
1499 lua_pushboolean(L, true);
1503 // get_day_night_ratio(self)
1504 int ObjectRef::l_get_day_night_ratio(lua_State *L)
1506 ObjectRef *ref = checkobject(L, 1);
1507 Player *player = getplayer(ref);
1513 player->getDayNightRatio(&do_override, &ratio);
1516 lua_pushnumber(L, ratio);
1523 // set_nametag_attributes(self, attributes)
1524 int ObjectRef::l_set_nametag_attributes(lua_State *L)
1526 NO_MAP_LOCK_REQUIRED;
1527 ObjectRef *ref = checkobject(L, 1);
1528 PlayerSAO *playersao = getplayersao(ref);
1529 if (playersao == NULL)
1532 lua_getfield(L, 2, "color");
1533 if (!lua_isnil(L, -1)) {
1534 video::SColor color = playersao->getNametagColor();
1535 if (!read_color(L, -1, &color))
1537 playersao->setNametagColor(color);
1540 lua_pushboolean(L, true);
1544 // get_nametag_attributes(self)
1545 int ObjectRef::l_get_nametag_attributes(lua_State *L)
1547 NO_MAP_LOCK_REQUIRED;
1548 ObjectRef *ref = checkobject(L, 1);
1549 PlayerSAO *playersao = getplayersao(ref);
1550 if (playersao == NULL)
1553 video::SColor color = playersao->getNametagColor();
1556 push_ARGB8(L, color);
1557 lua_setfield(L, -2, "color");
1562 ObjectRef::ObjectRef(ServerActiveObject *object):
1565 //infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl;
1568 ObjectRef::~ObjectRef()
1571 infostream<<"ObjectRef destructing for id="
1572 <<m_object->getId()<<std::endl;
1574 infostream<<"ObjectRef destructing for id=unknown"<<std::endl;*/
1577 // Creates an ObjectRef and leaves it on top of stack
1578 // Not callable from Lua; all references are created on the C side.
1579 void ObjectRef::create(lua_State *L, ServerActiveObject *object)
1581 ObjectRef *o = new ObjectRef(object);
1582 //infostream<<"ObjectRef::create: o="<<o<<std::endl;
1583 *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
1584 luaL_getmetatable(L, className);
1585 lua_setmetatable(L, -2);
1588 void ObjectRef::set_null(lua_State *L)
1590 ObjectRef *o = checkobject(L, -1);
1594 void ObjectRef::Register(lua_State *L)
1597 int methodtable = lua_gettop(L);
1598 luaL_newmetatable(L, className);
1599 int metatable = lua_gettop(L);
1601 lua_pushliteral(L, "__metatable");
1602 lua_pushvalue(L, methodtable);
1603 lua_settable(L, metatable); // hide metatable from Lua getmetatable()
1605 lua_pushliteral(L, "__index");
1606 lua_pushvalue(L, methodtable);
1607 lua_settable(L, metatable);
1609 lua_pushliteral(L, "__gc");
1610 lua_pushcfunction(L, gc_object);
1611 lua_settable(L, metatable);
1613 lua_pop(L, 1); // drop metatable
1615 luaL_openlib(L, 0, methods, 0); // fill methodtable
1616 lua_pop(L, 1); // drop methodtable
1618 // Cannot be created from Lua
1619 //lua_register(L, className, create_object);
1622 const char ObjectRef::className[] = "ObjectRef";
1623 const luaL_reg ObjectRef::methods[] = {
1624 // ServerActiveObject
1625 luamethod(ObjectRef, remove),
1626 luamethod(ObjectRef, getpos),
1627 luamethod(ObjectRef, setpos),
1628 luamethod(ObjectRef, moveto),
1629 luamethod(ObjectRef, punch),
1630 luamethod(ObjectRef, right_click),
1631 luamethod(ObjectRef, set_hp),
1632 luamethod(ObjectRef, get_hp),
1633 luamethod(ObjectRef, get_inventory),
1634 luamethod(ObjectRef, get_wield_list),
1635 luamethod(ObjectRef, get_wield_index),
1636 luamethod(ObjectRef, get_wielded_item),
1637 luamethod(ObjectRef, set_wielded_item),
1638 luamethod(ObjectRef, set_armor_groups),
1639 luamethod(ObjectRef, get_armor_groups),
1640 luamethod(ObjectRef, set_animation),
1641 luamethod(ObjectRef, get_animation),
1642 luamethod(ObjectRef, set_bone_position),
1643 luamethod(ObjectRef, get_bone_position),
1644 luamethod(ObjectRef, set_attach),
1645 luamethod(ObjectRef, get_attach),
1646 luamethod(ObjectRef, set_detach),
1647 luamethod(ObjectRef, set_properties),
1648 luamethod(ObjectRef, get_properties),
1649 // LuaEntitySAO-only
1650 luamethod(ObjectRef, setvelocity),
1651 luamethod(ObjectRef, getvelocity),
1652 luamethod(ObjectRef, setacceleration),
1653 luamethod(ObjectRef, getacceleration),
1654 luamethod(ObjectRef, setyaw),
1655 luamethod(ObjectRef, getyaw),
1656 luamethod(ObjectRef, settexturemod),
1657 luamethod(ObjectRef, setsprite),
1658 luamethod(ObjectRef, get_entity_name),
1659 luamethod(ObjectRef, get_luaentity),
1661 luamethod(ObjectRef, is_player),
1662 luamethod(ObjectRef, is_player_connected),
1663 luamethod(ObjectRef, get_player_name),
1664 luamethod(ObjectRef, get_look_dir),
1665 luamethod(ObjectRef, get_look_pitch),
1666 luamethod(ObjectRef, get_look_yaw),
1667 luamethod(ObjectRef, set_look_yaw),
1668 luamethod(ObjectRef, set_look_pitch),
1669 luamethod(ObjectRef, get_breath),
1670 luamethod(ObjectRef, set_breath),
1671 luamethod(ObjectRef, set_inventory_formspec),
1672 luamethod(ObjectRef, get_inventory_formspec),
1673 luamethod(ObjectRef, get_player_control),
1674 luamethod(ObjectRef, get_player_control_bits),
1675 luamethod(ObjectRef, set_physics_override),
1676 luamethod(ObjectRef, get_physics_override),
1677 luamethod(ObjectRef, hud_add),
1678 luamethod(ObjectRef, hud_remove),
1679 luamethod(ObjectRef, hud_change),
1680 luamethod(ObjectRef, hud_get),
1681 luamethod(ObjectRef, hud_set_flags),
1682 luamethod(ObjectRef, hud_get_flags),
1683 luamethod(ObjectRef, hud_set_hotbar_itemcount),
1684 luamethod(ObjectRef, hud_get_hotbar_itemcount),
1685 luamethod(ObjectRef, hud_set_hotbar_image),
1686 luamethod(ObjectRef, hud_get_hotbar_image),
1687 luamethod(ObjectRef, hud_set_hotbar_selected_image),
1688 luamethod(ObjectRef, hud_get_hotbar_selected_image),
1689 luamethod(ObjectRef, set_sky),
1690 luamethod(ObjectRef, get_sky),
1691 luamethod(ObjectRef, override_day_night_ratio),
1692 luamethod(ObjectRef, get_day_night_ratio),
1693 luamethod(ObjectRef, set_local_animation),
1694 luamethod(ObjectRef, get_local_animation),
1695 luamethod(ObjectRef, set_eye_offset),
1696 luamethod(ObjectRef, get_eye_offset),
1697 luamethod(ObjectRef, set_nametag_attributes),
1698 luamethod(ObjectRef, get_nametag_attributes),