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"
22 #include "lua_api/l_internal.h"
23 #include "lua_api/l_inventory.h"
24 #include "lua_api/l_item.h"
25 #include "lua_api/l_playermeta.h"
26 #include "common/c_converter.h"
27 #include "common/c_content.h"
30 #include "remoteplayer.h"
33 #include "scripting_server.h"
34 #include "server/luaentity_sao.h"
35 #include "server/player_sao.h"
36 #include "server/serverinventorymgr.h"
43 ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
45 luaL_checktype(L, narg, LUA_TUSERDATA);
46 void *ud = luaL_checkudata(L, narg, className);
48 luaL_typerror(L, narg, className);
49 return *(ObjectRef**)ud; // unbox pointer
52 ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
54 ServerActiveObject *sao = ref->m_object;
55 if (sao && sao->isGone())
60 LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
62 ServerActiveObject *sao = getobject(ref);
65 if (sao->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
67 return (LuaEntitySAO*)sao;
70 PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
72 ServerActiveObject *sao = getobject(ref);
75 if (sao->getType() != ACTIVEOBJECT_TYPE_PLAYER)
77 return (PlayerSAO*)sao;
80 RemotePlayer *ObjectRef::getplayer(ObjectRef *ref)
82 PlayerSAO *playersao = getplayersao(ref);
83 if (playersao == nullptr)
85 return playersao->getPlayer();
91 int ObjectRef::gc_object(lua_State *L) {
92 ObjectRef *obj = *(ObjectRef **)(lua_touserdata(L, 1));
98 int ObjectRef::l_remove(lua_State *L)
102 ObjectRef *ref = checkobject(L, 1);
103 ServerActiveObject *sao = getobject(ref);
106 if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
109 sao->clearChildAttachments();
110 sao->clearParentAttachment();
112 verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
113 sao->markForRemoval();
118 int ObjectRef::l_get_pos(lua_State *L)
120 NO_MAP_LOCK_REQUIRED;
121 ObjectRef *ref = checkobject(L, 1);
122 ServerActiveObject *sao = getobject(ref);
126 push_v3f(L, sao->getBasePosition() / BS);
130 // set_pos(self, pos)
131 int ObjectRef::l_set_pos(lua_State *L)
133 NO_MAP_LOCK_REQUIRED;
134 ObjectRef *ref = checkobject(L, 1);
135 ServerActiveObject *sao = getobject(ref);
139 v3f pos = checkFloatPos(L, 2);
145 // move_to(self, pos, continuous)
146 int ObjectRef::l_move_to(lua_State *L)
148 NO_MAP_LOCK_REQUIRED;
149 ObjectRef *ref = checkobject(L, 1);
150 ServerActiveObject *sao = getobject(ref);
154 v3f pos = checkFloatPos(L, 2);
155 bool continuous = readParam<bool>(L, 3);
157 sao->moveTo(pos, continuous);
161 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
162 int ObjectRef::l_punch(lua_State *L)
164 NO_MAP_LOCK_REQUIRED;
165 ObjectRef *ref = checkobject(L, 1);
166 ObjectRef *puncher_ref = checkobject(L, 2);
167 ServerActiveObject *sao = getobject(ref);
168 ServerActiveObject *puncher = getobject(puncher_ref);
169 if (sao == nullptr || puncher == nullptr)
172 float time_from_last_punch = readParam<float>(L, 3, 1000000.0f);
173 ToolCapabilities toolcap = read_tool_capabilities(L, 4);
174 v3f dir = readParam<v3f>(L, 5, sao->getBasePosition() - puncher->getBasePosition());
177 u16 src_original_hp = sao->getHP();
178 u16 dst_origin_hp = puncher->getHP();
180 u16 wear = sao->punch(dir, &toolcap, puncher, time_from_last_punch);
181 lua_pushnumber(L, wear);
183 // If the punched is a player, and its HP changed
184 if (src_original_hp != sao->getHP() &&
185 sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
186 getServer(L)->SendPlayerHPOrDie((PlayerSAO *)sao,
187 PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
190 // If the puncher is a player, and its HP changed
191 if (dst_origin_hp != puncher->getHP() &&
192 puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
193 getServer(L)->SendPlayerHPOrDie((PlayerSAO *)puncher,
194 PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, sao));
199 // right_click(self, clicker)
200 int ObjectRef::l_right_click(lua_State *L)
202 NO_MAP_LOCK_REQUIRED;
203 ObjectRef *ref = checkobject(L, 1);
204 ObjectRef *ref2 = checkobject(L, 2);
205 ServerActiveObject *sao = getobject(ref);
206 ServerActiveObject *sao2 = getobject(ref2);
207 if (sao == nullptr || sao2 == nullptr)
210 sao->rightClick(sao2);
214 // set_hp(self, hp, reason)
215 int ObjectRef::l_set_hp(lua_State *L)
217 NO_MAP_LOCK_REQUIRED;
218 ObjectRef *ref = checkobject(L, 1);
219 ServerActiveObject *sao = getobject(ref);
223 int hp = readParam<float>(L, 2);
224 PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
226 reason.from_mod = true;
227 if (lua_istable(L, 3)) {
230 lua_getfield(L, -1, "type");
231 if (lua_isstring(L, -1) &&
232 !reason.setTypeFromString(readParam<std::string>(L, -1))) {
233 errorstream << "Bad type given!" << std::endl;
237 reason.lua_reference = luaL_ref(L, LUA_REGISTRYINDEX);
240 sao->setHP(hp, reason);
241 if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
242 getServer(L)->SendPlayerHPOrDie((PlayerSAO *)sao, reason);
243 if (reason.hasLuaReference())
244 luaL_unref(L, LUA_REGISTRYINDEX, reason.lua_reference);
249 int ObjectRef::l_get_hp(lua_State *L)
251 NO_MAP_LOCK_REQUIRED;
252 ObjectRef *ref = checkobject(L, 1);
253 ServerActiveObject *sao = getobject(ref);
254 if (sao == nullptr) {
256 lua_pushnumber(L, 1);
260 int hp = sao->getHP();
262 lua_pushnumber(L, hp);
266 // get_inventory(self)
267 int ObjectRef::l_get_inventory(lua_State *L)
269 NO_MAP_LOCK_REQUIRED;
270 ObjectRef *ref = checkobject(L, 1);
271 ServerActiveObject *sao = getobject(ref);
275 InventoryLocation loc = sao->getInventoryLocation();
276 if (getServerInventoryMgr(L)->getInventory(loc) != nullptr)
277 InvRef::create(L, loc);
279 lua_pushnil(L); // An object may have no inventory (nil)
283 // get_wield_list(self)
284 int ObjectRef::l_get_wield_list(lua_State *L)
286 NO_MAP_LOCK_REQUIRED;
287 ObjectRef *ref = checkobject(L, 1);
288 ServerActiveObject *sao = getobject(ref);
292 lua_pushstring(L, sao->getWieldList().c_str());
296 // get_wield_index(self)
297 int ObjectRef::l_get_wield_index(lua_State *L)
299 NO_MAP_LOCK_REQUIRED;
300 ObjectRef *ref = checkobject(L, 1);
301 ServerActiveObject *sao = getobject(ref);
305 lua_pushinteger(L, sao->getWieldIndex() + 1);
309 // get_wielded_item(self)
310 int ObjectRef::l_get_wielded_item(lua_State *L)
312 NO_MAP_LOCK_REQUIRED;
313 ObjectRef *ref = checkobject(L, 1);
314 ServerActiveObject *sao = getobject(ref);
315 if (sao == nullptr) {
317 LuaItemStack::create(L, ItemStack());
321 ItemStack selected_item;
322 sao->getWieldedItem(&selected_item, nullptr);
323 LuaItemStack::create(L, selected_item);
327 // set_wielded_item(self, item)
328 int ObjectRef::l_set_wielded_item(lua_State *L)
330 NO_MAP_LOCK_REQUIRED;
331 ObjectRef *ref = checkobject(L, 1);
332 ServerActiveObject *sao = getobject(ref);
336 ItemStack item = read_item(L, 2, getServer(L)->idef());
338 bool success = sao->setWieldedItem(item);
339 if (success && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
340 getServer(L)->SendInventory((PlayerSAO *)sao, true);
342 lua_pushboolean(L, success);
346 // set_armor_groups(self, groups)
347 int ObjectRef::l_set_armor_groups(lua_State *L)
349 NO_MAP_LOCK_REQUIRED;
350 ObjectRef *ref = checkobject(L, 1);
351 ServerActiveObject *sao = getobject(ref);
355 ItemGroupList groups;
357 read_groups(L, 2, groups);
358 sao->setArmorGroups(groups);
362 // get_armor_groups(self)
363 int ObjectRef::l_get_armor_groups(lua_State *L)
365 NO_MAP_LOCK_REQUIRED;
366 ObjectRef *ref = checkobject(L, 1);
367 ServerActiveObject *sao = getobject(ref);
371 push_groups(L, sao->getArmorGroups());
375 // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
376 int ObjectRef::l_set_animation(lua_State *L)
378 NO_MAP_LOCK_REQUIRED;
379 ObjectRef *ref = checkobject(L, 1);
380 ServerActiveObject *sao = getobject(ref);
384 v2f frame_range = readParam<v2f>(L, 2, v2f(1, 1));
385 float frame_speed = readParam<float>(L, 3, 15.0f);
386 float frame_blend = readParam<float>(L, 4, 0.0f);
387 bool frame_loop = readParam<bool>(L, 5, true);
389 sao->setAnimation(frame_range, frame_speed, frame_blend, frame_loop);
393 // get_animation(self)
394 int ObjectRef::l_get_animation(lua_State *L)
396 NO_MAP_LOCK_REQUIRED;
397 ObjectRef *ref = checkobject(L, 1);
398 ServerActiveObject *sao = getobject(ref);
402 v2f frames = v2f(1,1);
403 float frame_speed = 15;
404 float frame_blend = 0;
405 bool frame_loop = true;
407 sao->getAnimation(&frames, &frame_speed, &frame_blend, &frame_loop);
409 lua_pushnumber(L, frame_speed);
410 lua_pushnumber(L, frame_blend);
411 lua_pushboolean(L, frame_loop);
415 // set_local_animation(self, idle, walk, dig, walk_while_dig, frame_speed)
416 int ObjectRef::l_set_local_animation(lua_State *L)
418 NO_MAP_LOCK_REQUIRED;
419 ObjectRef *ref = checkobject(L, 1);
420 RemotePlayer *player = getplayer(ref);
421 if (player == nullptr)
425 for (int i=0;i<4;i++) {
426 if (!lua_isnil(L, 2+1))
427 frames[i] = read_v2s32(L, 2+i);
429 float frame_speed = readParam<float>(L, 6, 30.0f);
431 getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
432 lua_pushboolean(L, true);
436 // get_local_animation(self)
437 int ObjectRef::l_get_local_animation(lua_State *L)
439 NO_MAP_LOCK_REQUIRED;
440 ObjectRef *ref = checkobject(L, 1);
441 RemotePlayer *player = getplayer(ref);
442 if (player == nullptr)
447 player->getLocalAnimations(frames, &frame_speed);
449 for (const v2s32 &frame : frames) {
450 push_v2s32(L, frame);
453 lua_pushnumber(L, frame_speed);
457 // set_eye_offset(self, firstperson, thirdperson)
458 int ObjectRef::l_set_eye_offset(lua_State *L)
460 NO_MAP_LOCK_REQUIRED;
461 ObjectRef *ref = checkobject(L, 1);
462 RemotePlayer *player = getplayer(ref);
463 if (player == nullptr)
466 v3f offset_first = read_v3f(L, 2);
467 v3f offset_third = read_v3f(L, 3);
469 // Prevent abuse of offset values (keep player always visible)
470 offset_third.X = rangelim(offset_third.X,-10,10);
471 offset_third.Z = rangelim(offset_third.Z,-5,5);
472 /* TODO: if possible: improve the camera collision detection to allow Y <= -1.5) */
473 offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
475 getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
476 lua_pushboolean(L, true);
480 // get_eye_offset(self)
481 int ObjectRef::l_get_eye_offset(lua_State *L)
483 NO_MAP_LOCK_REQUIRED;
484 ObjectRef *ref = checkobject(L, 1);
485 RemotePlayer *player = getplayer(ref);
486 if (player == nullptr)
489 push_v3f(L, player->eye_offset_first);
490 push_v3f(L, player->eye_offset_third);
494 // send_mapblock(self, pos)
495 int ObjectRef::l_send_mapblock(lua_State *L)
497 NO_MAP_LOCK_REQUIRED;
498 ObjectRef *ref = checkobject(L, 1);
499 RemotePlayer *player = getplayer(ref);
500 if (player == nullptr)
503 v3s16 pos = read_v3s16(L, 2);
505 session_t peer_id = player->getPeerId();
506 bool r = getServer(L)->SendBlock(peer_id, pos);
508 lua_pushboolean(L, r);
512 // set_animation_frame_speed(self, frame_speed)
513 int ObjectRef::l_set_animation_frame_speed(lua_State *L)
515 NO_MAP_LOCK_REQUIRED;
516 ObjectRef *ref = checkobject(L, 1);
517 ServerActiveObject *sao = getobject(ref);
521 if (!lua_isnil(L, 2)) {
522 float frame_speed = readParam<float>(L, 2);
523 sao->setAnimationSpeed(frame_speed);
524 lua_pushboolean(L, true);
526 lua_pushboolean(L, false);
531 // set_bone_position(self, bone, position, rotation)
532 int ObjectRef::l_set_bone_position(lua_State *L)
534 NO_MAP_LOCK_REQUIRED;
535 ObjectRef *ref = checkobject(L, 1);
536 ServerActiveObject *sao = getobject(ref);
540 std::string bone = readParam<std::string>(L, 2);
541 v3f position = check_v3f(L, 3);
542 v3f rotation = check_v3f(L, 4);
544 sao->setBonePosition(bone, position, rotation);
548 // get_bone_position(self, bone)
549 int ObjectRef::l_get_bone_position(lua_State *L)
551 NO_MAP_LOCK_REQUIRED;
552 ObjectRef *ref = checkobject(L, 1);
553 ServerActiveObject *sao = getobject(ref);
557 std::string bone = readParam<std::string>(L, 2);
559 v3f position = v3f(0, 0, 0);
560 v3f rotation = v3f(0, 0, 0);
561 sao->getBonePosition(bone, &position, &rotation);
563 push_v3f(L, position);
564 push_v3f(L, rotation);
568 // set_attach(self, parent, bone, position, rotation, force_visible)
569 int ObjectRef::l_set_attach(lua_State *L)
572 ObjectRef *ref = checkobject(L, 1);
573 ObjectRef *parent_ref = checkobject(L, 2);
574 ServerActiveObject *sao = getobject(ref);
575 ServerActiveObject *parent = getobject(parent_ref);
576 if (sao == nullptr || parent == nullptr)
579 throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");
583 v3f position = v3f(0, 0, 0);
584 v3f rotation = v3f(0, 0, 0);
587 sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
589 ServerActiveObject *old_parent = env->getActiveObject(parent_id);
590 old_parent->removeAttachmentChild(sao->getId());
593 bone = readParam<std::string>(L, 3, "");
594 position = read_v3f(L, 4);
595 rotation = read_v3f(L, 5);
596 force_visible = readParam<bool>(L, 6, false);
598 sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
599 parent->addAttachmentChild(sao->getId());
604 int ObjectRef::l_get_attach(lua_State *L)
607 ObjectRef *ref = checkobject(L, 1);
608 ServerActiveObject *sao = getobject(ref);
614 v3f position = v3f(0, 0, 0);
615 v3f rotation = v3f(0, 0, 0);
618 sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
622 ServerActiveObject *parent = env->getActiveObject(parent_id);
623 getScriptApiBase(L)->objectrefGetOrCreate(L, parent);
624 lua_pushlstring(L, bone.c_str(), bone.size());
625 push_v3f(L, position);
626 push_v3f(L, rotation);
627 lua_pushboolean(L, force_visible);
631 // get_children(self)
632 int ObjectRef::l_get_children(lua_State *L)
635 ObjectRef *ref = checkobject(L, 1);
636 ServerActiveObject *sao = getobject(ref);
640 const std::unordered_set<int> child_ids = sao->getAttachmentChildIds();
643 lua_createtable(L, child_ids.size(), 0);
644 for (const int id : child_ids) {
645 ServerActiveObject *child = env->getActiveObject(id);
646 getScriptApiBase(L)->objectrefGetOrCreate(L, child);
647 lua_rawseti(L, -2, ++i);
653 int ObjectRef::l_set_detach(lua_State *L)
656 ObjectRef *ref = checkobject(L, 1);
657 ServerActiveObject *sao = getobject(ref);
661 sao->clearParentAttachment();
665 // set_properties(self, properties)
666 int ObjectRef::l_set_properties(lua_State *L)
668 NO_MAP_LOCK_REQUIRED;
669 ObjectRef *ref = checkobject(L, 1);
670 ServerActiveObject *sao = getobject(ref);
674 ObjectProperties *prop = sao->accessObjectProperties();
678 read_object_properties(L, 2, sao, prop, getServer(L)->idef());
679 sao->notifyObjectPropertiesModified();
683 // get_properties(self)
684 int ObjectRef::l_get_properties(lua_State *L)
686 NO_MAP_LOCK_REQUIRED;
687 ObjectRef *ref = checkobject(L, 1);
688 ServerActiveObject *sao = getobject(ref);
692 ObjectProperties *prop = sao->accessObjectProperties();
696 push_object_properties(L, prop);
701 int ObjectRef::l_is_player(lua_State *L)
703 NO_MAP_LOCK_REQUIRED;
704 ObjectRef *ref = checkobject(L, 1);
705 RemotePlayer *player = getplayer(ref);
706 lua_pushboolean(L, (player != nullptr));
710 // set_nametag_attributes(self, attributes)
711 int ObjectRef::l_set_nametag_attributes(lua_State *L)
713 NO_MAP_LOCK_REQUIRED;
714 ObjectRef *ref = checkobject(L, 1);
715 ServerActiveObject *sao = getobject(ref);
719 ObjectProperties *prop = sao->accessObjectProperties();
723 lua_getfield(L, 2, "color");
724 if (!lua_isnil(L, -1)) {
725 video::SColor color = prop->nametag_color;
726 read_color(L, -1, &color);
727 prop->nametag_color = color;
731 std::string nametag = getstringfield_default(L, 2, "text", "");
732 prop->nametag = nametag;
734 sao->notifyObjectPropertiesModified();
735 lua_pushboolean(L, true);
739 // get_nametag_attributes(self)
740 int ObjectRef::l_get_nametag_attributes(lua_State *L)
742 NO_MAP_LOCK_REQUIRED;
743 ObjectRef *ref = checkobject(L, 1);
744 ServerActiveObject *sao = getobject(ref);
748 ObjectProperties *prop = sao->accessObjectProperties();
752 video::SColor color = prop->nametag_color;
755 push_ARGB8(L, color);
756 lua_setfield(L, -2, "color");
757 lua_pushstring(L, prop->nametag.c_str());
758 lua_setfield(L, -2, "text");
762 /* LuaEntitySAO-only */
764 // set_velocity(self, velocity)
765 int ObjectRef::l_set_velocity(lua_State *L)
767 NO_MAP_LOCK_REQUIRED;
768 ObjectRef *ref = checkobject(L, 1);
769 LuaEntitySAO *sao = getluaobject(ref);
773 v3f vel = checkFloatPos(L, 2);
775 sao->setVelocity(vel);
779 // add_velocity(self, velocity)
780 int ObjectRef::l_add_velocity(lua_State *L)
782 NO_MAP_LOCK_REQUIRED;
783 ObjectRef *ref = checkobject(L, 1);
784 ServerActiveObject *sao = getobject(ref);
788 v3f vel = checkFloatPos(L, 2);
790 if (sao->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
791 LuaEntitySAO *entitysao = dynamic_cast<LuaEntitySAO*>(sao);
792 entitysao->addVelocity(vel);
793 } else if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
794 PlayerSAO *playersao = dynamic_cast<PlayerSAO*>(sao);
795 playersao->setMaxSpeedOverride(vel);
796 getServer(L)->SendPlayerSpeed(playersao->getPeerID(), vel);
802 // get_velocity(self)
803 int ObjectRef::l_get_velocity(lua_State *L)
805 NO_MAP_LOCK_REQUIRED;
806 ObjectRef *ref = checkobject(L, 1);
807 ServerActiveObject *sao = getobject(ref);
811 if (sao->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
812 LuaEntitySAO *entitysao = dynamic_cast<LuaEntitySAO*>(sao);
813 v3f vel = entitysao->getVelocity();
814 pushFloatPos(L, vel);
816 } else if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
817 RemotePlayer *player = dynamic_cast<PlayerSAO*>(sao)->getPlayer();
818 push_v3f(L, player->getSpeed() / BS);
826 // set_acceleration(self, acceleration)
827 int ObjectRef::l_set_acceleration(lua_State *L)
829 NO_MAP_LOCK_REQUIRED;
830 ObjectRef *ref = checkobject(L, 1);
831 LuaEntitySAO *entitysao = getluaobject(ref);
832 if (entitysao == nullptr)
835 v3f acceleration = checkFloatPos(L, 2);
837 entitysao->setAcceleration(acceleration);
841 // get_acceleration(self)
842 int ObjectRef::l_get_acceleration(lua_State *L)
844 NO_MAP_LOCK_REQUIRED;
845 ObjectRef *ref = checkobject(L, 1);
846 LuaEntitySAO *entitysao = getluaobject(ref);
847 if (entitysao == nullptr)
850 v3f acceleration = entitysao->getAcceleration();
851 pushFloatPos(L, acceleration);
855 // set_rotation(self, rotation)
856 int ObjectRef::l_set_rotation(lua_State *L)
858 NO_MAP_LOCK_REQUIRED;
859 ObjectRef *ref = checkobject(L, 1);
860 LuaEntitySAO *entitysao = getluaobject(ref);
861 if (entitysao == nullptr)
864 v3f rotation = check_v3f(L, 2) * core::RADTODEG;
866 entitysao->setRotation(rotation);
870 // get_rotation(self)
871 int ObjectRef::l_get_rotation(lua_State *L)
873 NO_MAP_LOCK_REQUIRED;
874 ObjectRef *ref = checkobject(L, 1);
875 LuaEntitySAO *entitysao = getluaobject(ref);
876 if (entitysao == nullptr)
879 v3f rotation = entitysao->getRotation() * core::DEGTORAD;
882 push_v3f(L, rotation);
886 // set_yaw(self, yaw)
887 int ObjectRef::l_set_yaw(lua_State *L)
889 NO_MAP_LOCK_REQUIRED;
890 ObjectRef *ref = checkobject(L, 1);
891 LuaEntitySAO *entitysao = getluaobject(ref);
892 if (entitysao == nullptr)
896 throw LuaError("ObjectRef::set_yaw: NaN value is not allowed.");
898 float yaw = readParam<float>(L, 2) * core::RADTODEG;
900 entitysao->setRotation(v3f(0, yaw, 0));
905 int ObjectRef::l_get_yaw(lua_State *L)
907 NO_MAP_LOCK_REQUIRED;
908 ObjectRef *ref = checkobject(L, 1);
909 LuaEntitySAO *entitysao = getluaobject(ref);
910 if (entitysao == nullptr)
913 float yaw = entitysao->getRotation().Y * core::DEGTORAD;
915 lua_pushnumber(L, yaw);
919 // set_texture_mod(self, mod)
920 int ObjectRef::l_set_texture_mod(lua_State *L)
922 NO_MAP_LOCK_REQUIRED;
923 ObjectRef *ref = checkobject(L, 1);
924 LuaEntitySAO *entitysao = getluaobject(ref);
925 if (entitysao == nullptr)
928 std::string mod = readParam<std::string>(L, 2);
930 entitysao->setTextureMod(mod);
934 // get_texture_mod(self)
935 int ObjectRef::l_get_texture_mod(lua_State *L)
937 NO_MAP_LOCK_REQUIRED;
938 ObjectRef *ref = checkobject(L, 1);
939 LuaEntitySAO *entitysao = getluaobject(ref);
940 if (entitysao == nullptr)
943 std::string mod = entitysao->getTextureMod();
945 lua_pushstring(L, mod.c_str());
949 // set_sprite(self, start_frame, num_frames, framelength, select_x_by_camera)
950 int ObjectRef::l_set_sprite(lua_State *L)
952 NO_MAP_LOCK_REQUIRED;
953 ObjectRef *ref = checkobject(L, 1);
954 LuaEntitySAO *entitysao = getluaobject(ref);
955 if (entitysao == nullptr)
958 v2s16 start_frame = readParam<v2s16>(L, 2, v2s16(0,0));
959 int num_frames = readParam<int>(L, 3, 1);
960 float framelength = readParam<float>(L, 4, 0.2f);
961 bool select_x_by_camera = readParam<bool>(L, 5, false);
963 entitysao->setSprite(start_frame, num_frames, framelength, select_x_by_camera);
968 // get_entity_name(self)
969 int ObjectRef::l_get_entity_name(lua_State *L)
971 NO_MAP_LOCK_REQUIRED;
972 ObjectRef *ref = checkobject(L, 1);
973 LuaEntitySAO *entitysao = getluaobject(ref);
974 log_deprecated(L,"Deprecated call to \"get_entity_name");
975 if (entitysao == nullptr)
978 std::string name = entitysao->getName();
980 lua_pushstring(L, name.c_str());
984 // get_luaentity(self)
985 int ObjectRef::l_get_luaentity(lua_State *L)
987 NO_MAP_LOCK_REQUIRED;
988 ObjectRef *ref = checkobject(L, 1);
989 LuaEntitySAO *entitysao = getluaobject(ref);
990 if (entitysao == nullptr)
993 luaentity_get(L, entitysao->getId());
999 // get_player_name(self)
1000 int ObjectRef::l_get_player_name(lua_State *L)
1002 NO_MAP_LOCK_REQUIRED;
1003 ObjectRef *ref = checkobject(L, 1);
1004 RemotePlayer *player = getplayer(ref);
1005 if (player == nullptr) {
1006 lua_pushlstring(L, "", 0);
1010 lua_pushstring(L, player->getName());
1014 // get_look_dir(self)
1015 int ObjectRef::l_get_look_dir(lua_State *L)
1017 NO_MAP_LOCK_REQUIRED;
1018 ObjectRef *ref = checkobject(L, 1);
1019 PlayerSAO* playersao = getplayersao(ref);
1020 if (playersao == nullptr)
1023 float pitch = playersao->getRadLookPitchDep();
1024 float yaw = playersao->getRadYawDep();
1025 v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), std::cos(pitch) *
1033 // get_look_pitch(self)
1034 int ObjectRef::l_get_look_pitch(lua_State *L)
1036 NO_MAP_LOCK_REQUIRED;
1039 "Deprecated call to get_look_pitch, use get_look_vertical instead");
1041 ObjectRef *ref = checkobject(L, 1);
1042 PlayerSAO* playersao = getplayersao(ref);
1043 if (playersao == nullptr)
1046 lua_pushnumber(L, playersao->getRadLookPitchDep());
1051 // get_look_yaw(self)
1052 int ObjectRef::l_get_look_yaw(lua_State *L)
1054 NO_MAP_LOCK_REQUIRED;
1057 "Deprecated call to get_look_yaw, use get_look_horizontal instead");
1059 ObjectRef *ref = checkobject(L, 1);
1060 PlayerSAO* playersao = getplayersao(ref);
1061 if (playersao == nullptr)
1064 lua_pushnumber(L, playersao->getRadYawDep());
1068 // get_look_vertical(self)
1069 int ObjectRef::l_get_look_vertical(lua_State *L)
1071 NO_MAP_LOCK_REQUIRED;
1072 ObjectRef *ref = checkobject(L, 1);
1073 PlayerSAO* playersao = getplayersao(ref);
1074 if (playersao == nullptr)
1077 lua_pushnumber(L, playersao->getRadLookPitch());
1081 // get_look_horizontal(self)
1082 int ObjectRef::l_get_look_horizontal(lua_State *L)
1084 NO_MAP_LOCK_REQUIRED;
1085 ObjectRef *ref = checkobject(L, 1);
1086 PlayerSAO* playersao = getplayersao(ref);
1087 if (playersao == nullptr)
1090 lua_pushnumber(L, playersao->getRadRotation().Y);
1094 // set_look_vertical(self, radians)
1095 int ObjectRef::l_set_look_vertical(lua_State *L)
1097 NO_MAP_LOCK_REQUIRED;
1098 ObjectRef *ref = checkobject(L, 1);
1099 PlayerSAO* playersao = getplayersao(ref);
1100 if (playersao == nullptr)
1103 float pitch = readParam<float>(L, 2) * core::RADTODEG;
1105 playersao->setLookPitchAndSend(pitch);
1109 // set_look_horizontal(self, radians)
1110 int ObjectRef::l_set_look_horizontal(lua_State *L)
1112 NO_MAP_LOCK_REQUIRED;
1113 ObjectRef *ref = checkobject(L, 1);
1114 PlayerSAO* playersao = getplayersao(ref);
1115 if (playersao == nullptr)
1118 float yaw = readParam<float>(L, 2) * core::RADTODEG;
1120 playersao->setPlayerYawAndSend(yaw);
1125 // set_look_pitch(self, radians)
1126 int ObjectRef::l_set_look_pitch(lua_State *L)
1128 NO_MAP_LOCK_REQUIRED;
1131 "Deprecated call to set_look_pitch, use set_look_vertical instead.");
1133 ObjectRef *ref = checkobject(L, 1);
1134 PlayerSAO* playersao = getplayersao(ref);
1135 if (playersao == nullptr)
1138 float pitch = readParam<float>(L, 2) * core::RADTODEG;
1140 playersao->setLookPitchAndSend(pitch);
1145 // set_look_yaw(self, radians)
1146 int ObjectRef::l_set_look_yaw(lua_State *L)
1148 NO_MAP_LOCK_REQUIRED;
1151 "Deprecated call to set_look_yaw, use set_look_horizontal instead.");
1153 ObjectRef *ref = checkobject(L, 1);
1154 PlayerSAO* playersao = getplayersao(ref);
1155 if (playersao == nullptr)
1158 float yaw = readParam<float>(L, 2) * core::RADTODEG;
1160 playersao->setPlayerYawAndSend(yaw);
1164 // set_fov(self, degrees, is_multiplier, transition_time)
1165 int ObjectRef::l_set_fov(lua_State *L)
1167 NO_MAP_LOCK_REQUIRED;
1168 ObjectRef *ref = checkobject(L, 1);
1169 RemotePlayer *player = getplayer(ref);
1170 if (player == nullptr)
1173 float degrees = static_cast<f32>(luaL_checknumber(L, 2));
1174 bool is_multiplier = readParam<bool>(L, 3, false);
1175 float transition_time = lua_isnumber(L, 4) ?
1176 static_cast<f32>(luaL_checknumber(L, 4)) : 0.0f;
1178 player->setFov({degrees, is_multiplier, transition_time});
1179 getServer(L)->SendPlayerFov(player->getPeerId());
1184 int ObjectRef::l_get_fov(lua_State *L)
1186 NO_MAP_LOCK_REQUIRED;
1187 ObjectRef *ref = checkobject(L, 1);
1188 RemotePlayer *player = getplayer(ref);
1189 if (player == nullptr)
1192 PlayerFovSpec fov_spec = player->getFov();
1194 lua_pushnumber(L, fov_spec.fov);
1195 lua_pushboolean(L, fov_spec.is_multiplier);
1196 lua_pushnumber(L, fov_spec.transition_time);
1200 // set_breath(self, breath)
1201 int ObjectRef::l_set_breath(lua_State *L)
1203 NO_MAP_LOCK_REQUIRED;
1204 ObjectRef *ref = checkobject(L, 1);
1205 PlayerSAO* playersao = getplayersao(ref);
1206 if (playersao == nullptr)
1209 u16 breath = luaL_checknumber(L, 2);
1211 playersao->setBreath(breath);
1216 int ObjectRef::l_get_breath(lua_State *L)
1218 NO_MAP_LOCK_REQUIRED;
1219 ObjectRef *ref = checkobject(L, 1);
1220 PlayerSAO* playersao = getplayersao(ref);
1221 if (playersao == nullptr)
1224 u16 breath = playersao->getBreath();
1226 lua_pushinteger(L, breath);
1230 // set_attribute(self, attribute, value)
1231 int ObjectRef::l_set_attribute(lua_State *L)
1234 "Deprecated call to set_attribute, use MetaDataRef methods instead.");
1236 ObjectRef *ref = checkobject(L, 1);
1237 PlayerSAO* playersao = getplayersao(ref);
1238 if (playersao == nullptr)
1241 std::string attr = luaL_checkstring(L, 2);
1242 if (lua_isnil(L, 3)) {
1243 playersao->getMeta().removeString(attr);
1245 std::string value = luaL_checkstring(L, 3);
1246 playersao->getMeta().setString(attr, value);
1251 // get_attribute(self, attribute)
1252 int ObjectRef::l_get_attribute(lua_State *L)
1255 "Deprecated call to get_attribute, use MetaDataRef methods instead.");
1257 ObjectRef *ref = checkobject(L, 1);
1258 PlayerSAO* playersao = getplayersao(ref);
1259 if (playersao == nullptr)
1262 std::string attr = luaL_checkstring(L, 2);
1265 if (playersao->getMeta().getStringToRef(attr, value)) {
1266 lua_pushstring(L, value.c_str());
1274 // get_meta(self, attribute)
1275 int ObjectRef::l_get_meta(lua_State *L)
1277 ObjectRef *ref = checkobject(L, 1);
1278 PlayerSAO *playersao = getplayersao(ref);
1279 if (playersao == nullptr)
1282 PlayerMetaRef::create(L, &playersao->getMeta());
1287 // set_inventory_formspec(self, formspec)
1288 int ObjectRef::l_set_inventory_formspec(lua_State *L)
1290 NO_MAP_LOCK_REQUIRED;
1291 ObjectRef *ref = checkobject(L, 1);
1292 RemotePlayer *player = getplayer(ref);
1293 if (player == nullptr)
1296 std::string formspec = luaL_checkstring(L, 2);
1298 player->inventory_formspec = formspec;
1299 getServer(L)->reportInventoryFormspecModified(player->getName());
1300 lua_pushboolean(L, true);
1304 // get_inventory_formspec(self) -> formspec
1305 int ObjectRef::l_get_inventory_formspec(lua_State *L)
1307 NO_MAP_LOCK_REQUIRED;
1308 ObjectRef *ref = checkobject(L, 1);
1309 RemotePlayer *player = getplayer(ref);
1310 if (player == nullptr)
1313 std::string formspec = player->inventory_formspec;
1315 lua_pushlstring(L, formspec.c_str(), formspec.size());
1319 // set_formspec_prepend(self, formspec)
1320 int ObjectRef::l_set_formspec_prepend(lua_State *L)
1322 NO_MAP_LOCK_REQUIRED;
1323 ObjectRef *ref = checkobject(L, 1);
1324 RemotePlayer *player = getplayer(ref);
1325 if (player == nullptr)
1328 std::string formspec = luaL_checkstring(L, 2);
1330 player->formspec_prepend = formspec;
1331 getServer(L)->reportFormspecPrependModified(player->getName());
1332 lua_pushboolean(L, true);
1336 // get_formspec_prepend(self)
1337 int ObjectRef::l_get_formspec_prepend(lua_State *L)
1339 NO_MAP_LOCK_REQUIRED;
1340 ObjectRef *ref = checkobject(L, 1);
1341 RemotePlayer *player = getplayer(ref);
1342 if (player == nullptr)
1345 std::string formspec = player->formspec_prepend;
1347 lua_pushlstring(L, formspec.c_str(), formspec.size());
1351 // get_player_control(self)
1352 int ObjectRef::l_get_player_control(lua_State *L)
1354 NO_MAP_LOCK_REQUIRED;
1355 ObjectRef *ref = checkobject(L, 1);
1356 RemotePlayer *player = getplayer(ref);
1357 if (player == nullptr) {
1358 lua_pushlstring(L, "", 0);
1362 const PlayerControl &control = player->getPlayerControl();
1364 lua_pushboolean(L, control.up);
1365 lua_setfield(L, -2, "up");
1366 lua_pushboolean(L, control.down);
1367 lua_setfield(L, -2, "down");
1368 lua_pushboolean(L, control.left);
1369 lua_setfield(L, -2, "left");
1370 lua_pushboolean(L, control.right);
1371 lua_setfield(L, -2, "right");
1372 lua_pushboolean(L, control.jump);
1373 lua_setfield(L, -2, "jump");
1374 lua_pushboolean(L, control.aux1);
1375 lua_setfield(L, -2, "aux1");
1376 lua_pushboolean(L, control.sneak);
1377 lua_setfield(L, -2, "sneak");
1378 lua_pushboolean(L, control.dig);
1379 lua_setfield(L, -2, "dig");
1380 lua_pushboolean(L, control.place);
1381 lua_setfield(L, -2, "place");
1382 // Legacy fields to ensure mod compatibility
1383 lua_pushboolean(L, control.dig);
1384 lua_setfield(L, -2, "LMB");
1385 lua_pushboolean(L, control.place);
1386 lua_setfield(L, -2, "RMB");
1387 lua_pushboolean(L, control.zoom);
1388 lua_setfield(L, -2, "zoom");
1392 // get_player_control_bits(self)
1393 int ObjectRef::l_get_player_control_bits(lua_State *L)
1395 NO_MAP_LOCK_REQUIRED;
1396 ObjectRef *ref = checkobject(L, 1);
1397 RemotePlayer *player = getplayer(ref);
1398 if (player == nullptr) {
1399 lua_pushlstring(L, "", 0);
1403 lua_pushnumber(L, player->keyPressed);
1407 // set_physics_override(self, override_table)
1408 int ObjectRef::l_set_physics_override(lua_State *L)
1410 NO_MAP_LOCK_REQUIRED;
1411 ObjectRef *ref = checkobject(L, 1);
1412 PlayerSAO *playersao = getplayersao(ref);
1413 if (playersao == nullptr)
1416 if (lua_istable(L, 2)) {
1417 bool modified = false;
1418 modified |= getfloatfield(L, 2, "speed", playersao->m_physics_override_speed);
1419 modified |= getfloatfield(L, 2, "jump", playersao->m_physics_override_jump);
1420 modified |= getfloatfield(L, 2, "gravity", playersao->m_physics_override_gravity);
1421 modified |= getboolfield(L, 2, "sneak", playersao->m_physics_override_sneak);
1422 modified |= getboolfield(L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch);
1423 modified |= getboolfield(L, 2, "new_move", playersao->m_physics_override_new_move);
1425 playersao->m_physics_override_sent = false;
1427 // old, non-table format
1428 // TODO: Remove this code after version 5.4.0
1429 log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)");
1431 if (!lua_isnil(L, 2)) {
1432 playersao->m_physics_override_speed = lua_tonumber(L, 2);
1433 playersao->m_physics_override_sent = false;
1435 if (!lua_isnil(L, 3)) {
1436 playersao->m_physics_override_jump = lua_tonumber(L, 3);
1437 playersao->m_physics_override_sent = false;
1439 if (!lua_isnil(L, 4)) {
1440 playersao->m_physics_override_gravity = lua_tonumber(L, 4);
1441 playersao->m_physics_override_sent = false;
1447 // get_physics_override(self)
1448 int ObjectRef::l_get_physics_override(lua_State *L)
1450 NO_MAP_LOCK_REQUIRED;
1451 ObjectRef *ref = checkobject(L, 1);
1452 PlayerSAO *playersao = getplayersao(ref);
1453 if (playersao == nullptr)
1457 lua_pushnumber(L, playersao->m_physics_override_speed);
1458 lua_setfield(L, -2, "speed");
1459 lua_pushnumber(L, playersao->m_physics_override_jump);
1460 lua_setfield(L, -2, "jump");
1461 lua_pushnumber(L, playersao->m_physics_override_gravity);
1462 lua_setfield(L, -2, "gravity");
1463 lua_pushboolean(L, playersao->m_physics_override_sneak);
1464 lua_setfield(L, -2, "sneak");
1465 lua_pushboolean(L, playersao->m_physics_override_sneak_glitch);
1466 lua_setfield(L, -2, "sneak_glitch");
1467 lua_pushboolean(L, playersao->m_physics_override_new_move);
1468 lua_setfield(L, -2, "new_move");
1472 // hud_add(self, hud)
1473 int ObjectRef::l_hud_add(lua_State *L)
1475 NO_MAP_LOCK_REQUIRED;
1476 ObjectRef *ref = checkobject(L, 1);
1477 RemotePlayer *player = getplayer(ref);
1478 if (player == nullptr)
1481 HudElement *elem = new HudElement;
1482 read_hud_element(L, elem);
1484 u32 id = getServer(L)->hudAdd(player, elem);
1485 if (id == U32_MAX) {
1490 lua_pushnumber(L, id);
1494 // hud_remove(self, id)
1495 int ObjectRef::l_hud_remove(lua_State *L)
1497 NO_MAP_LOCK_REQUIRED;
1498 ObjectRef *ref = checkobject(L, 1);
1499 RemotePlayer *player = getplayer(ref);
1500 if (player == nullptr)
1503 u32 id = luaL_checkint(L, 2);
1505 if (!getServer(L)->hudRemove(player, id))
1508 lua_pushboolean(L, true);
1512 // hud_change(self, id, stat, data)
1513 int ObjectRef::l_hud_change(lua_State *L)
1515 NO_MAP_LOCK_REQUIRED;
1516 ObjectRef *ref = checkobject(L, 1);
1517 RemotePlayer *player = getplayer(ref);
1518 if (player == nullptr)
1521 u32 id = luaL_checkint(L, 2);
1523 HudElement *elem = player->getHud(id);
1524 if (elem == nullptr)
1527 void *value = nullptr;
1528 HudElementStat stat = read_hud_change(L, elem, &value);
1530 getServer(L)->hudChange(player, id, stat, value);
1532 lua_pushboolean(L, true);
1536 // hud_get(self, id)
1537 int ObjectRef::l_hud_get(lua_State *L)
1539 NO_MAP_LOCK_REQUIRED;
1540 ObjectRef *ref = checkobject(L, 1);
1541 RemotePlayer *player = getplayer(ref);
1542 if (player == nullptr)
1545 u32 id = luaL_checkint(L, 2);
1547 HudElement *elem = player->getHud(id);
1548 if (elem == nullptr)
1551 push_hud_element(L, elem);
1555 // hud_set_flags(self, flags)
1556 int ObjectRef::l_hud_set_flags(lua_State *L)
1558 NO_MAP_LOCK_REQUIRED;
1559 ObjectRef *ref = checkobject(L, 1);
1560 RemotePlayer *player = getplayer(ref);
1561 if (player == nullptr)
1568 const EnumString *esp = es_HudBuiltinElement;
1569 for (int i = 0; esp[i].str; i++) {
1570 if (getboolfield(L, 2, esp[i].str, flag)) {
1571 flags |= esp[i].num * flag;
1575 if (!getServer(L)->hudSetFlags(player, flags, mask))
1578 lua_pushboolean(L, true);
1582 // hud_get_flags(self)
1583 int ObjectRef::l_hud_get_flags(lua_State *L)
1585 NO_MAP_LOCK_REQUIRED;
1586 ObjectRef *ref = checkobject(L, 1);
1587 RemotePlayer *player = getplayer(ref);
1588 if (player == nullptr)
1592 lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
1593 lua_setfield(L, -2, "hotbar");
1594 lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
1595 lua_setfield(L, -2, "healthbar");
1596 lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
1597 lua_setfield(L, -2, "crosshair");
1598 lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
1599 lua_setfield(L, -2, "wielditem");
1600 lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
1601 lua_setfield(L, -2, "breathbar");
1602 lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
1603 lua_setfield(L, -2, "minimap");
1604 lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE);
1605 lua_setfield(L, -2, "minimap_radar");
1609 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
1610 int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
1612 NO_MAP_LOCK_REQUIRED;
1613 ObjectRef *ref = checkobject(L, 1);
1614 RemotePlayer *player = getplayer(ref);
1615 if (player == nullptr)
1618 s32 hotbar_itemcount = luaL_checkint(L, 2);
1620 if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
1623 lua_pushboolean(L, true);
1627 // hud_get_hotbar_itemcount(self)
1628 int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
1630 NO_MAP_LOCK_REQUIRED;
1631 ObjectRef *ref = checkobject(L, 1);
1632 RemotePlayer *player = getplayer(ref);
1633 if (player == nullptr)
1636 lua_pushnumber(L, player->getHotbarItemcount());
1640 // hud_set_hotbar_image(self, name)
1641 int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
1643 NO_MAP_LOCK_REQUIRED;
1644 ObjectRef *ref = checkobject(L, 1);
1645 RemotePlayer *player = getplayer(ref);
1646 if (player == nullptr)
1649 std::string name = readParam<std::string>(L, 2);
1651 getServer(L)->hudSetHotbarImage(player, name);
1655 // hud_get_hotbar_image(self)
1656 int ObjectRef::l_hud_get_hotbar_image(lua_State *L)
1658 NO_MAP_LOCK_REQUIRED;
1659 ObjectRef *ref = checkobject(L, 1);
1660 RemotePlayer *player = getplayer(ref);
1661 if (player == nullptr)
1664 const std::string &name = player->getHotbarImage();
1666 lua_pushlstring(L, name.c_str(), name.size());
1670 // hud_set_hotbar_selected_image(self, name)
1671 int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
1673 NO_MAP_LOCK_REQUIRED;
1674 ObjectRef *ref = checkobject(L, 1);
1675 RemotePlayer *player = getplayer(ref);
1676 if (player == nullptr)
1679 std::string name = readParam<std::string>(L, 2);
1681 getServer(L)->hudSetHotbarSelectedImage(player, name);
1685 // hud_get_hotbar_selected_image(self)
1686 int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
1688 NO_MAP_LOCK_REQUIRED;
1689 ObjectRef *ref = checkobject(L, 1);
1690 RemotePlayer *player = getplayer(ref);
1691 if (player == nullptr)
1694 const std::string &name = player->getHotbarSelectedImage();
1696 lua_pushlstring(L, name.c_str(), name.size());
1700 // set_sky(self, sky_parameters)
1701 int ObjectRef::l_set_sky(lua_State *L)
1703 NO_MAP_LOCK_REQUIRED;
1704 ObjectRef *ref = checkobject(L, 1);
1705 RemotePlayer *player = getplayer(ref);
1706 if (player == nullptr)
1709 SkyboxParams sky_params = player->getSkyParams();
1710 bool is_colorspec = is_color_table(L, 2);
1712 if (lua_istable(L, 2) && !is_colorspec) {
1713 lua_getfield(L, 2, "base_color");
1714 if (!lua_isnil(L, -1))
1715 read_color(L, -1, &sky_params.bgcolor);
1718 lua_getfield(L, 2, "type");
1719 if (!lua_isnil(L, -1))
1720 sky_params.type = luaL_checkstring(L, -1);
1723 lua_getfield(L, 2, "textures");
1724 sky_params.textures.clear();
1725 if (lua_istable(L, -1) && sky_params.type == "skybox") {
1727 while (lua_next(L, -2) != 0) {
1728 // Key is at index -2 and value at index -1
1729 sky_params.textures.emplace_back(readParam<std::string>(L, -1));
1730 // Removes the value, but keeps the key for iteration
1737 We want to avoid crashes, so we're checking even if we're not using them.
1738 However, we want to ensure that the skybox can be set to nil when
1739 using "regular" or "plain" skybox modes as textures aren't needed.
1742 if (sky_params.textures.size() != 6 && sky_params.textures.size() > 0)
1743 throw LuaError("Skybox expects 6 textures!");
1745 sky_params.clouds = getboolfield_default(L, 2,
1746 "clouds", sky_params.clouds);
1748 lua_getfield(L, 2, "sky_color");
1749 if (lua_istable(L, -1)) {
1750 lua_getfield(L, -1, "day_sky");
1751 read_color(L, -1, &sky_params.sky_color.day_sky);
1754 lua_getfield(L, -1, "day_horizon");
1755 read_color(L, -1, &sky_params.sky_color.day_horizon);
1758 lua_getfield(L, -1, "dawn_sky");
1759 read_color(L, -1, &sky_params.sky_color.dawn_sky);
1762 lua_getfield(L, -1, "dawn_horizon");
1763 read_color(L, -1, &sky_params.sky_color.dawn_horizon);
1766 lua_getfield(L, -1, "night_sky");
1767 read_color(L, -1, &sky_params.sky_color.night_sky);
1770 lua_getfield(L, -1, "night_horizon");
1771 read_color(L, -1, &sky_params.sky_color.night_horizon);
1774 lua_getfield(L, -1, "indoors");
1775 read_color(L, -1, &sky_params.sky_color.indoors);
1778 // Prevent flickering clouds at dawn/dusk:
1779 sky_params.fog_sun_tint = video::SColor(255, 255, 255, 255);
1780 lua_getfield(L, -1, "fog_sun_tint");
1781 read_color(L, -1, &sky_params.fog_sun_tint);
1784 sky_params.fog_moon_tint = video::SColor(255, 255, 255, 255);
1785 lua_getfield(L, -1, "fog_moon_tint");
1786 read_color(L, -1, &sky_params.fog_moon_tint);
1789 lua_getfield(L, -1, "fog_tint_type");
1790 if (!lua_isnil(L, -1))
1791 sky_params.fog_tint_type = luaL_checkstring(L, -1);
1794 // Because we need to leave the "sky_color" table.
1798 // Handle old set_sky calls, and log deprecated:
1799 log_deprecated(L, "Deprecated call to set_sky, please check lua_api.txt");
1801 // Fix sun, moon and stars showing when classic textured skyboxes are used
1802 SunParams sun_params = player->getSunParams();
1803 MoonParams moon_params = player->getMoonParams();
1804 StarParams star_params = player->getStarParams();
1806 // Prevent erroneous background colors
1807 sky_params.bgcolor = video::SColor(255, 255, 255, 255);
1808 read_color(L, 2, &sky_params.bgcolor);
1810 sky_params.type = luaL_checkstring(L, 3);
1812 // Preserve old behaviour of the sun, moon and stars
1813 // when using the old set_sky call.
1814 if (sky_params.type == "regular") {
1815 sun_params.visible = true;
1816 sun_params.sunrise_visible = true;
1817 moon_params.visible = true;
1818 star_params.visible = true;
1820 sun_params.visible = false;
1821 sun_params.sunrise_visible = false;
1822 moon_params.visible = false;
1823 star_params.visible = false;
1826 sky_params.textures.clear();
1827 if (lua_istable(L, 4)) {
1829 while (lua_next(L, 4) != 0) {
1830 // Key at index -2, and value at index -1
1831 if (lua_isstring(L, -1))
1832 sky_params.textures.emplace_back(readParam<std::string>(L, -1));
1834 sky_params.textures.emplace_back("");
1835 // Remove the value, keep the key for the next iteration
1839 if (sky_params.type == "skybox" && sky_params.textures.size() != 6)
1840 throw LuaError("Skybox expects 6 textures.");
1842 sky_params.clouds = true;
1843 if (lua_isboolean(L, 5))
1844 sky_params.clouds = readParam<bool>(L, 5);
1846 getServer(L)->setSun(player, sun_params);
1847 getServer(L)->setMoon(player, moon_params);
1848 getServer(L)->setStars(player, star_params);
1850 getServer(L)->setSky(player, sky_params);
1851 lua_pushboolean(L, true);
1856 int ObjectRef::l_get_sky(lua_State *L)
1858 NO_MAP_LOCK_REQUIRED;
1859 ObjectRef *ref = checkobject(L, 1);
1860 RemotePlayer *player = getplayer(ref);
1861 if (player == nullptr)
1864 SkyboxParams skybox_params = player->getSkyParams();
1866 push_ARGB8(L, skybox_params.bgcolor);
1867 lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
1871 for (const std::string &texture : skybox_params.textures) {
1872 lua_pushlstring(L, texture.c_str(), texture.size());
1873 lua_rawseti(L, -2, i++);
1875 lua_pushboolean(L, skybox_params.clouds);
1879 // get_sky_color(self)
1880 int ObjectRef::l_get_sky_color(lua_State *L)
1882 NO_MAP_LOCK_REQUIRED;
1883 ObjectRef *ref = checkobject(L, 1);
1884 RemotePlayer *player = getplayer(ref);
1885 if (player == nullptr)
1888 const SkyboxParams &skybox_params = player->getSkyParams();
1891 if (skybox_params.type == "regular") {
1892 push_ARGB8(L, skybox_params.sky_color.day_sky);
1893 lua_setfield(L, -2, "day_sky");
1894 push_ARGB8(L, skybox_params.sky_color.day_horizon);
1895 lua_setfield(L, -2, "day_horizon");
1896 push_ARGB8(L, skybox_params.sky_color.dawn_sky);
1897 lua_setfield(L, -2, "dawn_sky");
1898 push_ARGB8(L, skybox_params.sky_color.dawn_horizon);
1899 lua_setfield(L, -2, "dawn_horizon");
1900 push_ARGB8(L, skybox_params.sky_color.night_sky);
1901 lua_setfield(L, -2, "night_sky");
1902 push_ARGB8(L, skybox_params.sky_color.night_horizon);
1903 lua_setfield(L, -2, "night_horizon");
1904 push_ARGB8(L, skybox_params.sky_color.indoors);
1905 lua_setfield(L, -2, "indoors");
1907 push_ARGB8(L, skybox_params.fog_sun_tint);
1908 lua_setfield(L, -2, "fog_sun_tint");
1909 push_ARGB8(L, skybox_params.fog_moon_tint);
1910 lua_setfield(L, -2, "fog_moon_tint");
1911 lua_pushstring(L, skybox_params.fog_tint_type.c_str());
1912 lua_setfield(L, -2, "fog_tint_type");
1916 // set_sun(self, sun_parameters)
1917 int ObjectRef::l_set_sun(lua_State *L)
1919 NO_MAP_LOCK_REQUIRED;
1920 ObjectRef *ref = checkobject(L, 1);
1921 RemotePlayer *player = getplayer(ref);
1922 if (player == nullptr)
1925 luaL_checktype(L, 2, LUA_TTABLE);
1926 SunParams sun_params = player->getSunParams();
1928 sun_params.visible = getboolfield_default(L, 2,
1929 "visible", sun_params.visible);
1930 sun_params.texture = getstringfield_default(L, 2,
1931 "texture", sun_params.texture);
1932 sun_params.tonemap = getstringfield_default(L, 2,
1933 "tonemap", sun_params.tonemap);
1934 sun_params.sunrise = getstringfield_default(L, 2,
1935 "sunrise", sun_params.sunrise);
1936 sun_params.sunrise_visible = getboolfield_default(L, 2,
1937 "sunrise_visible", sun_params.sunrise_visible);
1938 sun_params.scale = getfloatfield_default(L, 2,
1939 "scale", sun_params.scale);
1941 getServer(L)->setSun(player, sun_params);
1942 lua_pushboolean(L, true);
1947 int ObjectRef::l_get_sun(lua_State *L)
1949 NO_MAP_LOCK_REQUIRED;
1950 ObjectRef *ref = checkobject(L, 1);
1951 RemotePlayer *player = getplayer(ref);
1952 if (player == nullptr)
1955 const SunParams &sun_params = player->getSunParams();
1958 lua_pushboolean(L, sun_params.visible);
1959 lua_setfield(L, -2, "visible");
1960 lua_pushstring(L, sun_params.texture.c_str());
1961 lua_setfield(L, -2, "texture");
1962 lua_pushstring(L, sun_params.tonemap.c_str());
1963 lua_setfield(L, -2, "tonemap");
1964 lua_pushstring(L, sun_params.sunrise.c_str());
1965 lua_setfield(L, -2, "sunrise");
1966 lua_pushboolean(L, sun_params.sunrise_visible);
1967 lua_setfield(L, -2, "sunrise_visible");
1968 lua_pushnumber(L, sun_params.scale);
1969 lua_setfield(L, -2, "scale");
1973 // set_moon(self, moon_parameters)
1974 int ObjectRef::l_set_moon(lua_State *L)
1976 NO_MAP_LOCK_REQUIRED;
1977 ObjectRef *ref = checkobject(L, 1);
1978 RemotePlayer *player = getplayer(ref);
1979 if (player == nullptr)
1982 luaL_checktype(L, 2, LUA_TTABLE);
1983 MoonParams moon_params = player->getMoonParams();
1985 moon_params.visible = getboolfield_default(L, 2,
1986 "visible", moon_params.visible);
1987 moon_params.texture = getstringfield_default(L, 2,
1988 "texture", moon_params.texture);
1989 moon_params.tonemap = getstringfield_default(L, 2,
1990 "tonemap", moon_params.tonemap);
1991 moon_params.scale = getfloatfield_default(L, 2,
1992 "scale", moon_params.scale);
1994 getServer(L)->setMoon(player, moon_params);
1995 lua_pushboolean(L, true);
2000 int ObjectRef::l_get_moon(lua_State *L)
2002 NO_MAP_LOCK_REQUIRED;
2003 ObjectRef *ref = checkobject(L, 1);
2004 RemotePlayer *player = getplayer(ref);
2005 if (player == nullptr)
2008 const MoonParams &moon_params = player->getMoonParams();
2011 lua_pushboolean(L, moon_params.visible);
2012 lua_setfield(L, -2, "visible");
2013 lua_pushstring(L, moon_params.texture.c_str());
2014 lua_setfield(L, -2, "texture");
2015 lua_pushstring(L, moon_params.tonemap.c_str());
2016 lua_setfield(L, -2, "tonemap");
2017 lua_pushnumber(L, moon_params.scale);
2018 lua_setfield(L, -2, "scale");
2022 // set_stars(self, star_parameters)
2023 int ObjectRef::l_set_stars(lua_State *L)
2025 NO_MAP_LOCK_REQUIRED;
2026 ObjectRef *ref = checkobject(L, 1);
2027 RemotePlayer *player = getplayer(ref);
2028 if (player == nullptr)
2031 luaL_checktype(L, 2, LUA_TTABLE);
2032 StarParams star_params = player->getStarParams();
2034 star_params.visible = getboolfield_default(L, 2,
2035 "visible", star_params.visible);
2036 star_params.count = getintfield_default(L, 2,
2037 "count", star_params.count);
2039 lua_getfield(L, 2, "star_color");
2040 if (!lua_isnil(L, -1))
2041 read_color(L, -1, &star_params.starcolor);
2044 star_params.scale = getfloatfield_default(L, 2,
2045 "scale", star_params.scale);
2047 getServer(L)->setStars(player, star_params);
2048 lua_pushboolean(L, true);
2053 int ObjectRef::l_get_stars(lua_State *L)
2055 NO_MAP_LOCK_REQUIRED;
2056 ObjectRef *ref = checkobject(L, 1);
2057 RemotePlayer *player = getplayer(ref);
2058 if (player == nullptr)
2061 const StarParams &star_params = player->getStarParams();
2064 lua_pushboolean(L, star_params.visible);
2065 lua_setfield(L, -2, "visible");
2066 lua_pushnumber(L, star_params.count);
2067 lua_setfield(L, -2, "count");
2068 push_ARGB8(L, star_params.starcolor);
2069 lua_setfield(L, -2, "star_color");
2070 lua_pushnumber(L, star_params.scale);
2071 lua_setfield(L, -2, "scale");
2075 // set_clouds(self, cloud_parameters)
2076 int ObjectRef::l_set_clouds(lua_State *L)
2078 NO_MAP_LOCK_REQUIRED;
2079 ObjectRef *ref = checkobject(L, 1);
2080 RemotePlayer *player = getplayer(ref);
2081 if (player == nullptr)
2084 luaL_checktype(L, 2, LUA_TTABLE);
2085 CloudParams cloud_params = player->getCloudParams();
2087 cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
2089 lua_getfield(L, 2, "color");
2090 if (!lua_isnil(L, -1))
2091 read_color(L, -1, &cloud_params.color_bright);
2093 lua_getfield(L, 2, "ambient");
2094 if (!lua_isnil(L, -1))
2095 read_color(L, -1, &cloud_params.color_ambient);
2098 cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height );
2099 cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness);
2101 lua_getfield(L, 2, "speed");
2102 if (lua_istable(L, -1)) {
2104 new_speed.X = getfloatfield_default(L, -1, "x", 0);
2105 new_speed.Y = getfloatfield_default(L, -1, "z", 0);
2106 cloud_params.speed = new_speed;
2110 getServer(L)->setClouds(player, cloud_params);
2111 lua_pushboolean(L, true);
2115 int ObjectRef::l_get_clouds(lua_State *L)
2117 NO_MAP_LOCK_REQUIRED;
2118 ObjectRef *ref = checkobject(L, 1);
2119 RemotePlayer *player = getplayer(ref);
2120 if (player == nullptr)
2123 const CloudParams &cloud_params = player->getCloudParams();
2126 lua_pushnumber(L, cloud_params.density);
2127 lua_setfield(L, -2, "density");
2128 push_ARGB8(L, cloud_params.color_bright);
2129 lua_setfield(L, -2, "color");
2130 push_ARGB8(L, cloud_params.color_ambient);
2131 lua_setfield(L, -2, "ambient");
2132 lua_pushnumber(L, cloud_params.height);
2133 lua_setfield(L, -2, "height");
2134 lua_pushnumber(L, cloud_params.thickness);
2135 lua_setfield(L, -2, "thickness");
2137 lua_pushnumber(L, cloud_params.speed.X);
2138 lua_setfield(L, -2, "x");
2139 lua_pushnumber(L, cloud_params.speed.Y);
2140 lua_setfield(L, -2, "y");
2141 lua_setfield(L, -2, "speed");
2146 // override_day_night_ratio(self, ratio)
2147 int ObjectRef::l_override_day_night_ratio(lua_State *L)
2149 NO_MAP_LOCK_REQUIRED;
2150 ObjectRef *ref = checkobject(L, 1);
2151 RemotePlayer *player = getplayer(ref);
2152 if (player == nullptr)
2155 bool do_override = false;
2158 if (!lua_isnil(L, 2)) {
2160 ratio = readParam<float>(L, 2);
2161 luaL_argcheck(L, ratio >= 0.0f && ratio <= 1.0f, 1,
2162 "value must be between 0 and 1");
2165 getServer(L)->overrideDayNightRatio(player, do_override, ratio);
2166 lua_pushboolean(L, true);
2170 // get_day_night_ratio(self)
2171 int ObjectRef::l_get_day_night_ratio(lua_State *L)
2173 NO_MAP_LOCK_REQUIRED;
2174 ObjectRef *ref = checkobject(L, 1);
2175 RemotePlayer *player = getplayer(ref);
2176 if (player == nullptr)
2181 player->getDayNightRatio(&do_override, &ratio);
2184 lua_pushnumber(L, ratio);
2191 // set_minimap_modes(self, modes, selected_mode)
2192 int ObjectRef::l_set_minimap_modes(lua_State *L)
2194 NO_MAP_LOCK_REQUIRED;
2195 ObjectRef *ref = checkobject(L, 1);
2196 RemotePlayer *player = getplayer(ref);
2197 if (player == nullptr)
2200 luaL_checktype(L, 2, LUA_TTABLE);
2201 std::vector<MinimapMode> modes;
2202 s16 selected_mode = luaL_checkint(L, 3);
2205 while (lua_next(L, 2) != 0) {
2206 /* key is at index -2, value is at index -1 */
2207 if (lua_istable(L, -1)) {
2210 std::string type = getstringfield_default(L, -1, "type", "");
2212 mode.type = MINIMAP_TYPE_OFF;
2213 else if (type == "surface")
2214 mode.type = MINIMAP_TYPE_SURFACE;
2215 else if (type == "radar")
2216 mode.type = MINIMAP_TYPE_RADAR;
2217 else if (type == "texture") {
2218 mode.type = MINIMAP_TYPE_TEXTURE;
2219 mode.texture = getstringfield_default(L, -1, "texture", "");
2220 mode.scale = getintfield_default(L, -1, "scale", 1);
2222 warningstream << "Minimap mode of unknown type \"" << type.c_str()
2223 << "\" ignored.\n" << std::endl;
2228 mode.label = getstringfield_default(L, -1, "label", "");
2229 // Size is limited to 512. Performance gets poor if size too large, and
2230 // segfaults have been experienced.
2231 mode.size = rangelim(getintfield_default(L, -1, "size", 0), 1, 512);
2232 modes.push_back(mode);
2235 /* removes 'value'; keeps 'key' for next iteration */
2238 lua_pop(L, 1); // Remove key
2240 getServer(L)->SendMinimapModes(player->getPeerId(), modes, selected_mode);
2244 ObjectRef::ObjectRef(ServerActiveObject *object):
2248 // Creates an ObjectRef and leaves it on top of stack
2249 // Not callable from Lua; all references are created on the C side.
2250 void ObjectRef::create(lua_State *L, ServerActiveObject *object)
2252 ObjectRef *obj = new ObjectRef(object);
2253 *(void **)(lua_newuserdata(L, sizeof(void *))) = obj;
2254 luaL_getmetatable(L, className);
2255 lua_setmetatable(L, -2);
2258 void ObjectRef::set_null(lua_State *L)
2260 ObjectRef *obj = checkobject(L, -1);
2261 obj->m_object = nullptr;
2264 void ObjectRef::Register(lua_State *L)
2267 int methodtable = lua_gettop(L);
2268 luaL_newmetatable(L, className);
2269 int metatable = lua_gettop(L);
2271 lua_pushliteral(L, "__metatable");
2272 lua_pushvalue(L, methodtable);
2273 lua_settable(L, metatable); // hide metatable from Lua getmetatable()
2275 lua_pushliteral(L, "__index");
2276 lua_pushvalue(L, methodtable);
2277 lua_settable(L, metatable);
2279 lua_pushliteral(L, "__gc");
2280 lua_pushcfunction(L, gc_object);
2281 lua_settable(L, metatable);
2283 lua_pop(L, 1); // drop metatable
2285 luaL_openlib(L, 0, methods, 0); // fill methodtable
2286 lua_pop(L, 1); // drop methodtable
2289 const char ObjectRef::className[] = "ObjectRef";
2290 luaL_Reg ObjectRef::methods[] = {
2291 // ServerActiveObject
2292 luamethod(ObjectRef, remove),
2293 luamethod_aliased(ObjectRef, get_pos, getpos),
2294 luamethod_aliased(ObjectRef, set_pos, setpos),
2295 luamethod_aliased(ObjectRef, move_to, moveto),
2296 luamethod(ObjectRef, punch),
2297 luamethod(ObjectRef, right_click),
2298 luamethod(ObjectRef, set_hp),
2299 luamethod(ObjectRef, get_hp),
2300 luamethod(ObjectRef, get_inventory),
2301 luamethod(ObjectRef, get_wield_list),
2302 luamethod(ObjectRef, get_wield_index),
2303 luamethod(ObjectRef, get_wielded_item),
2304 luamethod(ObjectRef, set_wielded_item),
2305 luamethod(ObjectRef, set_armor_groups),
2306 luamethod(ObjectRef, get_armor_groups),
2307 luamethod(ObjectRef, set_animation),
2308 luamethod(ObjectRef, get_animation),
2309 luamethod(ObjectRef, set_animation_frame_speed),
2310 luamethod(ObjectRef, set_bone_position),
2311 luamethod(ObjectRef, get_bone_position),
2312 luamethod(ObjectRef, set_attach),
2313 luamethod(ObjectRef, get_attach),
2314 luamethod(ObjectRef, get_children),
2315 luamethod(ObjectRef, set_detach),
2316 luamethod(ObjectRef, set_properties),
2317 luamethod(ObjectRef, get_properties),
2318 luamethod(ObjectRef, set_nametag_attributes),
2319 luamethod(ObjectRef, get_nametag_attributes),
2321 luamethod_aliased(ObjectRef, set_velocity, setvelocity),
2322 luamethod_aliased(ObjectRef, add_velocity, add_player_velocity),
2323 luamethod_aliased(ObjectRef, get_velocity, getvelocity),
2324 luamethod_dep(ObjectRef, get_velocity, get_player_velocity),
2326 // LuaEntitySAO-only
2327 luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
2328 luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
2329 luamethod_aliased(ObjectRef, set_yaw, setyaw),
2330 luamethod_aliased(ObjectRef, get_yaw, getyaw),
2331 luamethod(ObjectRef, set_rotation),
2332 luamethod(ObjectRef, get_rotation),
2333 luamethod_aliased(ObjectRef, set_texture_mod, settexturemod),
2334 luamethod(ObjectRef, get_texture_mod),
2335 luamethod_aliased(ObjectRef, set_sprite, setsprite),
2336 luamethod(ObjectRef, get_entity_name),
2337 luamethod(ObjectRef, get_luaentity),
2340 luamethod(ObjectRef, is_player),
2341 luamethod(ObjectRef, get_player_name),
2342 luamethod(ObjectRef, get_look_dir),
2343 luamethod(ObjectRef, get_look_pitch),
2344 luamethod(ObjectRef, get_look_yaw),
2345 luamethod(ObjectRef, get_look_vertical),
2346 luamethod(ObjectRef, get_look_horizontal),
2347 luamethod(ObjectRef, set_look_horizontal),
2348 luamethod(ObjectRef, set_look_vertical),
2349 luamethod(ObjectRef, set_look_yaw),
2350 luamethod(ObjectRef, set_look_pitch),
2351 luamethod(ObjectRef, get_fov),
2352 luamethod(ObjectRef, set_fov),
2353 luamethod(ObjectRef, get_breath),
2354 luamethod(ObjectRef, set_breath),
2355 luamethod(ObjectRef, get_attribute),
2356 luamethod(ObjectRef, set_attribute),
2357 luamethod(ObjectRef, get_meta),
2358 luamethod(ObjectRef, set_inventory_formspec),
2359 luamethod(ObjectRef, get_inventory_formspec),
2360 luamethod(ObjectRef, set_formspec_prepend),
2361 luamethod(ObjectRef, get_formspec_prepend),
2362 luamethod(ObjectRef, get_player_control),
2363 luamethod(ObjectRef, get_player_control_bits),
2364 luamethod(ObjectRef, set_physics_override),
2365 luamethod(ObjectRef, get_physics_override),
2366 luamethod(ObjectRef, hud_add),
2367 luamethod(ObjectRef, hud_remove),
2368 luamethod(ObjectRef, hud_change),
2369 luamethod(ObjectRef, hud_get),
2370 luamethod(ObjectRef, hud_set_flags),
2371 luamethod(ObjectRef, hud_get_flags),
2372 luamethod(ObjectRef, hud_set_hotbar_itemcount),
2373 luamethod(ObjectRef, hud_get_hotbar_itemcount),
2374 luamethod(ObjectRef, hud_set_hotbar_image),
2375 luamethod(ObjectRef, hud_get_hotbar_image),
2376 luamethod(ObjectRef, hud_set_hotbar_selected_image),
2377 luamethod(ObjectRef, hud_get_hotbar_selected_image),
2378 luamethod(ObjectRef, set_sky),
2379 luamethod(ObjectRef, get_sky),
2380 luamethod(ObjectRef, get_sky_color),
2381 luamethod(ObjectRef, set_sun),
2382 luamethod(ObjectRef, get_sun),
2383 luamethod(ObjectRef, set_moon),
2384 luamethod(ObjectRef, get_moon),
2385 luamethod(ObjectRef, set_stars),
2386 luamethod(ObjectRef, get_stars),
2387 luamethod(ObjectRef, set_clouds),
2388 luamethod(ObjectRef, get_clouds),
2389 luamethod(ObjectRef, override_day_night_ratio),
2390 luamethod(ObjectRef, get_day_night_ratio),
2391 luamethod(ObjectRef, set_local_animation),
2392 luamethod(ObjectRef, get_local_animation),
2393 luamethod(ObjectRef, set_eye_offset),
2394 luamethod(ObjectRef, get_eye_offset),
2395 luamethod(ObjectRef, send_mapblock),
2396 luamethod(ObjectRef, set_minimap_modes),