l_object.cpp 45 KB

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