l_object.cpp 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "lua_api/l_object.h"
  17. #include <cmath>
  18. #include "lua_api/l_internal.h"
  19. #include "lua_api/l_inventory.h"
  20. #include "lua_api/l_item.h"
  21. #include "lua_api/l_playermeta.h"
  22. #include "common/c_converter.h"
  23. #include "common/c_content.h"
  24. #include "log.h"
  25. #include "tool.h"
  26. #include "serverobject.h"
  27. #include "content_sao.h"
  28. #include "remoteplayer.h"
  29. #include "server.h"
  30. #include "hud.h"
  31. #include "scripting_server.h"
  32. /*
  33. ObjectRef
  34. */
  35. ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
  36. {
  37. luaL_checktype(L, narg, LUA_TUSERDATA);
  38. void *ud = luaL_checkudata(L, narg, className);
  39. if (!ud) luaL_typerror(L, narg, className);
  40. return *(ObjectRef**)ud; // unbox pointer
  41. }
  42. ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
  43. {
  44. ServerActiveObject *co = ref->m_object;
  45. return co;
  46. }
  47. LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
  48. {
  49. ServerActiveObject *obj = getobject(ref);
  50. if (obj == NULL)
  51. return NULL;
  52. if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
  53. return NULL;
  54. return (LuaEntitySAO*)obj;
  55. }
  56. PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
  57. {
  58. ServerActiveObject *obj = getobject(ref);
  59. if (obj == NULL)
  60. return NULL;
  61. if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
  62. return NULL;
  63. return (PlayerSAO*)obj;
  64. }
  65. RemotePlayer *ObjectRef::getplayer(ObjectRef *ref)
  66. {
  67. PlayerSAO *playersao = getplayersao(ref);
  68. if (playersao == NULL)
  69. return NULL;
  70. return playersao->getPlayer();
  71. }
  72. // Exported functions
  73. // garbage collector
  74. int ObjectRef::gc_object(lua_State *L) {
  75. ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1));
  76. //infostream<<"ObjectRef::gc_object: o="<<o<<std::endl;
  77. delete o;
  78. return 0;
  79. }
  80. // remove(self)
  81. int ObjectRef::l_remove(lua_State *L)
  82. {
  83. GET_ENV_PTR;
  84. ObjectRef *ref = checkobject(L, 1);
  85. ServerActiveObject *co = getobject(ref);
  86. if (co == NULL)
  87. return 0;
  88. if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
  89. return 0;
  90. co->clearChildAttachments();
  91. co->clearParentAttachment();
  92. verbosestream << "ObjectRef::l_remove(): id=" << co->getId() << std::endl;
  93. co->m_pending_removal = true;
  94. return 0;
  95. }
  96. // get_pos(self)
  97. // returns: {x=num, y=num, z=num}
  98. int ObjectRef::l_get_pos(lua_State *L)
  99. {
  100. NO_MAP_LOCK_REQUIRED;
  101. ObjectRef *ref = checkobject(L, 1);
  102. ServerActiveObject *co = getobject(ref);
  103. if (co == NULL) return 0;
  104. v3f pos = co->getBasePosition() / BS;
  105. lua_newtable(L);
  106. lua_pushnumber(L, pos.X);
  107. lua_setfield(L, -2, "x");
  108. lua_pushnumber(L, pos.Y);
  109. lua_setfield(L, -2, "y");
  110. lua_pushnumber(L, pos.Z);
  111. lua_setfield(L, -2, "z");
  112. return 1;
  113. }
  114. // set_pos(self, pos)
  115. int ObjectRef::l_set_pos(lua_State *L)
  116. {
  117. NO_MAP_LOCK_REQUIRED;
  118. ObjectRef *ref = checkobject(L, 1);
  119. //LuaEntitySAO *co = getluaobject(ref);
  120. ServerActiveObject *co = getobject(ref);
  121. if (co == NULL) return 0;
  122. // pos
  123. v3f pos = checkFloatPos(L, 2);
  124. // Do it
  125. co->setPos(pos);
  126. return 0;
  127. }
  128. // move_to(self, pos, continuous=false)
  129. int ObjectRef::l_move_to(lua_State *L)
  130. {
  131. NO_MAP_LOCK_REQUIRED;
  132. ObjectRef *ref = checkobject(L, 1);
  133. //LuaEntitySAO *co = getluaobject(ref);
  134. ServerActiveObject *co = getobject(ref);
  135. if (co == NULL) return 0;
  136. // pos
  137. v3f pos = checkFloatPos(L, 2);
  138. // continuous
  139. bool continuous = lua_toboolean(L, 3);
  140. // Do it
  141. co->moveTo(pos, continuous);
  142. return 0;
  143. }
  144. // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
  145. int ObjectRef::l_punch(lua_State *L)
  146. {
  147. NO_MAP_LOCK_REQUIRED;
  148. ObjectRef *ref = checkobject(L, 1);
  149. ObjectRef *puncher_ref = checkobject(L, 2);
  150. ServerActiveObject *co = getobject(ref);
  151. ServerActiveObject *puncher = getobject(puncher_ref);
  152. if (co == NULL) return 0;
  153. if (puncher == NULL) return 0;
  154. v3f dir;
  155. if (lua_type(L, 5) != LUA_TTABLE)
  156. dir = co->getBasePosition() - puncher->getBasePosition();
  157. else
  158. dir = read_v3f(L, 5);
  159. float time_from_last_punch = 1000000;
  160. if (lua_isnumber(L, 3))
  161. time_from_last_punch = lua_tonumber(L, 3);
  162. ToolCapabilities toolcap = read_tool_capabilities(L, 4);
  163. dir.normalize();
  164. s16 src_original_hp = co->getHP();
  165. s16 dst_origin_hp = puncher->getHP();
  166. // Do it
  167. co->punch(dir, &toolcap, puncher, time_from_last_punch);
  168. // If the punched is a player, and its HP changed
  169. if (src_original_hp != co->getHP() &&
  170. co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
  171. getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
  172. }
  173. // If the puncher is a player, and its HP changed
  174. if (dst_origin_hp != puncher->getHP() &&
  175. puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
  176. getServer(L)->SendPlayerHPOrDie((PlayerSAO *)puncher,
  177. PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, co));
  178. }
  179. return 0;
  180. }
  181. // right_click(self, clicker); clicker = an another ObjectRef
  182. int ObjectRef::l_right_click(lua_State *L)
  183. {
  184. NO_MAP_LOCK_REQUIRED;
  185. ObjectRef *ref = checkobject(L, 1);
  186. ObjectRef *ref2 = checkobject(L, 2);
  187. ServerActiveObject *co = getobject(ref);
  188. ServerActiveObject *co2 = getobject(ref2);
  189. if (co == NULL) return 0;
  190. if (co2 == NULL) return 0;
  191. // Do it
  192. co->rightClick(co2);
  193. return 0;
  194. }
  195. // set_hp(self, hp)
  196. // hp = number of hitpoints (2 * number of hearts)
  197. // returns: nil
  198. int ObjectRef::l_set_hp(lua_State *L)
  199. {
  200. NO_MAP_LOCK_REQUIRED;
  201. // Get Object
  202. ObjectRef *ref = checkobject(L, 1);
  203. luaL_checknumber(L, 2);
  204. ServerActiveObject *co = getobject(ref);
  205. if (co == NULL)
  206. return 0;
  207. // Get HP
  208. int hp = lua_tonumber(L, 2);
  209. // Get Reason
  210. PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
  211. reason.from_mod = true;
  212. if (lua_istable(L, 3)) {
  213. lua_pushvalue(L, 3);
  214. lua_getfield(L, -1, "type");
  215. if (lua_isstring(L, -1) && !reason.setTypeFromString(lua_tostring(L, -1))) {
  216. errorstream << "Bad type given!" << std::endl;
  217. }
  218. lua_pop(L, 1);
  219. reason.lua_reference = luaL_ref(L, LUA_REGISTRYINDEX);
  220. }
  221. // Do it
  222. co->setHP(hp, reason);
  223. if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
  224. getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, reason);
  225. // Return
  226. return 0;
  227. }
  228. // get_hp(self)
  229. // returns: number of hitpoints (2 * number of hearts)
  230. // 0 if not applicable to this type of object
  231. int ObjectRef::l_get_hp(lua_State *L)
  232. {
  233. NO_MAP_LOCK_REQUIRED;
  234. ObjectRef *ref = checkobject(L, 1);
  235. ServerActiveObject *co = getobject(ref);
  236. if (co == NULL) {
  237. // Default hp is 1
  238. lua_pushnumber(L, 1);
  239. return 1;
  240. }
  241. int hp = co->getHP();
  242. /*infostream<<"ObjectRef::l_get_hp(): id="<<co->getId()
  243. <<" hp="<<hp<<std::endl;*/
  244. // Return
  245. lua_pushnumber(L, hp);
  246. return 1;
  247. }
  248. // get_inventory(self)
  249. int ObjectRef::l_get_inventory(lua_State *L)
  250. {
  251. NO_MAP_LOCK_REQUIRED;
  252. ObjectRef *ref = checkobject(L, 1);
  253. ServerActiveObject *co = getobject(ref);
  254. if (co == NULL) return 0;
  255. // Do it
  256. InventoryLocation loc = co->getInventoryLocation();
  257. if (getServer(L)->getInventory(loc) != NULL)
  258. InvRef::create(L, loc);
  259. else
  260. lua_pushnil(L); // An object may have no inventory (nil)
  261. return 1;
  262. }
  263. // get_wield_list(self)
  264. int ObjectRef::l_get_wield_list(lua_State *L)
  265. {
  266. NO_MAP_LOCK_REQUIRED;
  267. ObjectRef *ref = checkobject(L, 1);
  268. ServerActiveObject *co = getobject(ref);
  269. if (co == NULL) return 0;
  270. // Do it
  271. lua_pushstring(L, co->getWieldList().c_str());
  272. return 1;
  273. }
  274. // get_wield_index(self)
  275. int ObjectRef::l_get_wield_index(lua_State *L)
  276. {
  277. NO_MAP_LOCK_REQUIRED;
  278. ObjectRef *ref = checkobject(L, 1);
  279. ServerActiveObject *co = getobject(ref);
  280. if (co == NULL) return 0;
  281. // Do it
  282. lua_pushinteger(L, co->getWieldIndex() + 1);
  283. return 1;
  284. }
  285. // get_wielded_item(self)
  286. int ObjectRef::l_get_wielded_item(lua_State *L)
  287. {
  288. NO_MAP_LOCK_REQUIRED;
  289. ObjectRef *ref = checkobject(L, 1);
  290. ServerActiveObject *co = getobject(ref);
  291. if (co == NULL) {
  292. // Empty ItemStack
  293. LuaItemStack::create(L, ItemStack());
  294. return 1;
  295. }
  296. // Do it
  297. LuaItemStack::create(L, co->getWieldedItem());
  298. return 1;
  299. }
  300. // set_wielded_item(self, itemstack or itemstring or table or nil)
  301. int ObjectRef::l_set_wielded_item(lua_State *L)
  302. {
  303. NO_MAP_LOCK_REQUIRED;
  304. ObjectRef *ref = checkobject(L, 1);
  305. ServerActiveObject *co = getobject(ref);
  306. if (co == NULL) return 0;
  307. // Do it
  308. ItemStack item = read_item(L, 2, getServer(L)->idef());
  309. bool success = co->setWieldedItem(item);
  310. if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
  311. getServer(L)->SendInventory(((PlayerSAO*)co));
  312. }
  313. lua_pushboolean(L, success);
  314. return 1;
  315. }
  316. // set_armor_groups(self, groups)
  317. int ObjectRef::l_set_armor_groups(lua_State *L)
  318. {
  319. NO_MAP_LOCK_REQUIRED;
  320. ObjectRef *ref = checkobject(L, 1);
  321. ServerActiveObject *co = getobject(ref);
  322. if (co == NULL) return 0;
  323. // Do it
  324. ItemGroupList groups;
  325. read_groups(L, 2, groups);
  326. co->setArmorGroups(groups);
  327. return 0;
  328. }
  329. // get_armor_groups(self)
  330. int ObjectRef::l_get_armor_groups(lua_State *L)
  331. {
  332. NO_MAP_LOCK_REQUIRED;
  333. ObjectRef *ref = checkobject(L, 1);
  334. ServerActiveObject *co = getobject(ref);
  335. if (co == NULL)
  336. return 0;
  337. // Do it
  338. push_groups(L, co->getArmorGroups());
  339. return 1;
  340. }
  341. // set_physics_override(self, physics_override_speed, physics_override_jump,
  342. // physics_override_gravity, sneak, sneak_glitch, new_move)
  343. int ObjectRef::l_set_physics_override(lua_State *L)
  344. {
  345. NO_MAP_LOCK_REQUIRED;
  346. ObjectRef *ref = checkobject(L, 1);
  347. PlayerSAO *co = (PlayerSAO *) getobject(ref);
  348. if (co == NULL) return 0;
  349. // Do it
  350. if (lua_istable(L, 2)) {
  351. co->m_physics_override_speed = getfloatfield_default(
  352. L, 2, "speed", co->m_physics_override_speed);
  353. co->m_physics_override_jump = getfloatfield_default(
  354. L, 2, "jump", co->m_physics_override_jump);
  355. co->m_physics_override_gravity = getfloatfield_default(
  356. L, 2, "gravity", co->m_physics_override_gravity);
  357. co->m_physics_override_sneak = getboolfield_default(
  358. L, 2, "sneak", co->m_physics_override_sneak);
  359. co->m_physics_override_sneak_glitch = getboolfield_default(
  360. L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
  361. co->m_physics_override_new_move = getboolfield_default(
  362. L, 2, "new_move", co->m_physics_override_new_move);
  363. co->m_physics_override_sent = false;
  364. } else {
  365. // old, non-table format
  366. if (!lua_isnil(L, 2)) {
  367. co->m_physics_override_speed = lua_tonumber(L, 2);
  368. co->m_physics_override_sent = false;
  369. }
  370. if (!lua_isnil(L, 3)) {
  371. co->m_physics_override_jump = lua_tonumber(L, 3);
  372. co->m_physics_override_sent = false;
  373. }
  374. if (!lua_isnil(L, 4)) {
  375. co->m_physics_override_gravity = lua_tonumber(L, 4);
  376. co->m_physics_override_sent = false;
  377. }
  378. }
  379. return 0;
  380. }
  381. // get_physics_override(self)
  382. int ObjectRef::l_get_physics_override(lua_State *L)
  383. {
  384. NO_MAP_LOCK_REQUIRED;
  385. ObjectRef *ref = checkobject(L, 1);
  386. PlayerSAO *co = (PlayerSAO *)getobject(ref);
  387. if (co == NULL)
  388. return 0;
  389. // Do it
  390. lua_newtable(L);
  391. lua_pushnumber(L, co->m_physics_override_speed);
  392. lua_setfield(L, -2, "speed");
  393. lua_pushnumber(L, co->m_physics_override_jump);
  394. lua_setfield(L, -2, "jump");
  395. lua_pushnumber(L, co->m_physics_override_gravity);
  396. lua_setfield(L, -2, "gravity");
  397. lua_pushboolean(L, co->m_physics_override_sneak);
  398. lua_setfield(L, -2, "sneak");
  399. lua_pushboolean(L, co->m_physics_override_sneak_glitch);
  400. lua_setfield(L, -2, "sneak_glitch");
  401. lua_pushboolean(L, co->m_physics_override_new_move);
  402. lua_setfield(L, -2, "new_move");
  403. return 1;
  404. }
  405. // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
  406. int ObjectRef::l_set_animation(lua_State *L)
  407. {
  408. NO_MAP_LOCK_REQUIRED;
  409. ObjectRef *ref = checkobject(L, 1);
  410. ServerActiveObject *co = getobject(ref);
  411. if (co == NULL) return 0;
  412. // Do it
  413. v2f frames = v2f(1, 1);
  414. if (!lua_isnil(L, 2))
  415. frames = read_v2f(L, 2);
  416. float frame_speed = 15;
  417. if (!lua_isnil(L, 3))
  418. frame_speed = lua_tonumber(L, 3);
  419. float frame_blend = 0;
  420. if (!lua_isnil(L, 4))
  421. frame_blend = lua_tonumber(L, 4);
  422. bool frame_loop = true;
  423. if (lua_isboolean(L, 5))
  424. frame_loop = lua_toboolean(L, 5);
  425. co->setAnimation(frames, frame_speed, frame_blend, frame_loop);
  426. return 0;
  427. }
  428. // get_animation(self)
  429. int ObjectRef::l_get_animation(lua_State *L)
  430. {
  431. NO_MAP_LOCK_REQUIRED;
  432. ObjectRef *ref = checkobject(L, 1);
  433. ServerActiveObject *co = getobject(ref);
  434. if (co == NULL)
  435. return 0;
  436. // Do it
  437. v2f frames = v2f(1,1);
  438. float frame_speed = 15;
  439. float frame_blend = 0;
  440. bool frame_loop = true;
  441. co->getAnimation(&frames, &frame_speed, &frame_blend, &frame_loop);
  442. push_v2f(L, frames);
  443. lua_pushnumber(L, frame_speed);
  444. lua_pushnumber(L, frame_blend);
  445. lua_pushboolean(L, frame_loop);
  446. return 4;
  447. }
  448. // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
  449. int ObjectRef::l_set_local_animation(lua_State *L)
  450. {
  451. NO_MAP_LOCK_REQUIRED;
  452. ObjectRef *ref = checkobject(L, 1);
  453. RemotePlayer *player = getplayer(ref);
  454. if (player == NULL)
  455. return 0;
  456. // Do it
  457. v2s32 frames[4];
  458. for (int i=0;i<4;i++) {
  459. if (!lua_isnil(L, 2+1))
  460. frames[i] = read_v2s32(L, 2+i);
  461. }
  462. float frame_speed = 30;
  463. if (!lua_isnil(L, 6))
  464. frame_speed = lua_tonumber(L, 6);
  465. getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
  466. lua_pushboolean(L, true);
  467. return 1;
  468. }
  469. // get_local_animation(self)
  470. int ObjectRef::l_get_local_animation(lua_State *L)
  471. {
  472. NO_MAP_LOCK_REQUIRED
  473. ObjectRef *ref = checkobject(L, 1);
  474. RemotePlayer *player = getplayer(ref);
  475. if (player == NULL)
  476. return 0;
  477. v2s32 frames[4];
  478. float frame_speed;
  479. player->getLocalAnimations(frames, &frame_speed);
  480. for (const v2s32 &frame : frames) {
  481. push_v2s32(L, frame);
  482. }
  483. lua_pushnumber(L, frame_speed);
  484. return 5;
  485. }
  486. // set_eye_offset(self, v3f first pv, v3f third pv)
  487. int ObjectRef::l_set_eye_offset(lua_State *L)
  488. {
  489. NO_MAP_LOCK_REQUIRED;
  490. ObjectRef *ref = checkobject(L, 1);
  491. RemotePlayer *player = getplayer(ref);
  492. if (player == NULL)
  493. return 0;
  494. // Do it
  495. v3f offset_first = v3f(0, 0, 0);
  496. v3f offset_third = v3f(0, 0, 0);
  497. if (!lua_isnil(L, 2))
  498. offset_first = read_v3f(L, 2);
  499. if (!lua_isnil(L, 3))
  500. offset_third = read_v3f(L, 3);
  501. // Prevent abuse of offset values (keep player always visible)
  502. offset_third.X = rangelim(offset_third.X,-10,10);
  503. offset_third.Z = rangelim(offset_third.Z,-5,5);
  504. /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
  505. offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
  506. getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
  507. lua_pushboolean(L, true);
  508. return 1;
  509. }
  510. // get_eye_offset(self)
  511. int ObjectRef::l_get_eye_offset(lua_State *L)
  512. {
  513. NO_MAP_LOCK_REQUIRED;
  514. ObjectRef *ref = checkobject(L, 1);
  515. RemotePlayer *player = getplayer(ref);
  516. if (player == NULL)
  517. return 0;
  518. // Do it
  519. push_v3f(L, player->eye_offset_first);
  520. push_v3f(L, player->eye_offset_third);
  521. return 2;
  522. }
  523. // set_animation_frame_speed(self, frame_speed)
  524. int ObjectRef::l_set_animation_frame_speed(lua_State *L)
  525. {
  526. NO_MAP_LOCK_REQUIRED;
  527. ObjectRef *ref = checkobject(L, 1);
  528. ServerActiveObject *co = getobject(ref);
  529. if (co == NULL)
  530. return 0;
  531. // Do it
  532. if (!lua_isnil(L, 2)) {
  533. float frame_speed = lua_tonumber(L, 2);
  534. co->setAnimationSpeed(frame_speed);
  535. lua_pushboolean(L, true);
  536. } else {
  537. lua_pushboolean(L, false);
  538. }
  539. return 1;
  540. }
  541. // set_bone_position(self, std::string bone, v3f position, v3f rotation)
  542. int ObjectRef::l_set_bone_position(lua_State *L)
  543. {
  544. NO_MAP_LOCK_REQUIRED;
  545. ObjectRef *ref = checkobject(L, 1);
  546. ServerActiveObject *co = getobject(ref);
  547. if (co == NULL) return 0;
  548. // Do it
  549. std::string bone;
  550. if (!lua_isnil(L, 2))
  551. bone = lua_tostring(L, 2);
  552. v3f position = v3f(0, 0, 0);
  553. if (!lua_isnil(L, 3))
  554. position = check_v3f(L, 3);
  555. v3f rotation = v3f(0, 0, 0);
  556. if (!lua_isnil(L, 4))
  557. rotation = check_v3f(L, 4);
  558. co->setBonePosition(bone, position, rotation);
  559. return 0;
  560. }
  561. // get_bone_position(self, bone)
  562. int ObjectRef::l_get_bone_position(lua_State *L)
  563. {
  564. NO_MAP_LOCK_REQUIRED;
  565. ObjectRef *ref = checkobject(L, 1);
  566. ServerActiveObject *co = getobject(ref);
  567. if (co == NULL)
  568. return 0;
  569. // Do it
  570. std::string bone;
  571. if (!lua_isnil(L, 2))
  572. bone = lua_tostring(L, 2);
  573. v3f position = v3f(0, 0, 0);
  574. v3f rotation = v3f(0, 0, 0);
  575. co->getBonePosition(bone, &position, &rotation);
  576. push_v3f(L, position);
  577. push_v3f(L, rotation);
  578. return 2;
  579. }
  580. // set_attach(self, parent, bone, position, rotation)
  581. int ObjectRef::l_set_attach(lua_State *L)
  582. {
  583. GET_ENV_PTR;
  584. ObjectRef *ref = checkobject(L, 1);
  585. ObjectRef *parent_ref = checkobject(L, 2);
  586. ServerActiveObject *co = getobject(ref);
  587. ServerActiveObject *parent = getobject(parent_ref);
  588. if (co == NULL)
  589. return 0;
  590. if (parent == NULL)
  591. return 0;
  592. // Do it
  593. int parent_id = 0;
  594. std::string bone;
  595. v3f position = v3f(0, 0, 0);
  596. v3f rotation = v3f(0, 0, 0);
  597. co->getAttachment(&parent_id, &bone, &position, &rotation);
  598. if (parent_id) {
  599. ServerActiveObject *old_parent = env->getActiveObject(parent_id);
  600. old_parent->removeAttachmentChild(co->getId());
  601. }
  602. bone = "";
  603. if (!lua_isnil(L, 3))
  604. bone = lua_tostring(L, 3);
  605. position = v3f(0, 0, 0);
  606. if (!lua_isnil(L, 4))
  607. position = read_v3f(L, 4);
  608. rotation = v3f(0, 0, 0);
  609. if (!lua_isnil(L, 5))
  610. rotation = read_v3f(L, 5);
  611. co->setAttachment(parent->getId(), bone, position, rotation);
  612. parent->addAttachmentChild(co->getId());
  613. return 0;
  614. }
  615. // get_attach(self)
  616. int ObjectRef::l_get_attach(lua_State *L)
  617. {
  618. GET_ENV_PTR;
  619. ObjectRef *ref = checkobject(L, 1);
  620. ServerActiveObject *co = getobject(ref);
  621. if (co == NULL)
  622. return 0;
  623. // Do it
  624. int parent_id = 0;
  625. std::string bone;
  626. v3f position = v3f(0, 0, 0);
  627. v3f rotation = v3f(0, 0, 0);
  628. co->getAttachment(&parent_id, &bone, &position, &rotation);
  629. if (!parent_id)
  630. return 0;
  631. ServerActiveObject *parent = env->getActiveObject(parent_id);
  632. getScriptApiBase(L)->objectrefGetOrCreate(L, parent);
  633. lua_pushlstring(L, bone.c_str(), bone.size());
  634. push_v3f(L, position);
  635. push_v3f(L, rotation);
  636. return 4;
  637. }
  638. // set_detach(self)
  639. int ObjectRef::l_set_detach(lua_State *L)
  640. {
  641. GET_ENV_PTR;
  642. ObjectRef *ref = checkobject(L, 1);
  643. ServerActiveObject *co = getobject(ref);
  644. if (co == NULL)
  645. return 0;
  646. co->clearParentAttachment();
  647. return 0;
  648. }
  649. // set_properties(self, properties)
  650. int ObjectRef::l_set_properties(lua_State *L)
  651. {
  652. NO_MAP_LOCK_REQUIRED;
  653. ObjectRef *ref = checkobject(L, 1);
  654. ServerActiveObject *co = getobject(ref);
  655. if (co == NULL) return 0;
  656. ObjectProperties *prop = co->accessObjectProperties();
  657. if (!prop)
  658. return 0;
  659. read_object_properties(L, 2, prop, getServer(L)->idef());
  660. if (prop->hp_max < co->getHP()) {
  661. PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
  662. co->setHP(prop->hp_max, reason);
  663. if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
  664. getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, reason);
  665. }
  666. co->notifyObjectPropertiesModified();
  667. return 0;
  668. }
  669. // get_properties(self)
  670. int ObjectRef::l_get_properties(lua_State *L)
  671. {
  672. NO_MAP_LOCK_REQUIRED;
  673. ObjectRef *ref = checkobject(L, 1);
  674. ServerActiveObject *co = getobject(ref);
  675. if (co == NULL)
  676. return 0;
  677. ObjectProperties *prop = co->accessObjectProperties();
  678. if (!prop)
  679. return 0;
  680. push_object_properties(L, prop);
  681. return 1;
  682. }
  683. // is_player(self)
  684. int ObjectRef::l_is_player(lua_State *L)
  685. {
  686. NO_MAP_LOCK_REQUIRED;
  687. ObjectRef *ref = checkobject(L, 1);
  688. RemotePlayer *player = getplayer(ref);
  689. lua_pushboolean(L, (player != NULL));
  690. return 1;
  691. }
  692. // set_nametag_attributes(self, attributes)
  693. int ObjectRef::l_set_nametag_attributes(lua_State *L)
  694. {
  695. NO_MAP_LOCK_REQUIRED;
  696. ObjectRef *ref = checkobject(L, 1);
  697. ServerActiveObject *co = getobject(ref);
  698. if (co == NULL)
  699. return 0;
  700. ObjectProperties *prop = co->accessObjectProperties();
  701. if (!prop)
  702. return 0;
  703. lua_getfield(L, 2, "color");
  704. if (!lua_isnil(L, -1)) {
  705. video::SColor color = prop->nametag_color;
  706. read_color(L, -1, &color);
  707. prop->nametag_color = color;
  708. }
  709. lua_pop(L, 1);
  710. std::string nametag = getstringfield_default(L, 2, "text", "");
  711. prop->nametag = nametag;
  712. co->notifyObjectPropertiesModified();
  713. lua_pushboolean(L, true);
  714. return 1;
  715. }
  716. // get_nametag_attributes(self)
  717. int ObjectRef::l_get_nametag_attributes(lua_State *L)
  718. {
  719. NO_MAP_LOCK_REQUIRED;
  720. ObjectRef *ref = checkobject(L, 1);
  721. ServerActiveObject *co = getobject(ref);
  722. if (co == NULL)
  723. return 0;
  724. ObjectProperties *prop = co->accessObjectProperties();
  725. if (!prop)
  726. return 0;
  727. video::SColor color = prop->nametag_color;
  728. lua_newtable(L);
  729. push_ARGB8(L, color);
  730. lua_setfield(L, -2, "color");
  731. lua_pushstring(L, prop->nametag.c_str());
  732. lua_setfield(L, -2, "text");
  733. return 1;
  734. }
  735. /* LuaEntitySAO-only */
  736. // set_velocity(self, {x=num, y=num, z=num})
  737. int ObjectRef::l_set_velocity(lua_State *L)
  738. {
  739. NO_MAP_LOCK_REQUIRED;
  740. ObjectRef *ref = checkobject(L, 1);
  741. LuaEntitySAO *co = getluaobject(ref);
  742. if (co == NULL) return 0;
  743. v3f pos = checkFloatPos(L, 2);
  744. // Do it
  745. co->setVelocity(pos);
  746. return 0;
  747. }
  748. // add_velocity(self, {x=num, y=num, z=num})
  749. int ObjectRef::l_add_velocity(lua_State *L)
  750. {
  751. NO_MAP_LOCK_REQUIRED;
  752. ObjectRef *ref = checkobject(L, 1);
  753. LuaEntitySAO *co = getluaobject(ref);
  754. if (!co)
  755. return 0;
  756. v3f pos = checkFloatPos(L, 2);
  757. // Do it
  758. co->addVelocity(pos);
  759. return 0;
  760. }
  761. // get_velocity(self)
  762. int ObjectRef::l_get_velocity(lua_State *L)
  763. {
  764. NO_MAP_LOCK_REQUIRED;
  765. ObjectRef *ref = checkobject(L, 1);
  766. LuaEntitySAO *co = getluaobject(ref);
  767. if (co == NULL) return 0;
  768. // Do it
  769. v3f v = co->getVelocity();
  770. pushFloatPos(L, v);
  771. return 1;
  772. }
  773. // set_acceleration(self, {x=num, y=num, z=num})
  774. int ObjectRef::l_set_acceleration(lua_State *L)
  775. {
  776. NO_MAP_LOCK_REQUIRED;
  777. ObjectRef *ref = checkobject(L, 1);
  778. LuaEntitySAO *co = getluaobject(ref);
  779. if (co == NULL) return 0;
  780. // pos
  781. v3f pos = checkFloatPos(L, 2);
  782. // Do it
  783. co->setAcceleration(pos);
  784. return 0;
  785. }
  786. // get_acceleration(self)
  787. int ObjectRef::l_get_acceleration(lua_State *L)
  788. {
  789. NO_MAP_LOCK_REQUIRED;
  790. ObjectRef *ref = checkobject(L, 1);
  791. LuaEntitySAO *co = getluaobject(ref);
  792. if (co == NULL) return 0;
  793. // Do it
  794. v3f v = co->getAcceleration();
  795. pushFloatPos(L, v);
  796. return 1;
  797. }
  798. // set_yaw(self, radians)
  799. int ObjectRef::l_set_yaw(lua_State *L)
  800. {
  801. NO_MAP_LOCK_REQUIRED;
  802. ObjectRef *ref = checkobject(L, 1);
  803. LuaEntitySAO *co = getluaobject(ref);
  804. if (co == NULL) return 0;
  805. float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
  806. // Do it
  807. co->setYaw(yaw);
  808. return 0;
  809. }
  810. // get_yaw(self)
  811. int ObjectRef::l_get_yaw(lua_State *L)
  812. {
  813. NO_MAP_LOCK_REQUIRED;
  814. ObjectRef *ref = checkobject(L, 1);
  815. LuaEntitySAO *co = getluaobject(ref);
  816. if (co == NULL) return 0;
  817. // Do it
  818. float yaw = co->getYaw() * core::DEGTORAD;
  819. lua_pushnumber(L, yaw);
  820. return 1;
  821. }
  822. // set_texture_mod(self, mod)
  823. int ObjectRef::l_set_texture_mod(lua_State *L)
  824. {
  825. NO_MAP_LOCK_REQUIRED;
  826. ObjectRef *ref = checkobject(L, 1);
  827. LuaEntitySAO *co = getluaobject(ref);
  828. if (co == NULL) return 0;
  829. // Do it
  830. std::string mod = luaL_checkstring(L, 2);
  831. co->setTextureMod(mod);
  832. return 0;
  833. }
  834. // get_texture_mod(self)
  835. int ObjectRef::l_get_texture_mod(lua_State *L)
  836. {
  837. NO_MAP_LOCK_REQUIRED;
  838. ObjectRef *ref = checkobject(L, 1);
  839. LuaEntitySAO *co = getluaobject(ref);
  840. if (co == NULL) return 0;
  841. // Do it
  842. std::string mod = co->getTextureMod();
  843. lua_pushstring(L, mod.c_str());
  844. return 1;
  845. }
  846. // set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
  847. // select_horiz_by_yawpitch=false)
  848. int ObjectRef::l_set_sprite(lua_State *L)
  849. {
  850. NO_MAP_LOCK_REQUIRED;
  851. ObjectRef *ref = checkobject(L, 1);
  852. LuaEntitySAO *co = getluaobject(ref);
  853. if (co == NULL) return 0;
  854. // Do it
  855. v2s16 p(0,0);
  856. if (!lua_isnil(L, 2))
  857. p = read_v2s16(L, 2);
  858. int num_frames = 1;
  859. if (!lua_isnil(L, 3))
  860. num_frames = lua_tonumber(L, 3);
  861. float framelength = 0.2;
  862. if (!lua_isnil(L, 4))
  863. framelength = lua_tonumber(L, 4);
  864. bool select_horiz_by_yawpitch = false;
  865. if (!lua_isnil(L, 5))
  866. select_horiz_by_yawpitch = lua_toboolean(L, 5);
  867. co->setSprite(p, num_frames, framelength, select_horiz_by_yawpitch);
  868. return 0;
  869. }
  870. // DEPRECATED
  871. // get_entity_name(self)
  872. int ObjectRef::l_get_entity_name(lua_State *L)
  873. {
  874. NO_MAP_LOCK_REQUIRED;
  875. ObjectRef *ref = checkobject(L, 1);
  876. LuaEntitySAO *co = getluaobject(ref);
  877. log_deprecated(L,"Deprecated call to \"get_entity_name");
  878. if (co == NULL) return 0;
  879. // Do it
  880. std::string name = co->getName();
  881. lua_pushstring(L, name.c_str());
  882. return 1;
  883. }
  884. // get_luaentity(self)
  885. int ObjectRef::l_get_luaentity(lua_State *L)
  886. {
  887. NO_MAP_LOCK_REQUIRED;
  888. ObjectRef *ref = checkobject(L, 1);
  889. LuaEntitySAO *co = getluaobject(ref);
  890. if (co == NULL) return 0;
  891. // Do it
  892. luaentity_get(L, co->getId());
  893. return 1;
  894. }
  895. /* Player-only */
  896. // is_player_connected(self)
  897. int ObjectRef::l_is_player_connected(lua_State *L)
  898. {
  899. NO_MAP_LOCK_REQUIRED;
  900. ObjectRef *ref = checkobject(L, 1);
  901. RemotePlayer *player = getplayer(ref);
  902. lua_pushboolean(L, (player != NULL && player->getPeerId() != PEER_ID_INEXISTENT));
  903. return 1;
  904. }
  905. // get_player_name(self)
  906. int ObjectRef::l_get_player_name(lua_State *L)
  907. {
  908. NO_MAP_LOCK_REQUIRED;
  909. ObjectRef *ref = checkobject(L, 1);
  910. RemotePlayer *player = getplayer(ref);
  911. if (player == NULL) {
  912. lua_pushlstring(L, "", 0);
  913. return 1;
  914. }
  915. // Do it
  916. lua_pushstring(L, player->getName());
  917. return 1;
  918. }
  919. // get_player_velocity(self)
  920. int ObjectRef::l_get_player_velocity(lua_State *L)
  921. {
  922. NO_MAP_LOCK_REQUIRED;
  923. ObjectRef *ref = checkobject(L, 1);
  924. RemotePlayer *player = getplayer(ref);
  925. if (player == NULL) {
  926. lua_pushnil(L);
  927. return 1;
  928. }
  929. // Do it
  930. push_v3f(L, player->getSpeed() / BS);
  931. return 1;
  932. }
  933. // get_look_dir(self)
  934. int ObjectRef::l_get_look_dir(lua_State *L)
  935. {
  936. NO_MAP_LOCK_REQUIRED;
  937. ObjectRef *ref = checkobject(L, 1);
  938. PlayerSAO* co = getplayersao(ref);
  939. if (co == NULL) return 0;
  940. // Do it
  941. float pitch = co->getRadPitchDep();
  942. float yaw = co->getRadYawDep();
  943. v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), std::cos(pitch) *
  944. std::sin(yaw));
  945. push_v3f(L, v);
  946. return 1;
  947. }
  948. // DEPRECATED
  949. // get_look_pitch(self)
  950. int ObjectRef::l_get_look_pitch(lua_State *L)
  951. {
  952. NO_MAP_LOCK_REQUIRED;
  953. log_deprecated(L,
  954. "Deprecated call to get_look_pitch, use get_look_vertical instead");
  955. ObjectRef *ref = checkobject(L, 1);
  956. PlayerSAO* co = getplayersao(ref);
  957. if (co == NULL) return 0;
  958. // Do it
  959. lua_pushnumber(L, co->getRadPitchDep());
  960. return 1;
  961. }
  962. // DEPRECATED
  963. // get_look_yaw(self)
  964. int ObjectRef::l_get_look_yaw(lua_State *L)
  965. {
  966. NO_MAP_LOCK_REQUIRED;
  967. log_deprecated(L,
  968. "Deprecated call to get_look_yaw, use get_look_horizontal instead");
  969. ObjectRef *ref = checkobject(L, 1);
  970. PlayerSAO* co = getplayersao(ref);
  971. if (co == NULL) return 0;
  972. // Do it
  973. lua_pushnumber(L, co->getRadYawDep());
  974. return 1;
  975. }
  976. // get_look_pitch2(self)
  977. int ObjectRef::l_get_look_vertical(lua_State *L)
  978. {
  979. NO_MAP_LOCK_REQUIRED;
  980. ObjectRef *ref = checkobject(L, 1);
  981. PlayerSAO* co = getplayersao(ref);
  982. if (co == NULL) return 0;
  983. // Do it
  984. lua_pushnumber(L, co->getRadPitch());
  985. return 1;
  986. }
  987. // get_look_yaw2(self)
  988. int ObjectRef::l_get_look_horizontal(lua_State *L)
  989. {
  990. NO_MAP_LOCK_REQUIRED;
  991. ObjectRef *ref = checkobject(L, 1);
  992. PlayerSAO* co = getplayersao(ref);
  993. if (co == NULL) return 0;
  994. // Do it
  995. lua_pushnumber(L, co->getRadYaw());
  996. return 1;
  997. }
  998. // set_look_vertical(self, radians)
  999. int ObjectRef::l_set_look_vertical(lua_State *L)
  1000. {
  1001. NO_MAP_LOCK_REQUIRED;
  1002. ObjectRef *ref = checkobject(L, 1);
  1003. PlayerSAO* co = getplayersao(ref);
  1004. if (co == NULL) return 0;
  1005. float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
  1006. // Do it
  1007. co->setPitchAndSend(pitch);
  1008. return 1;
  1009. }
  1010. // set_look_horizontal(self, radians)
  1011. int ObjectRef::l_set_look_horizontal(lua_State *L)
  1012. {
  1013. NO_MAP_LOCK_REQUIRED;
  1014. ObjectRef *ref = checkobject(L, 1);
  1015. PlayerSAO* co = getplayersao(ref);
  1016. if (co == NULL) return 0;
  1017. float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
  1018. // Do it
  1019. co->setYawAndSend(yaw);
  1020. return 1;
  1021. }
  1022. // DEPRECATED
  1023. // set_look_pitch(self, radians)
  1024. int ObjectRef::l_set_look_pitch(lua_State *L)
  1025. {
  1026. NO_MAP_LOCK_REQUIRED;
  1027. log_deprecated(L,
  1028. "Deprecated call to set_look_pitch, use set_look_vertical instead.");
  1029. ObjectRef *ref = checkobject(L, 1);
  1030. PlayerSAO* co = getplayersao(ref);
  1031. if (co == NULL) return 0;
  1032. float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
  1033. // Do it
  1034. co->setPitchAndSend(pitch);
  1035. return 1;
  1036. }
  1037. // DEPRECATED
  1038. // set_look_yaw(self, radians)
  1039. int ObjectRef::l_set_look_yaw(lua_State *L)
  1040. {
  1041. NO_MAP_LOCK_REQUIRED;
  1042. log_deprecated(L,
  1043. "Deprecated call to set_look_yaw, use set_look_horizontal instead.");
  1044. ObjectRef *ref = checkobject(L, 1);
  1045. PlayerSAO* co = getplayersao(ref);
  1046. if (co == NULL) return 0;
  1047. float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
  1048. // Do it
  1049. co->setYawAndSend(yaw);
  1050. return 1;
  1051. }
  1052. // set_breath(self, breath)
  1053. int ObjectRef::l_set_breath(lua_State *L)
  1054. {
  1055. NO_MAP_LOCK_REQUIRED;
  1056. ObjectRef *ref = checkobject(L, 1);
  1057. PlayerSAO* co = getplayersao(ref);
  1058. if (co == NULL) return 0;
  1059. u16 breath = luaL_checknumber(L, 2);
  1060. co->setBreath(breath);
  1061. return 0;
  1062. }
  1063. // get_breath(self)
  1064. int ObjectRef::l_get_breath(lua_State *L)
  1065. {
  1066. NO_MAP_LOCK_REQUIRED;
  1067. ObjectRef *ref = checkobject(L, 1);
  1068. PlayerSAO* co = getplayersao(ref);
  1069. if (co == NULL) return 0;
  1070. // Do it
  1071. u16 breath = co->getBreath();
  1072. lua_pushinteger (L, breath);
  1073. return 1;
  1074. }
  1075. // set_attribute(self, attribute, value)
  1076. int ObjectRef::l_set_attribute(lua_State *L)
  1077. {
  1078. ObjectRef *ref = checkobject(L, 1);
  1079. PlayerSAO* co = getplayersao(ref);
  1080. if (co == NULL)
  1081. return 0;
  1082. std::string attr = luaL_checkstring(L, 2);
  1083. if (lua_isnil(L, 3)) {
  1084. co->getMeta().removeString(attr);
  1085. } else {
  1086. std::string value = luaL_checkstring(L, 3);
  1087. co->getMeta().setString(attr, value);
  1088. }
  1089. return 1;
  1090. }
  1091. // get_attribute(self, attribute)
  1092. int ObjectRef::l_get_attribute(lua_State *L)
  1093. {
  1094. ObjectRef *ref = checkobject(L, 1);
  1095. PlayerSAO* co = getplayersao(ref);
  1096. if (co == NULL)
  1097. return 0;
  1098. std::string attr = luaL_checkstring(L, 2);
  1099. std::string value;
  1100. if (co->getMeta().getStringToRef(attr, value)) {
  1101. lua_pushstring(L, value.c_str());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. // get_meta(self, attribute)
  1107. int ObjectRef::l_get_meta(lua_State *L)
  1108. {
  1109. ObjectRef *ref = checkobject(L, 1);
  1110. PlayerSAO *co = getplayersao(ref);
  1111. if (co == NULL)
  1112. return 0;
  1113. PlayerMetaRef::create(L, &co->getMeta());
  1114. return 1;
  1115. }
  1116. // set_inventory_formspec(self, formspec)
  1117. int ObjectRef::l_set_inventory_formspec(lua_State *L)
  1118. {
  1119. NO_MAP_LOCK_REQUIRED;
  1120. ObjectRef *ref = checkobject(L, 1);
  1121. RemotePlayer *player = getplayer(ref);
  1122. if (player == NULL) return 0;
  1123. std::string formspec = luaL_checkstring(L, 2);
  1124. player->inventory_formspec = formspec;
  1125. getServer(L)->reportInventoryFormspecModified(player->getName());
  1126. lua_pushboolean(L, true);
  1127. return 1;
  1128. }
  1129. // get_inventory_formspec(self) -> formspec
  1130. int ObjectRef::l_get_inventory_formspec(lua_State *L)
  1131. {
  1132. NO_MAP_LOCK_REQUIRED;
  1133. ObjectRef *ref = checkobject(L, 1);
  1134. RemotePlayer *player = getplayer(ref);
  1135. if (player == NULL) return 0;
  1136. std::string formspec = player->inventory_formspec;
  1137. lua_pushlstring(L, formspec.c_str(), formspec.size());
  1138. return 1;
  1139. }
  1140. // set_formspec_prepend(self, formspec)
  1141. int ObjectRef::l_set_formspec_prepend(lua_State *L)
  1142. {
  1143. NO_MAP_LOCK_REQUIRED;
  1144. ObjectRef *ref = checkobject(L, 1);
  1145. RemotePlayer *player = getplayer(ref);
  1146. if (player == NULL)
  1147. return 0;
  1148. std::string formspec = luaL_checkstring(L, 2);
  1149. player->formspec_prepend = formspec;
  1150. getServer(L)->reportFormspecPrependModified(player->getName());
  1151. lua_pushboolean(L, true);
  1152. return 1;
  1153. }
  1154. // get_formspec_prepend(self) -> formspec
  1155. int ObjectRef::l_get_formspec_prepend(lua_State *L)
  1156. {
  1157. NO_MAP_LOCK_REQUIRED;
  1158. ObjectRef *ref = checkobject(L, 1);
  1159. RemotePlayer *player = getplayer(ref);
  1160. if (player == NULL)
  1161. return 0;
  1162. std::string formspec = player->formspec_prepend;
  1163. lua_pushlstring(L, formspec.c_str(), formspec.size());
  1164. return 1;
  1165. }
  1166. // get_player_control(self)
  1167. int ObjectRef::l_get_player_control(lua_State *L)
  1168. {
  1169. NO_MAP_LOCK_REQUIRED;
  1170. ObjectRef *ref = checkobject(L, 1);
  1171. RemotePlayer *player = getplayer(ref);
  1172. if (player == NULL) {
  1173. lua_pushlstring(L, "", 0);
  1174. return 1;
  1175. }
  1176. const PlayerControl &control = player->getPlayerControl();
  1177. lua_newtable(L);
  1178. lua_pushboolean(L, control.up);
  1179. lua_setfield(L, -2, "up");
  1180. lua_pushboolean(L, control.down);
  1181. lua_setfield(L, -2, "down");
  1182. lua_pushboolean(L, control.left);
  1183. lua_setfield(L, -2, "left");
  1184. lua_pushboolean(L, control.right);
  1185. lua_setfield(L, -2, "right");
  1186. lua_pushboolean(L, control.jump);
  1187. lua_setfield(L, -2, "jump");
  1188. lua_pushboolean(L, control.aux1);
  1189. lua_setfield(L, -2, "aux1");
  1190. lua_pushboolean(L, control.sneak);
  1191. lua_setfield(L, -2, "sneak");
  1192. lua_pushboolean(L, control.LMB);
  1193. lua_setfield(L, -2, "LMB");
  1194. lua_pushboolean(L, control.RMB);
  1195. lua_setfield(L, -2, "RMB");
  1196. return 1;
  1197. }
  1198. // get_player_control_bits(self)
  1199. int ObjectRef::l_get_player_control_bits(lua_State *L)
  1200. {
  1201. NO_MAP_LOCK_REQUIRED;
  1202. ObjectRef *ref = checkobject(L, 1);
  1203. RemotePlayer *player = getplayer(ref);
  1204. if (player == NULL) {
  1205. lua_pushlstring(L, "", 0);
  1206. return 1;
  1207. }
  1208. // Do it
  1209. lua_pushnumber(L, player->keyPressed);
  1210. return 1;
  1211. }
  1212. // hud_add(self, form)
  1213. int ObjectRef::l_hud_add(lua_State *L)
  1214. {
  1215. NO_MAP_LOCK_REQUIRED;
  1216. ObjectRef *ref = checkobject(L, 1);
  1217. RemotePlayer *player = getplayer(ref);
  1218. if (player == NULL)
  1219. return 0;
  1220. HudElement *elem = new HudElement;
  1221. read_hud_element(L, elem);
  1222. u32 id = getServer(L)->hudAdd(player, elem);
  1223. if (id == U32_MAX) {
  1224. delete elem;
  1225. return 0;
  1226. }
  1227. lua_pushnumber(L, id);
  1228. return 1;
  1229. }
  1230. // hud_remove(self, id)
  1231. int ObjectRef::l_hud_remove(lua_State *L)
  1232. {
  1233. NO_MAP_LOCK_REQUIRED;
  1234. ObjectRef *ref = checkobject(L, 1);
  1235. RemotePlayer *player = getplayer(ref);
  1236. if (player == NULL)
  1237. return 0;
  1238. u32 id = -1;
  1239. if (!lua_isnil(L, 2))
  1240. id = lua_tonumber(L, 2);
  1241. if (!getServer(L)->hudRemove(player, id))
  1242. return 0;
  1243. lua_pushboolean(L, true);
  1244. return 1;
  1245. }
  1246. // hud_change(self, id, stat, data)
  1247. int ObjectRef::l_hud_change(lua_State *L)
  1248. {
  1249. NO_MAP_LOCK_REQUIRED;
  1250. ObjectRef *ref = checkobject(L, 1);
  1251. RemotePlayer *player = getplayer(ref);
  1252. if (player == NULL)
  1253. return 0;
  1254. u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1;
  1255. HudElement *e = player->getHud(id);
  1256. if (!e)
  1257. return 0;
  1258. void *value = NULL;
  1259. HudElementStat stat = read_hud_change(L, e, &value);
  1260. getServer(L)->hudChange(player, id, stat, value);
  1261. lua_pushboolean(L, true);
  1262. return 1;
  1263. }
  1264. // hud_get(self, id)
  1265. int ObjectRef::l_hud_get(lua_State *L)
  1266. {
  1267. NO_MAP_LOCK_REQUIRED;
  1268. ObjectRef *ref = checkobject(L, 1);
  1269. RemotePlayer *player = getplayer(ref);
  1270. if (player == NULL)
  1271. return 0;
  1272. u32 id = lua_tonumber(L, -1);
  1273. HudElement *e = player->getHud(id);
  1274. if (!e)
  1275. return 0;
  1276. push_hud_element(L, e);
  1277. return 1;
  1278. }
  1279. // hud_set_flags(self, flags)
  1280. int ObjectRef::l_hud_set_flags(lua_State *L)
  1281. {
  1282. NO_MAP_LOCK_REQUIRED;
  1283. ObjectRef *ref = checkobject(L, 1);
  1284. RemotePlayer *player = getplayer(ref);
  1285. if (player == NULL)
  1286. return 0;
  1287. u32 flags = 0;
  1288. u32 mask = 0;
  1289. bool flag;
  1290. const EnumString *esp = es_HudBuiltinElement;
  1291. for (int i = 0; esp[i].str; i++) {
  1292. if (getboolfield(L, 2, esp[i].str, flag)) {
  1293. flags |= esp[i].num * flag;
  1294. mask |= esp[i].num;
  1295. }
  1296. }
  1297. if (!getServer(L)->hudSetFlags(player, flags, mask))
  1298. return 0;
  1299. lua_pushboolean(L, true);
  1300. return 1;
  1301. }
  1302. int ObjectRef::l_hud_get_flags(lua_State *L)
  1303. {
  1304. NO_MAP_LOCK_REQUIRED;
  1305. ObjectRef *ref = checkobject(L, 1);
  1306. RemotePlayer *player = getplayer(ref);
  1307. if (player == NULL)
  1308. return 0;
  1309. lua_newtable(L);
  1310. lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
  1311. lua_setfield(L, -2, "hotbar");
  1312. lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
  1313. lua_setfield(L, -2, "healthbar");
  1314. lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
  1315. lua_setfield(L, -2, "crosshair");
  1316. lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
  1317. lua_setfield(L, -2, "wielditem");
  1318. lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
  1319. lua_setfield(L, -2, "breathbar");
  1320. lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
  1321. lua_setfield(L, -2, "minimap");
  1322. lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE);
  1323. lua_setfield(L, -2, "minimap_radar");
  1324. return 1;
  1325. }
  1326. // hud_set_hotbar_itemcount(self, hotbar_itemcount)
  1327. int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
  1328. {
  1329. NO_MAP_LOCK_REQUIRED;
  1330. ObjectRef *ref = checkobject(L, 1);
  1331. RemotePlayer *player = getplayer(ref);
  1332. if (player == NULL)
  1333. return 0;
  1334. s32 hotbar_itemcount = lua_tonumber(L, 2);
  1335. if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
  1336. return 0;
  1337. lua_pushboolean(L, true);
  1338. return 1;
  1339. }
  1340. // hud_get_hotbar_itemcount(self)
  1341. int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
  1342. {
  1343. NO_MAP_LOCK_REQUIRED;
  1344. ObjectRef *ref = checkobject(L, 1);
  1345. RemotePlayer *player = getplayer(ref);
  1346. if (player == NULL)
  1347. return 0;
  1348. lua_pushnumber(L, player->getHotbarItemcount());
  1349. return 1;
  1350. }
  1351. // hud_set_hotbar_image(self, name)
  1352. int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
  1353. {
  1354. NO_MAP_LOCK_REQUIRED;
  1355. ObjectRef *ref = checkobject(L, 1);
  1356. RemotePlayer *player = getplayer(ref);
  1357. if (player == NULL)
  1358. return 0;
  1359. std::string name = lua_tostring(L, 2);
  1360. getServer(L)->hudSetHotbarImage(player, name);
  1361. return 1;
  1362. }
  1363. // hud_get_hotbar_image(self)
  1364. int ObjectRef::l_hud_get_hotbar_image(lua_State *L)
  1365. {
  1366. NO_MAP_LOCK_REQUIRED;
  1367. ObjectRef *ref = checkobject(L, 1);
  1368. RemotePlayer *player = getplayer(ref);
  1369. if (player == NULL)
  1370. return 0;
  1371. const std::string &name = player->getHotbarImage();
  1372. lua_pushlstring(L, name.c_str(), name.size());
  1373. return 1;
  1374. }
  1375. // hud_set_hotbar_selected_image(self, name)
  1376. int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
  1377. {
  1378. NO_MAP_LOCK_REQUIRED;
  1379. ObjectRef *ref = checkobject(L, 1);
  1380. RemotePlayer *player = getplayer(ref);
  1381. if (player == NULL)
  1382. return 0;
  1383. std::string name = lua_tostring(L, 2);
  1384. getServer(L)->hudSetHotbarSelectedImage(player, name);
  1385. return 1;
  1386. }
  1387. // hud_get_hotbar_selected_image(self)
  1388. int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
  1389. {
  1390. NO_MAP_LOCK_REQUIRED;
  1391. ObjectRef *ref = checkobject(L, 1);
  1392. RemotePlayer *player = getplayer(ref);
  1393. if (player == NULL)
  1394. return 0;
  1395. const std::string &name = player->getHotbarSelectedImage();
  1396. lua_pushlstring(L, name.c_str(), name.size());
  1397. return 1;
  1398. }
  1399. // set_sky(self, bgcolor, type, list, clouds = true)
  1400. int ObjectRef::l_set_sky(lua_State *L)
  1401. {
  1402. NO_MAP_LOCK_REQUIRED;
  1403. ObjectRef *ref = checkobject(L, 1);
  1404. RemotePlayer *player = getplayer(ref);
  1405. if (player == NULL)
  1406. return 0;
  1407. video::SColor bgcolor(255,255,255,255);
  1408. read_color(L, 2, &bgcolor);
  1409. std::string type = luaL_checkstring(L, 3);
  1410. std::vector<std::string> params;
  1411. if (lua_istable(L, 4)) {
  1412. lua_pushnil(L);
  1413. while (lua_next(L, 4) != 0) {
  1414. // key at index -2 and value at index -1
  1415. if (lua_isstring(L, -1))
  1416. params.emplace_back(lua_tostring(L, -1));
  1417. else
  1418. params.emplace_back("");
  1419. // removes value, keeps key for next iteration
  1420. lua_pop(L, 1);
  1421. }
  1422. }
  1423. if (type == "skybox" && params.size() != 6)
  1424. throw LuaError("skybox expects 6 textures");
  1425. bool clouds = true;
  1426. if (lua_isboolean(L, 5))
  1427. clouds = lua_toboolean(L, 5);
  1428. getServer(L)->setSky(player, bgcolor, type, params, clouds);
  1429. lua_pushboolean(L, true);
  1430. return 1;
  1431. }
  1432. // get_sky(self)
  1433. int ObjectRef::l_get_sky(lua_State *L)
  1434. {
  1435. NO_MAP_LOCK_REQUIRED;
  1436. ObjectRef *ref = checkobject(L, 1);
  1437. RemotePlayer *player = getplayer(ref);
  1438. if (player == NULL)
  1439. return 0;
  1440. video::SColor bgcolor(255, 255, 255, 255);
  1441. std::string type;
  1442. std::vector<std::string> params;
  1443. bool clouds;
  1444. player->getSky(&bgcolor, &type, &params, &clouds);
  1445. type = type.empty() ? "regular" : type;
  1446. push_ARGB8(L, bgcolor);
  1447. lua_pushlstring(L, type.c_str(), type.size());
  1448. lua_newtable(L);
  1449. s16 i = 1;
  1450. for (const std::string &param : params) {
  1451. lua_pushlstring(L, param.c_str(), param.size());
  1452. lua_rawseti(L, -2, i);
  1453. i++;
  1454. }
  1455. lua_pushboolean(L, clouds);
  1456. return 4;
  1457. }
  1458. // set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})
  1459. int ObjectRef::l_set_clouds(lua_State *L)
  1460. {
  1461. NO_MAP_LOCK_REQUIRED;
  1462. ObjectRef *ref = checkobject(L, 1);
  1463. RemotePlayer *player = getplayer(ref);
  1464. if (!player)
  1465. return 0;
  1466. if (!lua_istable(L, 2))
  1467. return 0;
  1468. CloudParams cloud_params = player->getCloudParams();
  1469. cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
  1470. lua_getfield(L, 2, "color");
  1471. if (!lua_isnil(L, -1))
  1472. read_color(L, -1, &cloud_params.color_bright);
  1473. lua_pop(L, 1);
  1474. lua_getfield(L, 2, "ambient");
  1475. if (!lua_isnil(L, -1))
  1476. read_color(L, -1, &cloud_params.color_ambient);
  1477. lua_pop(L, 1);
  1478. cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height );
  1479. cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness);
  1480. lua_getfield(L, 2, "speed");
  1481. if (lua_istable(L, -1)) {
  1482. v2f new_speed;
  1483. new_speed.X = getfloatfield_default(L, -1, "x", 0);
  1484. new_speed.Y = getfloatfield_default(L, -1, "z", 0);
  1485. cloud_params.speed = new_speed;
  1486. }
  1487. lua_pop(L, 1);
  1488. getServer(L)->setClouds(player, cloud_params);
  1489. lua_pushboolean(L, true);
  1490. return 1;
  1491. }
  1492. int ObjectRef::l_get_clouds(lua_State *L)
  1493. {
  1494. NO_MAP_LOCK_REQUIRED;
  1495. ObjectRef *ref = checkobject(L, 1);
  1496. RemotePlayer *player = getplayer(ref);
  1497. if (!player)
  1498. return 0;
  1499. const CloudParams &cloud_params = player->getCloudParams();
  1500. lua_newtable(L);
  1501. lua_pushnumber(L, cloud_params.density);
  1502. lua_setfield(L, -2, "density");
  1503. push_ARGB8(L, cloud_params.color_bright);
  1504. lua_setfield(L, -2, "color");
  1505. push_ARGB8(L, cloud_params.color_ambient);
  1506. lua_setfield(L, -2, "ambient");
  1507. lua_pushnumber(L, cloud_params.height);
  1508. lua_setfield(L, -2, "height");
  1509. lua_pushnumber(L, cloud_params.thickness);
  1510. lua_setfield(L, -2, "thickness");
  1511. lua_newtable(L);
  1512. lua_pushnumber(L, cloud_params.speed.X);
  1513. lua_setfield(L, -2, "x");
  1514. lua_pushnumber(L, cloud_params.speed.Y);
  1515. lua_setfield(L, -2, "y");
  1516. lua_setfield(L, -2, "speed");
  1517. return 1;
  1518. }
  1519. // override_day_night_ratio(self, brightness=0...1)
  1520. int ObjectRef::l_override_day_night_ratio(lua_State *L)
  1521. {
  1522. NO_MAP_LOCK_REQUIRED;
  1523. ObjectRef *ref = checkobject(L, 1);
  1524. RemotePlayer *player = getplayer(ref);
  1525. if (player == NULL)
  1526. return 0;
  1527. bool do_override = false;
  1528. float ratio = 0.0f;
  1529. if (!lua_isnil(L, 2)) {
  1530. do_override = true;
  1531. ratio = luaL_checknumber(L, 2);
  1532. }
  1533. if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio))
  1534. return 0;
  1535. lua_pushboolean(L, true);
  1536. return 1;
  1537. }
  1538. // get_day_night_ratio(self)
  1539. int ObjectRef::l_get_day_night_ratio(lua_State *L)
  1540. {
  1541. NO_MAP_LOCK_REQUIRED;
  1542. ObjectRef *ref = checkobject(L, 1);
  1543. RemotePlayer *player = getplayer(ref);
  1544. if (player == NULL)
  1545. return 0;
  1546. bool do_override;
  1547. float ratio;
  1548. player->getDayNightRatio(&do_override, &ratio);
  1549. if (do_override)
  1550. lua_pushnumber(L, ratio);
  1551. else
  1552. lua_pushnil(L);
  1553. return 1;
  1554. }
  1555. ObjectRef::ObjectRef(ServerActiveObject *object):
  1556. m_object(object)
  1557. {
  1558. //infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl;
  1559. }
  1560. // Creates an ObjectRef and leaves it on top of stack
  1561. // Not callable from Lua; all references are created on the C side.
  1562. void ObjectRef::create(lua_State *L, ServerActiveObject *object)
  1563. {
  1564. ObjectRef *o = new ObjectRef(object);
  1565. //infostream<<"ObjectRef::create: o="<<o<<std::endl;
  1566. *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
  1567. luaL_getmetatable(L, className);
  1568. lua_setmetatable(L, -2);
  1569. }
  1570. void ObjectRef::set_null(lua_State *L)
  1571. {
  1572. ObjectRef *o = checkobject(L, -1);
  1573. o->m_object = NULL;
  1574. }
  1575. void ObjectRef::Register(lua_State *L)
  1576. {
  1577. lua_newtable(L);
  1578. int methodtable = lua_gettop(L);
  1579. luaL_newmetatable(L, className);
  1580. int metatable = lua_gettop(L);
  1581. lua_pushliteral(L, "__metatable");
  1582. lua_pushvalue(L, methodtable);
  1583. lua_settable(L, metatable); // hide metatable from Lua getmetatable()
  1584. lua_pushliteral(L, "__index");
  1585. lua_pushvalue(L, methodtable);
  1586. lua_settable(L, metatable);
  1587. lua_pushliteral(L, "__gc");
  1588. lua_pushcfunction(L, gc_object);
  1589. lua_settable(L, metatable);
  1590. lua_pop(L, 1); // drop metatable
  1591. luaL_openlib(L, 0, methods, 0); // fill methodtable
  1592. lua_pop(L, 1); // drop methodtable
  1593. // Cannot be created from Lua
  1594. //lua_register(L, className, create_object);
  1595. }
  1596. const char ObjectRef::className[] = "ObjectRef";
  1597. const luaL_Reg ObjectRef::methods[] = {
  1598. // ServerActiveObject
  1599. luamethod(ObjectRef, remove),
  1600. luamethod_aliased(ObjectRef, get_pos, getpos),
  1601. luamethod_aliased(ObjectRef, set_pos, setpos),
  1602. luamethod_aliased(ObjectRef, move_to, moveto),
  1603. luamethod(ObjectRef, punch),
  1604. luamethod(ObjectRef, right_click),
  1605. luamethod(ObjectRef, set_hp),
  1606. luamethod(ObjectRef, get_hp),
  1607. luamethod(ObjectRef, get_inventory),
  1608. luamethod(ObjectRef, get_wield_list),
  1609. luamethod(ObjectRef, get_wield_index),
  1610. luamethod(ObjectRef, get_wielded_item),
  1611. luamethod(ObjectRef, set_wielded_item),
  1612. luamethod(ObjectRef, set_armor_groups),
  1613. luamethod(ObjectRef, get_armor_groups),
  1614. luamethod(ObjectRef, set_animation),
  1615. luamethod(ObjectRef, get_animation),
  1616. luamethod(ObjectRef, set_animation_frame_speed),
  1617. luamethod(ObjectRef, set_bone_position),
  1618. luamethod(ObjectRef, get_bone_position),
  1619. luamethod(ObjectRef, set_attach),
  1620. luamethod(ObjectRef, get_attach),
  1621. luamethod(ObjectRef, set_detach),
  1622. luamethod(ObjectRef, set_properties),
  1623. luamethod(ObjectRef, get_properties),
  1624. luamethod(ObjectRef, set_nametag_attributes),
  1625. luamethod(ObjectRef, get_nametag_attributes),
  1626. // LuaEntitySAO-only
  1627. luamethod_aliased(ObjectRef, set_velocity, setvelocity),
  1628. luamethod(ObjectRef, add_velocity),
  1629. luamethod_aliased(ObjectRef, get_velocity, getvelocity),
  1630. luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
  1631. luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
  1632. luamethod_aliased(ObjectRef, set_yaw, setyaw),
  1633. luamethod_aliased(ObjectRef, get_yaw, getyaw),
  1634. luamethod_aliased(ObjectRef, set_texture_mod, settexturemod),
  1635. luamethod_aliased(ObjectRef, set_sprite, setsprite),
  1636. luamethod(ObjectRef, get_entity_name),
  1637. luamethod(ObjectRef, get_luaentity),
  1638. // Player-only
  1639. luamethod(ObjectRef, is_player),
  1640. luamethod(ObjectRef, is_player_connected),
  1641. luamethod(ObjectRef, get_player_name),
  1642. luamethod(ObjectRef, get_player_velocity),
  1643. luamethod(ObjectRef, get_look_dir),
  1644. luamethod(ObjectRef, get_look_pitch),
  1645. luamethod(ObjectRef, get_look_yaw),
  1646. luamethod(ObjectRef, get_look_vertical),
  1647. luamethod(ObjectRef, get_look_horizontal),
  1648. luamethod(ObjectRef, set_look_horizontal),
  1649. luamethod(ObjectRef, set_look_vertical),
  1650. luamethod(ObjectRef, set_look_yaw),
  1651. luamethod(ObjectRef, set_look_pitch),
  1652. luamethod(ObjectRef, get_breath),
  1653. luamethod(ObjectRef, set_breath),
  1654. luamethod(ObjectRef, get_attribute),
  1655. luamethod(ObjectRef, set_attribute),
  1656. luamethod(ObjectRef, get_meta),
  1657. luamethod(ObjectRef, set_inventory_formspec),
  1658. luamethod(ObjectRef, get_inventory_formspec),
  1659. luamethod(ObjectRef, set_formspec_prepend),
  1660. luamethod(ObjectRef, get_formspec_prepend),
  1661. luamethod(ObjectRef, get_player_control),
  1662. luamethod(ObjectRef, get_player_control_bits),
  1663. luamethod(ObjectRef, set_physics_override),
  1664. luamethod(ObjectRef, get_physics_override),
  1665. luamethod(ObjectRef, hud_add),
  1666. luamethod(ObjectRef, hud_remove),
  1667. luamethod(ObjectRef, hud_change),
  1668. luamethod(ObjectRef, hud_get),
  1669. luamethod(ObjectRef, hud_set_flags),
  1670. luamethod(ObjectRef, hud_get_flags),
  1671. luamethod(ObjectRef, hud_set_hotbar_itemcount),
  1672. luamethod(ObjectRef, hud_get_hotbar_itemcount),
  1673. luamethod(ObjectRef, hud_set_hotbar_image),
  1674. luamethod(ObjectRef, hud_get_hotbar_image),
  1675. luamethod(ObjectRef, hud_set_hotbar_selected_image),
  1676. luamethod(ObjectRef, hud_get_hotbar_selected_image),
  1677. luamethod(ObjectRef, set_sky),
  1678. luamethod(ObjectRef, get_sky),
  1679. luamethod(ObjectRef, set_clouds),
  1680. luamethod(ObjectRef, get_clouds),
  1681. luamethod(ObjectRef, override_day_night_ratio),
  1682. luamethod(ObjectRef, get_day_night_ratio),
  1683. luamethod(ObjectRef, set_local_animation),
  1684. luamethod(ObjectRef, get_local_animation),
  1685. luamethod(ObjectRef, set_eye_offset),
  1686. luamethod(ObjectRef, get_eye_offset),
  1687. {0,0}
  1688. };