You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1333 lines
36 KiB

  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_env.h"
  17. #include "lua_api/l_internal.h"
  18. #include "lua_api/l_nodemeta.h"
  19. #include "lua_api/l_nodetimer.h"
  20. #include "lua_api/l_noise.h"
  21. #include "lua_api/l_vmanip.h"
  22. #include "common/c_converter.h"
  23. #include "common/c_content.h"
  24. #include <algorithm>
  25. #include "scripting_server.h"
  26. #include "environment.h"
  27. #include "mapblock.h"
  28. #include "server.h"
  29. #include "nodedef.h"
  30. #include "daynightratio.h"
  31. #include "util/pointedthing.h"
  32. #include "content_sao.h"
  33. #include "treegen.h"
  34. #include "emerge.h"
  35. #include "pathfinder.h"
  36. #include "face_position_cache.h"
  37. #include "remoteplayer.h"
  38. #ifndef SERVER
  39. #include "client.h"
  40. #endif
  41. struct EnumString ModApiEnvMod::es_ClearObjectsMode[] =
  42. {
  43. {CLEAR_OBJECTS_MODE_FULL, "full"},
  44. {CLEAR_OBJECTS_MODE_QUICK, "quick"},
  45. {0, NULL},
  46. };
  47. ///////////////////////////////////////////////////////////////////////////////
  48. void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
  49. u32 active_object_count, u32 active_object_count_wider)
  50. {
  51. ServerScripting *scriptIface = env->getScriptIface();
  52. scriptIface->realityCheck();
  53. lua_State *L = scriptIface->getStack();
  54. sanity_check(lua_checkstack(L, 20));
  55. StackUnroller stack_unroller(L);
  56. int error_handler = PUSH_ERROR_HANDLER(L);
  57. // Get registered_abms
  58. lua_getglobal(L, "core");
  59. lua_getfield(L, -1, "registered_abms");
  60. luaL_checktype(L, -1, LUA_TTABLE);
  61. lua_remove(L, -2); // Remove core
  62. // Get registered_abms[m_id]
  63. lua_pushnumber(L, m_id);
  64. lua_gettable(L, -2);
  65. if(lua_isnil(L, -1))
  66. FATAL_ERROR("");
  67. lua_remove(L, -2); // Remove registered_abms
  68. scriptIface->setOriginFromTable(-1);
  69. // Call action
  70. luaL_checktype(L, -1, LUA_TTABLE);
  71. lua_getfield(L, -1, "action");
  72. luaL_checktype(L, -1, LUA_TFUNCTION);
  73. lua_remove(L, -2); // Remove registered_abms[m_id]
  74. push_v3s16(L, p);
  75. pushnode(L, n, env->getGameDef()->ndef());
  76. lua_pushnumber(L, active_object_count);
  77. lua_pushnumber(L, active_object_count_wider);
  78. int result = lua_pcall(L, 4, 0, error_handler);
  79. if (result)
  80. scriptIface->scriptError(result, "LuaABM::trigger");
  81. lua_pop(L, 1); // Pop error handler
  82. }
  83. void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
  84. {
  85. ServerScripting *scriptIface = env->getScriptIface();
  86. scriptIface->realityCheck();
  87. lua_State *L = scriptIface->getStack();
  88. sanity_check(lua_checkstack(L, 20));
  89. StackUnroller stack_unroller(L);
  90. int error_handler = PUSH_ERROR_HANDLER(L);
  91. // Get registered_lbms
  92. lua_getglobal(L, "core");
  93. lua_getfield(L, -1, "registered_lbms");
  94. luaL_checktype(L, -1, LUA_TTABLE);
  95. lua_remove(L, -2); // Remove core
  96. // Get registered_lbms[m_id]
  97. lua_pushnumber(L, m_id);
  98. lua_gettable(L, -2);
  99. FATAL_ERROR_IF(lua_isnil(L, -1), "Entry with given id not found in registered_lbms table");
  100. lua_remove(L, -2); // Remove registered_lbms
  101. scriptIface->setOriginFromTable(-1);
  102. // Call action
  103. luaL_checktype(L, -1, LUA_TTABLE);
  104. lua_getfield(L, -1, "action");
  105. luaL_checktype(L, -1, LUA_TFUNCTION);
  106. lua_remove(L, -2); // Remove registered_lbms[m_id]
  107. push_v3s16(L, p);
  108. pushnode(L, n, env->getGameDef()->ndef());
  109. int result = lua_pcall(L, 2, 0, error_handler);
  110. if (result)
  111. scriptIface->scriptError(result, "LuaLBM::trigger");
  112. lua_pop(L, 1); // Pop error handler
  113. }
  114. int LuaRaycast::l_next(lua_State *L)
  115. {
  116. MAP_LOCK_REQUIRED;
  117. ScriptApiItem *script = getScriptApi<ScriptApiItem>(L);
  118. GET_ENV_PTR;
  119. LuaRaycast *o = checkobject(L, 1);
  120. PointedThing pointed;
  121. env->continueRaycast(&o->state, &pointed);
  122. if (pointed.type == POINTEDTHING_NOTHING)
  123. lua_pushnil(L);
  124. else
  125. script->pushPointedThing(pointed);
  126. return 1;
  127. }
  128. int LuaRaycast::create_object(lua_State *L)
  129. {
  130. NO_MAP_LOCK_REQUIRED;
  131. bool objects = true;
  132. bool liquids = false;
  133. v3f pos1 = checkFloatPos(L, 1);
  134. v3f pos2 = checkFloatPos(L, 2);
  135. if (lua_isboolean(L, 3)) {
  136. objects = readParam<bool>(L, 3);
  137. }
  138. if (lua_isboolean(L, 4)) {
  139. liquids = readParam<bool>(L, 4);
  140. }
  141. LuaRaycast *o = new LuaRaycast(core::line3d<f32>(pos1, pos2),
  142. objects, liquids);
  143. *(void **) (lua_newuserdata(L, sizeof(void *))) = o;
  144. luaL_getmetatable(L, className);
  145. lua_setmetatable(L, -2);
  146. return 1;
  147. }
  148. LuaRaycast *LuaRaycast::checkobject(lua_State *L, int narg)
  149. {
  150. NO_MAP_LOCK_REQUIRED;
  151. luaL_checktype(L, narg, LUA_TUSERDATA);
  152. void *ud = luaL_checkudata(L, narg, className);
  153. if (!ud)
  154. luaL_typerror(L, narg, className);
  155. return *(LuaRaycast **) ud;
  156. }
  157. int LuaRaycast::gc_object(lua_State *L)
  158. {
  159. LuaRaycast *o = *(LuaRaycast **) (lua_touserdata(L, 1));
  160. delete o;
  161. return 0;
  162. }
  163. void LuaRaycast::Register(lua_State *L)
  164. {
  165. lua_newtable(L);
  166. int methodtable = lua_gettop(L);
  167. luaL_newmetatable(L, className);
  168. int metatable = lua_gettop(L);
  169. lua_pushliteral(L, "__metatable");
  170. lua_pushvalue(L, methodtable);
  171. lua_settable(L, metatable);
  172. lua_pushliteral(L, "__index");
  173. lua_pushvalue(L, methodtable);
  174. lua_settable(L, metatable);
  175. lua_pushliteral(L, "__gc");
  176. lua_pushcfunction(L, gc_object);
  177. lua_settable(L, metatable);
  178. lua_pushliteral(L, "__call");
  179. lua_pushcfunction(L, l_next);
  180. lua_settable(L, metatable);
  181. lua_pop(L, 1);
  182. luaL_openlib(L, 0, methods, 0);
  183. lua_pop(L, 1);
  184. lua_register(L, className, create_object);
  185. }
  186. const char LuaRaycast::className[] = "Raycast";
  187. const luaL_Reg LuaRaycast::methods[] =
  188. {
  189. luamethod(LuaRaycast, next),
  190. { 0, 0 }
  191. };
  192. void LuaEmergeAreaCallback(v3s16 blockpos, EmergeAction action, void *param)
  193. {
  194. ScriptCallbackState *state = (ScriptCallbackState *)param;
  195. assert(state != NULL);
  196. assert(state->script != NULL);
  197. assert(state->refcount > 0);
  198. // state must be protected by envlock
  199. Server *server = state->script->getServer();
  200. MutexAutoLock envlock(server->m_env_mutex);
  201. state->refcount--;
  202. state->script->on_emerge_area_completion(blockpos, action, state);
  203. if (state->refcount == 0)
  204. delete state;
  205. }
  206. // Exported functions
  207. // set_node(pos, node)
  208. // pos = {x=num, y=num, z=num}
  209. int ModApiEnvMod::l_set_node(lua_State *L)
  210. {
  211. GET_ENV_PTR;
  212. INodeDefManager *ndef = env->getGameDef()->ndef();
  213. // parameters
  214. v3s16 pos = read_v3s16(L, 1);
  215. MapNode n = readnode(L, 2, ndef);
  216. // Do it
  217. bool succeeded = env->setNode(pos, n);
  218. lua_pushboolean(L, succeeded);
  219. return 1;
  220. }
  221. // bulk_set_node([pos1, pos2, ...], node)
  222. // pos = {x=num, y=num, z=num}
  223. int ModApiEnvMod::l_bulk_set_node(lua_State *L)
  224. {
  225. GET_ENV_PTR;
  226. INodeDefManager *ndef = env->getGameDef()->ndef();
  227. // parameters
  228. if (!lua_istable(L, 1)) {
  229. return 0;
  230. }
  231. s32 len = lua_objlen(L, 1);
  232. if (len == 0) {
  233. lua_pushboolean(L, true);
  234. return 1;
  235. }
  236. MapNode n = readnode(L, 2, ndef);
  237. // Do it
  238. bool succeeded = true;
  239. for (s32 i = 1; i <= len; i++) {
  240. lua_rawgeti(L, 1, i);
  241. if (!env->setNode(read_v3s16(L, -1), n))
  242. succeeded = false;
  243. lua_pop(L, 1);
  244. }
  245. lua_pushboolean(L, succeeded);
  246. return 1;
  247. }
  248. int ModApiEnvMod::l_add_node(lua_State *L)
  249. {
  250. return l_set_node(L);
  251. }
  252. // remove_node(pos)
  253. // pos = {x=num, y=num, z=num}
  254. int ModApiEnvMod::l_remove_node(lua_State *L)
  255. {
  256. GET_ENV_PTR;
  257. // parameters
  258. v3s16 pos = read_v3s16(L, 1);
  259. // Do it
  260. bool succeeded = env->removeNode(pos);
  261. lua_pushboolean(L, succeeded);
  262. return 1;
  263. }
  264. // swap_node(pos, node)
  265. // pos = {x=num, y=num, z=num}
  266. int ModApiEnvMod::l_swap_node(lua_State *L)
  267. {
  268. GET_ENV_PTR;
  269. INodeDefManager *ndef = env->getGameDef()->ndef();
  270. // parameters
  271. v3s16 pos = read_v3s16(L, 1);
  272. MapNode n = readnode(L, 2, ndef);
  273. // Do it
  274. bool succeeded = env->swapNode(pos, n);
  275. lua_pushboolean(L, succeeded);
  276. return 1;
  277. }
  278. // get_node(pos)
  279. // pos = {x=num, y=num, z=num}
  280. int ModApiEnvMod::l_get_node(lua_State *L)
  281. {
  282. GET_ENV_PTR;
  283. // pos
  284. v3s16 pos = read_v3s16(L, 1);
  285. // Do it
  286. MapNode n = env->getMap().getNodeNoEx(pos);
  287. // Return node
  288. pushnode(L, n, env->getGameDef()->ndef());
  289. return 1;
  290. }
  291. // get_node_or_nil(pos)
  292. // pos = {x=num, y=num, z=num}
  293. int ModApiEnvMod::l_get_node_or_nil(lua_State *L)
  294. {
  295. GET_ENV_PTR;
  296. // pos
  297. v3s16 pos = read_v3s16(L, 1);
  298. // Do it
  299. bool pos_ok;
  300. MapNode n = env->getMap().getNodeNoEx(pos, &pos_ok);
  301. if (pos_ok) {
  302. // Return node
  303. pushnode(L, n, env->getGameDef()->ndef());
  304. } else {
  305. lua_pushnil(L);
  306. }
  307. return 1;
  308. }
  309. // get_node_light(pos, timeofday)
  310. // pos = {x=num, y=num, z=num}
  311. // timeofday: nil = current time, 0 = night, 0.5 = day
  312. int ModApiEnvMod::l_get_node_light(lua_State *L)
  313. {
  314. GET_ENV_PTR;
  315. // Do it
  316. v3s16 pos = read_v3s16(L, 1);
  317. u32 time_of_day = env->getTimeOfDay();
  318. if(lua_isnumber(L, 2))
  319. time_of_day = 24000.0 * lua_tonumber(L, 2);
  320. time_of_day %= 24000;
  321. u32 dnr = time_to_daynight_ratio(time_of_day, true);
  322. bool is_position_ok;
  323. MapNode n = env->getMap().getNodeNoEx(pos, &is_position_ok);
  324. if (is_position_ok) {
  325. INodeDefManager *ndef = env->getGameDef()->ndef();
  326. lua_pushinteger(L, n.getLightBlend(dnr, ndef));
  327. } else {
  328. lua_pushnil(L);
  329. }
  330. return 1;
  331. }
  332. // place_node(pos, node)
  333. // pos = {x=num, y=num, z=num}
  334. int ModApiEnvMod::l_place_node(lua_State *L)
  335. {
  336. GET_ENV_PTR;
  337. ScriptApiItem *scriptIfaceItem = getScriptApi<ScriptApiItem>(L);
  338. Server *server = getServer(L);
  339. INodeDefManager *ndef = server->ndef();
  340. IItemDefManager *idef = server->idef();
  341. v3s16 pos = read_v3s16(L, 1);
  342. MapNode n = readnode(L, 2, ndef);
  343. // Don't attempt to load non-loaded area as of now
  344. MapNode n_old = env->getMap().getNodeNoEx(pos);
  345. if(n_old.getContent() == CONTENT_IGNORE){
  346. lua_pushboolean(L, false);
  347. return 1;
  348. }
  349. // Create item to place
  350. ItemStack item(ndef->get(n).name, 1, 0, idef);
  351. // Make pointed position
  352. PointedThing pointed;
  353. pointed.type = POINTEDTHING_NODE;
  354. pointed.node_abovesurface = pos;
  355. pointed.node_undersurface = pos + v3s16(0,-1,0);
  356. // Place it with a NULL placer (appears in Lua as nil)
  357. bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed);
  358. lua_pushboolean(L, success);
  359. return 1;
  360. }
  361. // dig_node(pos)
  362. // pos = {x=num, y=num, z=num}
  363. int ModApiEnvMod::l_dig_node(lua_State *L)
  364. {
  365. GET_ENV_PTR;
  366. ScriptApiNode *scriptIfaceNode = getScriptApi<ScriptApiNode>(L);
  367. v3s16 pos = read_v3s16(L, 1);
  368. // Don't attempt to load non-loaded area as of now
  369. MapNode n = env->getMap().getNodeNoEx(pos);
  370. if(n.getContent() == CONTENT_IGNORE){
  371. lua_pushboolean(L, false);
  372. return 1;
  373. }
  374. // Dig it out with a NULL digger (appears in Lua as a
  375. // non-functional ObjectRef)
  376. bool success = scriptIfaceNode->node_on_dig(pos, n, NULL);
  377. lua_pushboolean(L, success);
  378. return 1;
  379. }
  380. // punch_node(pos)
  381. // pos = {x=num, y=num, z=num}
  382. int ModApiEnvMod::l_punch_node(lua_State *L)
  383. {
  384. GET_ENV_PTR;
  385. ScriptApiNode *scriptIfaceNode = getScriptApi<ScriptApiNode>(L);
  386. v3s16 pos = read_v3s16(L, 1);
  387. // Don't attempt to load non-loaded area as of now
  388. MapNode n = env->getMap().getNodeNoEx(pos);
  389. if(n.getContent() == CONTENT_IGNORE){
  390. lua_pushboolean(L, false);
  391. return 1;
  392. }
  393. // Punch it with a NULL puncher (appears in Lua as a non-functional
  394. // ObjectRef)
  395. bool success = scriptIfaceNode->node_on_punch(pos, n, NULL, PointedThing());
  396. lua_pushboolean(L, success);
  397. return 1;
  398. }
  399. // get_node_max_level(pos)
  400. // pos = {x=num, y=num, z=num}
  401. int ModApiEnvMod::l_get_node_max_level(lua_State *L)
  402. {
  403. Environment *env = getEnv(L);
  404. if (!env) {
  405. return 0;
  406. }
  407. v3s16 pos = read_v3s16(L, 1);
  408. MapNode n = env->getMap().getNodeNoEx(pos);
  409. lua_pushnumber(L, n.getMaxLevel(env->getGameDef()->ndef()));
  410. return 1;
  411. }
  412. // get_node_level(pos)
  413. // pos = {x=num, y=num, z=num}
  414. int ModApiEnvMod::l_get_node_level(lua_State *L)
  415. {
  416. Environment *env = getEnv(L);
  417. if (!env) {
  418. return 0;
  419. }
  420. v3s16 pos = read_v3s16(L, 1);
  421. MapNode n = env->getMap().getNodeNoEx(pos);
  422. lua_pushnumber(L, n.getLevel(env->getGameDef()->ndef()));
  423. return 1;
  424. }
  425. // set_node_level(pos, level)
  426. // pos = {x=num, y=num, z=num}
  427. // level: 0..63
  428. int ModApiEnvMod::l_set_node_level(lua_State *L)
  429. {
  430. GET_ENV_PTR;
  431. v3s16 pos = read_v3s16(L, 1);
  432. u8 level = 1;
  433. if(lua_isnumber(L, 2))
  434. level = lua_tonumber(L, 2);
  435. MapNode n = env->getMap().getNodeNoEx(pos);
  436. lua_pushnumber(L, n.setLevel(env->getGameDef()->ndef(), level));
  437. env->setNode(pos, n);
  438. return 1;
  439. }
  440. // add_node_level(pos, level)
  441. // pos = {x=num, y=num, z=num}
  442. // level: 0..63
  443. int ModApiEnvMod::l_add_node_level(lua_State *L)
  444. {
  445. GET_ENV_PTR;
  446. v3s16 pos = read_v3s16(L, 1);
  447. u8 level = 1;
  448. if(lua_isnumber(L, 2))
  449. level = lua_tonumber(L, 2);
  450. MapNode n = env->getMap().getNodeNoEx(pos);
  451. lua_pushnumber(L, n.addLevel(env->getGameDef()->ndef(), level));
  452. env->setNode(pos, n);
  453. return 1;
  454. }
  455. // find_nodes_with_meta(pos1, pos2)
  456. int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L)
  457. {
  458. GET_ENV_PTR;
  459. std::vector<v3s16> positions = env->getMap().findNodesWithMetadata(
  460. check_v3s16(L, 1), check_v3s16(L, 2));
  461. lua_newtable(L);
  462. for (size_t i = 0; i != positions.size(); i++) {
  463. push_v3s16(L, positions[i]);
  464. lua_rawseti(L, -2, i + 1);
  465. }
  466. return 1;
  467. }
  468. // get_meta(pos)
  469. int ModApiEnvMod::l_get_meta(lua_State *L)
  470. {
  471. GET_ENV_PTR;
  472. // Do it
  473. v3s16 p = read_v3s16(L, 1);
  474. NodeMetaRef::create(L, p, env);
  475. return 1;
  476. }
  477. // get_node_timer(pos)
  478. int ModApiEnvMod::l_get_node_timer(lua_State *L)
  479. {
  480. GET_ENV_PTR;
  481. // Do it
  482. v3s16 p = read_v3s16(L, 1);
  483. NodeTimerRef::create(L, p, env);
  484. return 1;
  485. }
  486. // add_entity(pos, entityname, [staticdata]) -> ObjectRef or nil
  487. // pos = {x=num, y=num, z=num}
  488. int ModApiEnvMod::l_add_entity(lua_State *L)
  489. {
  490. GET_ENV_PTR;
  491. // pos
  492. v3f pos = checkFloatPos(L, 1);
  493. // content
  494. const char *name = luaL_checkstring(L, 2);
  495. // staticdata
  496. const char *staticdata = luaL_optstring(L, 3, "");
  497. // Do it
  498. ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
  499. int objectid = env->addActiveObject(obj);
  500. // If failed to add, return nothing (reads as nil)
  501. if(objectid == 0) return 0;
  502. // If already deleted (can happen in on_activate), return nil
  503. if (obj->isGone()) return 0;
  504. // Return ObjectRef
  505. getScriptApiBase(L)->objectrefGetOrCreate(L, obj);
  506. return 1;
  507. }
  508. // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
  509. // pos = {x=num, y=num, z=num}
  510. int ModApiEnvMod::l_add_item(lua_State *L)
  511. {
  512. GET_ENV_PTR;
  513. // pos
  514. //v3f pos = checkFloatPos(L, 1);
  515. // item
  516. ItemStack item = read_item(L, 2,getServer(L)->idef());
  517. if(item.empty() || !item.isKnown(getServer(L)->idef()))
  518. return 0;
  519. int error_handler = PUSH_ERROR_HANDLER(L);
  520. // Use spawn_item to spawn a __builtin:item
  521. lua_getglobal(L, "core");
  522. lua_getfield(L, -1, "spawn_item");
  523. lua_remove(L, -2); // Remove core
  524. if(lua_isnil(L, -1))
  525. return 0;
  526. lua_pushvalue(L, 1);
  527. lua_pushstring(L, item.getItemString().c_str());
  528. PCALL_RESL(L, lua_pcall(L, 2, 1, error_handler));
  529. lua_remove(L, error_handler);
  530. return 1;
  531. }
  532. // get_connected_players()
  533. int ModApiEnvMod::l_get_connected_players(lua_State *L)
  534. {
  535. ServerEnvironment *env = (ServerEnvironment *) getEnv(L);
  536. if (!env) {
  537. log_deprecated(L, "Calling get_connected_players() at mod load time"
  538. " is deprecated");
  539. lua_createtable(L, 0, 0);
  540. return 1;
  541. }
  542. lua_createtable(L, env->getPlayerCount(), 0);
  543. u32 i = 0;
  544. for (RemotePlayer *player : env->getPlayers()) {
  545. if (player->getPeerId() == PEER_ID_INEXISTENT) continue;
  546. PlayerSAO *sao = player->getPlayerSAO();
  547. if (sao && !sao->isGone()) {
  548. getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
  549. lua_rawseti(L, -2, ++i);
  550. }
  551. }
  552. return 1;
  553. }
  554. // get_player_by_name(name)
  555. int ModApiEnvMod::l_get_player_by_name(lua_State *L)
  556. {
  557. GET_ENV_PTR;
  558. // Do it
  559. const char *name = luaL_checkstring(L, 1);
  560. RemotePlayer *player = env->getPlayer(name);
  561. if (!player || player->getPeerId() == PEER_ID_INEXISTENT)
  562. return 0;
  563. PlayerSAO *sao = player->getPlayerSAO();
  564. if (!sao || sao->isGone())
  565. return 0;
  566. // Put player on stack
  567. getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
  568. return 1;
  569. }
  570. // get_objects_inside_radius(pos, radius)
  571. int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
  572. {
  573. GET_ENV_PTR;
  574. // Do it
  575. v3f pos = checkFloatPos(L, 1);
  576. float radius = readParam<float>(L, 2) * BS;
  577. std::vector<u16> ids;
  578. env->getObjectsInsideRadius(ids, pos, radius);
  579. ScriptApiBase *script = getScriptApiBase(L);
  580. lua_createtable(L, ids.size(), 0);
  581. std::vector<u16>::const_iterator iter = ids.begin();
  582. for(u32 i = 0; iter != ids.end(); ++iter) {
  583. ServerActiveObject *obj = env->getActiveObject(*iter);
  584. if (!obj->isGone()) {
  585. // Insert object reference into table
  586. script->objectrefGetOrCreate(L, obj);
  587. lua_rawseti(L, -2, ++i);
  588. }
  589. }
  590. return 1;
  591. }
  592. // set_timeofday(val)
  593. // val = 0...1
  594. int ModApiEnvMod::l_set_timeofday(lua_State *L)
  595. {
  596. GET_ENV_PTR;
  597. // Do it
  598. float timeofday_f = readParam<float>(L, 1);
  599. sanity_check(timeofday_f >= 0.0 && timeofday_f <= 1.0);
  600. int timeofday_mh = (int)(timeofday_f * 24000.0);
  601. // This should be set directly in the environment but currently
  602. // such changes aren't immediately sent to the clients, so call
  603. // the server instead.
  604. //env->setTimeOfDay(timeofday_mh);
  605. getServer(L)->setTimeOfDay(timeofday_mh);
  606. return 0;
  607. }
  608. // get_timeofday() -> 0...1
  609. int ModApiEnvMod::l_get_timeofday(lua_State *L)
  610. {
  611. Environment *env = getEnv(L);
  612. if (!env) {
  613. return 0;
  614. }
  615. // Do it
  616. int timeofday_mh = env->getTimeOfDay();
  617. float timeofday_f = (float)timeofday_mh / 24000.0f;
  618. lua_pushnumber(L, timeofday_f);
  619. return 1;
  620. }
  621. // get_day_count() -> int
  622. int ModApiEnvMod::l_get_day_count(lua_State *L)
  623. {
  624. Environment *env = getEnv(L);
  625. if (!env) {
  626. return 0;
  627. }
  628. lua_pushnumber(L, env->getDayCount());
  629. return 1;
  630. }
  631. // get_gametime()
  632. int ModApiEnvMod::l_get_gametime(lua_State *L)
  633. {
  634. GET_ENV_PTR;
  635. int game_time = env->getGameTime();
  636. lua_pushnumber(L, game_time);
  637. return 1;
  638. }
  639. // find_node_near(pos, radius, nodenames, search_center) -> pos or nil
  640. // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  641. int ModApiEnvMod::l_find_node_near(lua_State *L)
  642. {
  643. Environment *env = getEnv(L);
  644. if (!env) {
  645. return 0;
  646. }
  647. INodeDefManager *ndef = getGameDef(L)->ndef();
  648. v3s16 pos = read_v3s16(L, 1);
  649. int radius = luaL_checkinteger(L, 2);
  650. std::set<content_t> filter;
  651. if (lua_istable(L, 3)) {
  652. lua_pushnil(L);
  653. while (lua_next(L, 3) != 0) {
  654. // key at index -2 and value at index -1
  655. luaL_checktype(L, -1, LUA_TSTRING);
  656. ndef->getIds(readParam<std::string>(L, -1), filter);
  657. // removes value, keeps key for next iteration
  658. lua_pop(L, 1);
  659. }
  660. } else if (lua_isstring(L, 3)) {
  661. ndef->getIds(readParam<std::string>(L, 3), filter);
  662. }
  663. int start_radius = (lua_isboolean(L, 4) && readParam<bool>(L, 4)) ? 0 : 1;
  664. #ifndef SERVER
  665. // Client API limitations
  666. if (getClient(L) &&
  667. getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOOKUP_NODES)) {
  668. radius = std::max<int>(radius, getClient(L)->getCSMNodeRangeLimit());
  669. }
  670. #endif
  671. for (int d = start_radius; d <= radius; d++) {
  672. std::vector<v3s16> list = FacePositionCache::getFacePositions(d);
  673. for (std::vector<v3s16>::iterator i = list.begin();
  674. i != list.end(); ++i) {
  675. v3s16 p = pos + (*i);
  676. content_t c = env->getMap().getNodeNoEx(p).getContent();
  677. if (filter.count(c) != 0) {
  678. push_v3s16(L, p);
  679. return 1;
  680. }
  681. }
  682. }
  683. return 0;
  684. }
  685. // find_nodes_in_area(minp, maxp, nodenames) -> list of positions
  686. // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  687. int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
  688. {
  689. GET_ENV_PTR;
  690. INodeDefManager *ndef = getServer(L)->ndef();
  691. v3s16 minp = read_v3s16(L, 1);
  692. v3s16 maxp = read_v3s16(L, 2);
  693. sortBoxVerticies(minp, maxp);
  694. v3s16 cube = maxp - minp + 1;
  695. // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
  696. if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) {
  697. luaL_error(L, "find_nodes_in_area(): area volume"
  698. " exceeds allowed value of 4096000");
  699. return 0;
  700. }
  701. std::set<content_t> filter;
  702. if (lua_istable(L, 3)) {
  703. lua_pushnil(L);
  704. while (lua_next(L, 3) != 0) {
  705. // key at index -2 and value at index -1
  706. luaL_checktype(L, -1, LUA_TSTRING);
  707. ndef->getIds(readParam<std::string>(L, -1), filter);
  708. // removes value, keeps key for next iteration
  709. lua_pop(L, 1);
  710. }
  711. } else if (lua_isstring(L, 3)) {
  712. ndef->getIds(readParam<std::string>(L, 3), filter);
  713. }
  714. std::unordered_map<content_t, u32> individual_count;
  715. lua_newtable(L);
  716. u64 i = 0;
  717. for (s16 x = minp.X; x <= maxp.X; x++)
  718. for (s16 y = minp.Y; y <= maxp.Y; y++)
  719. for (s16 z = minp.Z; z <= maxp.Z; z++) {
  720. v3s16 p(x, y, z);
  721. content_t c = env->getMap().getNodeNoEx(p).getContent();
  722. if (filter.count(c) != 0) {
  723. push_v3s16(L, p);
  724. lua_rawseti(L, -2, ++i);
  725. individual_count[c]++;
  726. }
  727. }
  728. lua_newtable(L);
  729. for (std::set<content_t>::const_iterator it = filter.begin();
  730. it != filter.end(); ++it) {
  731. lua_pushnumber(L, individual_count[*it]);
  732. lua_setfield(L, -2, ndef->get(*it).name.c_str());
  733. }
  734. return 2;
  735. }
  736. // find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions
  737. // nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
  738. int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
  739. {
  740. /* Note: A similar but generalized (and therefore slower) version of this
  741. * function could be created -- e.g. find_nodes_in_area_under -- which
  742. * would accept a node name (or ID?) or list of names that the "above node"
  743. * should be.
  744. * TODO
  745. */
  746. GET_ENV_PTR;
  747. INodeDefManager *ndef = getServer(L)->ndef();
  748. v3s16 minp = read_v3s16(L, 1);
  749. v3s16 maxp = read_v3s16(L, 2);
  750. sortBoxVerticies(minp, maxp);
  751. v3s16 cube = maxp - minp + 1;
  752. // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
  753. if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) {
  754. luaL_error(L, "find_nodes_in_area_under_air(): area volume"
  755. " exceeds allowed value of 4096000");
  756. return 0;
  757. }
  758. std::set<content_t> filter;
  759. if (lua_istable(L, 3)) {
  760. lua_pushnil(L);
  761. while (lua_next(L, 3) != 0) {
  762. // key at index -2 and value at index -1
  763. luaL_checktype(L, -1, LUA_TSTRING);
  764. ndef->getIds(readParam<std::string>(L, -1), filter);
  765. // removes value, keeps key for next iteration
  766. lua_pop(L, 1);
  767. }
  768. } else if (lua_isstring(L, 3)) {
  769. ndef->getIds(readParam<std::string>(L, 3), filter);
  770. }
  771. lua_newtable(L);
  772. u64 i = 0;
  773. for (s16 x = minp.X; x <= maxp.X; x++)
  774. for (s16 z = minp.Z; z <= maxp.Z; z++) {
  775. s16 y = minp.Y;
  776. v3s16 p(x, y, z);
  777. content_t c = env->getMap().getNodeNoEx(p).getContent();
  778. for (; y <= maxp.Y; y++) {
  779. v3s16 psurf(x, y + 1, z);
  780. content_t csurf = env->getMap().getNodeNoEx(psurf).getContent();
  781. if (c != CONTENT_AIR && csurf == CONTENT_AIR &&
  782. filter.count(c) != 0) {
  783. push_v3s16(L, v3s16(x, y, z));
  784. lua_rawseti(L, -2, ++i);
  785. }
  786. c = csurf;
  787. }
  788. }
  789. return 1;
  790. }
  791. // get_perlin(seeddiff, octaves, persistence, scale)
  792. // returns world-specific PerlinNoise
  793. int ModApiEnvMod::l_get_perlin(lua_State *L)
  794. {
  795. GET_ENV_PTR_NO_MAP_LOCK;
  796. NoiseParams params;
  797. if (lua_istable(L, 1)) {
  798. read_noiseparams(L, 1, &params);
  799. } else {
  800. params.seed = luaL_checkint(L, 1);
  801. params.octaves = luaL_checkint(L, 2);
  802. params.persist = readParam<float>(L, 3);
  803. params.spread = v3f(1, 1, 1) * readParam<float>(L, 4);
  804. }
  805. params.seed += (int)env->getServerMap().getSeed();
  806. LuaPerlinNoise *n = new LuaPerlinNoise(&params);
  807. *(void **)(lua_newuserdata(L, sizeof(void *))) = n;
  808. luaL_getmetatable(L, "PerlinNoise");
  809. lua_setmetatable(L, -2);
  810. return 1;
  811. }
  812. // get_perlin_map(noiseparams, size)
  813. // returns world-specific PerlinNoiseMap
  814. int ModApiEnvMod::l_get_perlin_map(lua_State *L)
  815. {
  816. GET_ENV_PTR_NO_MAP_LOCK;
  817. NoiseParams np;
  818. if (!read_noiseparams(L, 1, &np))
  819. return 0;
  820. v3s16 size = read_v3s16(L, 2);
  821. s32 seed = (s32)(env->getServerMap().getSeed());
  822. LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size);
  823. *(void **)(lua_newuserdata(L, sizeof(void *))) = n;
  824. luaL_getmetatable(L, "PerlinNoiseMap");
  825. lua_setmetatable(L, -2);
  826. return 1;
  827. }
  828. // get_voxel_manip()
  829. // returns voxel manipulator
  830. int ModApiEnvMod::l_get_voxel_manip(lua_State *L)
  831. {
  832. GET_ENV_PTR;
  833. Map *map = &(env->getMap());
  834. LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
  835. new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) :
  836. new LuaVoxelManip(map);
  837. *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
  838. luaL_getmetatable(L, "VoxelManip");
  839. lua_setmetatable(L, -2);
  840. return 1;
  841. }
  842. // clear_objects([options])
  843. // clear all objects in the environment
  844. // where options = {mode = "full" or "quick"}
  845. int ModApiEnvMod::l_clear_objects(lua_State *L)
  846. {
  847. GET_ENV_PTR;
  848. ClearObjectsMode mode = CLEAR_OBJECTS_MODE_QUICK;
  849. if (lua_istable(L, 1)) {
  850. mode = (ClearObjectsMode)getenumfield(L, 1, "mode",
  851. ModApiEnvMod::es_ClearObjectsMode, mode);
  852. }
  853. env->clearObjects(mode);
  854. return 0;
  855. }
  856. // line_of_sight(pos1, pos2) -> true/false, pos
  857. int ModApiEnvMod::l_line_of_sight(lua_State *L)
  858. {
  859. GET_ENV_PTR;
  860. // read position 1 from lua
  861. v3f pos1 = checkFloatPos(L, 1);
  862. // read position 2 from lua
  863. v3f pos2 = checkFloatPos(L, 2);
  864. v3s16 p;
  865. bool success = env->line_of_sight(pos1, pos2, &p);
  866. lua_pushboolean(L, success);
  867. if (!success) {
  868. push_v3s16(L, p);
  869. return 2;
  870. }
  871. return 1;
  872. }
  873. int ModApiEnvMod::l_raycast(lua_State *L)
  874. {
  875. return LuaRaycast::create_object(L);
  876. }
  877. // load_area(p1, [p2])
  878. // load mapblocks in area p1..p2, but do not generate map
  879. int ModApiEnvMod::l_load_area(lua_State *L)
  880. {
  881. GET_ENV_PTR;
  882. MAP_LOCK_REQUIRED;
  883. Map *map = &(env->getMap());
  884. v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 1));
  885. if (!lua_istable(L, 2)) {
  886. map->emergeBlock(bp1);
  887. } else {
  888. v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 2));
  889. sortBoxVerticies(bp1, bp2);
  890. for (s16 z = bp1.Z; z <= bp2.Z; z++)
  891. for (s16 y = bp1.Y; y <= bp2.Y; y++)
  892. for (s16 x = bp1.X; x <= bp2.X; x++) {
  893. map->emergeBlock(v3s16(x, y, z));
  894. }
  895. }
  896. return 0;
  897. }
  898. // emerge_area(p1, p2, [callback, context])
  899. // emerge mapblocks in area p1..p2, calls callback with context upon completion
  900. int ModApiEnvMod::l_emerge_area(lua_State *L)
  901. {
  902. GET_ENV_PTR;
  903. EmergeCompletionCallback callback = NULL;
  904. ScriptCallbackState *state = NULL;
  905. EmergeManager *emerge = getServer(L)->getEmergeManager();
  906. v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1));
  907. v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2));
  908. sortBoxVerticies(bpmin, bpmax);
  909. size_t num_blocks = VoxelArea(bpmin, bpmax).getVolume();
  910. assert(num_blocks != 0);
  911. if (lua_isfunction(L, 3)) {
  912. callback = LuaEmergeAreaCallback;
  913. lua_pushvalue(L, 3);
  914. int callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  915. lua_pushvalue(L, 4);
  916. int args_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  917. state = new ScriptCallbackState;
  918. state->script = getServer(L)->getScriptIface();
  919. state->callback_ref = callback_ref;
  920. state->args_ref = args_ref;
  921. state->refcount = num_blocks;
  922. state->origin = getScriptApiBase(L)->getOrigin();
  923. }
  924. for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
  925. for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
  926. for (s16 x = bpmin.X; x <= bpmax.X; x++) {
  927. emerge->enqueueBlockEmergeEx(v3s16(x, y, z), PEER_ID_INEXISTENT,
  928. BLOCK_EMERGE_ALLOW_GEN | BLOCK_EMERGE_FORCE_QUEUE, callback, state);
  929. }
  930. return 0;
  931. }
  932. // delete_area(p1, p2)
  933. // delete mapblocks in area p1..p2
  934. int ModApiEnvMod::l_delete_area(lua_State *L)
  935. {
  936. GET_ENV_PTR;
  937. v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1));
  938. v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2));
  939. sortBoxVerticies(bpmin, bpmax);
  940. ServerMap &map = env->getServerMap();
  941. MapEditEvent event;
  942. event.type = MEET_OTHER;
  943. bool success = true;
  944. for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
  945. for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
  946. for (s16 x = bpmin.X; x <= bpmax.X; x++) {
  947. v3s16 bp(x, y, z);
  948. if (map.deleteBlock(bp)) {
  949. env->setStaticForActiveObjectsInBlock(bp, false);
  950. event.modified_blocks.insert(bp);
  951. } else {
  952. success = false;
  953. }
  954. }
  955. map.dispatchEvent(&event);
  956. lua_pushboolean(L, success);
  957. return 1;
  958. }
  959. // find_path(pos1, pos2, searchdistance,
  960. // max_jump, max_drop, algorithm) -> table containing path
  961. int ModApiEnvMod::l_find_path(lua_State *L)
  962. {
  963. GET_ENV_PTR;
  964. v3s16 pos1 = read_v3s16(L, 1);
  965. v3s16 pos2 = read_v3s16(L, 2);
  966. unsigned int searchdistance = luaL_checkint(L, 3);
  967. unsigned int max_jump = luaL_checkint(L, 4);
  968. unsigned int max_drop = luaL_checkint(L, 5);
  969. PathAlgorithm algo = PA_PLAIN_NP;
  970. if (!lua_isnoneornil(L, 6)) {
  971. std::string algorithm = luaL_checkstring(L,6);
  972. if (algorithm == "A*")
  973. algo = PA_PLAIN;
  974. if (algorithm == "Dijkstra")
  975. algo = PA_DIJKSTRA;
  976. }
  977. std::vector<v3s16> path = get_path(env, pos1, pos2,
  978. searchdistance, max_jump, max_drop, algo);
  979. if (path.size() > 0)
  980. {
  981. lua_newtable(L);
  982. int top = lua_gettop(L);
  983. unsigned int index = 1;
  984. for (std::vector<v3s16>::iterator i = path.begin(); i != path.end(); ++i) {
  985. lua_pushnumber(L,index);
  986. push_v3s16(L, *i);
  987. lua_settable(L, top);
  988. index++;
  989. }
  990. return 1;
  991. }
  992. return 0;
  993. }
  994. // spawn_tree(pos, treedef)
  995. int ModApiEnvMod::l_spawn_tree(lua_State *L)
  996. {
  997. GET_ENV_PTR;
  998. v3s16 p0 = read_v3s16(L, 1);
  999. treegen::TreeDef tree_def;
  1000. std::string trunk,leaves,fruit;
  1001. INodeDefManager *ndef = env->getGameDef()->ndef();
  1002. if(lua_istable(L, 2))
  1003. {
  1004. getstringfield(L, 2, "axiom", tree_def.initial_axiom);
  1005. getstringfield(L, 2, "rules_a", tree_def.rules_a);
  1006. getstringfield(L, 2, "rules_b", tree_def.rules_b);
  1007. getstringfield(L, 2, "rules_c", tree_def.rules_c);
  1008. getstringfield(L, 2, "rules_d", tree_def.rules_d);
  1009. getstringfield(L, 2, "trunk", trunk);
  1010. tree_def.trunknode=ndef->getId(trunk);
  1011. getstringfield(L, 2, "leaves", leaves);
  1012. tree_def.leavesnode=ndef->getId(leaves);
  1013. tree_def.leaves2_chance=0;
  1014. getstringfield(L, 2, "leaves2", leaves);
  1015. if (leaves !="")
  1016. {
  1017. tree_def.leaves2node=ndef->getId(leaves);
  1018. getintfield(L, 2, "leaves2_chance", tree_def.leaves2_chance);
  1019. }
  1020. getintfield(L, 2, "angle", tree_def.angle);
  1021. getintfield(L, 2, "iterations", tree_def.iterations);
  1022. if (!getintfield(L, 2, "random_level", tree_def.iterations_random_level))
  1023. tree_def.iterations_random_level = 0;
  1024. getstringfield(L, 2, "trunk_type", tree_def.trunk_type);
  1025. getboolfield(L, 2, "thin_branches", tree_def.thin_branches);
  1026. tree_def.fruit_chance=0;
  1027. getstringfield(L, 2, "fruit", fruit);
  1028. if (fruit != "")
  1029. {
  1030. tree_def.fruitnode=ndef->getId(fruit);
  1031. getintfield(L, 2, "fruit_chance",tree_def.fruit_chance);
  1032. }
  1033. tree_def.explicit_seed = getintfield(L, 2, "seed", tree_def.seed);
  1034. }
  1035. else
  1036. return 0;
  1037. treegen::error e;
  1038. if ((e = treegen::spawn_ltree (env, p0, ndef, tree_def)) != treegen::SUCCESS) {
  1039. if (e == treegen::UNBALANCED_BRACKETS) {
  1040. luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket");
  1041. } else {
  1042. luaL_error(L, "spawn_tree(): unknown error");
  1043. }
  1044. }
  1045. return 1;
  1046. }
  1047. // transforming_liquid_add(pos)
  1048. int ModApiEnvMod::l_transforming_liquid_add(lua_State *L)
  1049. {
  1050. GET_ENV_PTR;
  1051. v3s16 p0 = read_v3s16(L, 1);
  1052. env->getMap().transforming_liquid_add(p0);
  1053. return 1;
  1054. }
  1055. // forceload_block(blockpos)
  1056. // blockpos = {x=num, y=num, z=num}
  1057. int ModApiEnvMod::l_forceload_block(lua_State *L)
  1058. {
  1059. GET_ENV_PTR;
  1060. v3s16 blockpos = read_v3s16(L, 1);
  1061. env->getForceloadedBlocks()->insert(blockpos);
  1062. return 0;
  1063. }
  1064. // forceload_free_block(blockpos)
  1065. // blockpos = {x=num, y=num, z=num}
  1066. int ModApiEnvMod::l_forceload_free_block(lua_State *L)
  1067. {
  1068. GET_ENV_PTR;
  1069. v3s16 blockpos = read_v3s16(L, 1);
  1070. env->getForceloadedBlocks()->erase(blockpos);
  1071. return 0;
  1072. }
  1073. void ModApiEnvMod::Initialize(lua_State *L, int top)
  1074. {
  1075. API_FCT(set_node);
  1076. API_FCT(bulk_set_node);
  1077. API_FCT(add_node);
  1078. API_FCT(swap_node);
  1079. API_FCT(add_item);
  1080. API_FCT(remove_node);
  1081. API_FCT(get_node);
  1082. API_FCT(get_node_or_nil);
  1083. API_FCT(get_node_light);
  1084. API_FCT(place_node);
  1085. API_FCT(dig_node);
  1086. API_FCT(punch_node);
  1087. API_FCT(get_node_max_level);
  1088. API_FCT(get_node_level);
  1089. API_FCT(set_node_level);
  1090. API_FCT(add_node_level);
  1091. API_FCT(add_entity);
  1092. API_FCT(find_nodes_with_meta);
  1093. API_FCT(get_meta);
  1094. API_FCT(get_node_timer);
  1095. API_FCT(get_connected_players);
  1096. API_FCT(get_player_by_name);
  1097. API_FCT(get_objects_inside_radius);
  1098. API_FCT(set_timeofday);
  1099. API_FCT(get_timeofday);
  1100. API_FCT(get_gametime);
  1101. API_FCT(get_day_count);
  1102. API_FCT(find_node_near);
  1103. API_FCT(find_nodes_in_area);
  1104. API_FCT(find_nodes_in_area_under_air);
  1105. API_FCT(load_area);
  1106. API_FCT(emerge_area);
  1107. API_FCT(delete_area);
  1108. API_FCT(get_perlin);
  1109. API_FCT(get_perlin_map);
  1110. API_FCT(get_voxel_manip);
  1111. API_FCT(clear_objects);
  1112. API_FCT(spawn_tree);
  1113. API_FCT(find_path);
  1114. API_FCT(line_of_sight);
  1115. API_FCT(raycast);
  1116. API_FCT(transforming_liquid_add);
  1117. API_FCT(forceload_block);
  1118. API_FCT(forceload_free_block);
  1119. }
  1120. void ModApiEnvMod::InitializeClient(lua_State *L, int top)
  1121. {
  1122. API_FCT(get_timeofday);
  1123. API_FCT(get_day_count);
  1124. API_FCT(get_node_max_level);
  1125. API_FCT(get_node_level);
  1126. API_FCT(find_node_near);
  1127. }