summaryrefslogtreecommitdiff
path: root/src/map.h
Commit message (Collapse)AuthorAge
* Remove legacy flat-file map coderandom-geek2019-10-23
|
* Fix some reference counters (memleak) (#8981)SmallJoker2019-09-24
| | | | | Fix some reference counters (memleak) Map::dispatchEvent: Allocation safety using references
* Improve occlusion culling in corridors with additional checksfan52019-08-24
|
* Restore approximate occlusion checksfan52019-08-24
| | | | While less precise, it worked better which is what matters in the end.
* Occlusion: Check for light_propagates and do mapblock bounds checksSmallJoker2019-08-23
|
* Occlusion: Begin cleanupSmallJoker2019-08-23
|
* Fix unnecessary exception use in Map::getSectorXXX (#8792)Jozef Behran2019-08-13
| | | | | | | The Map::getSectorNoGenerate throws an exception but no other code is really dependent on that. Fix the odd instance of misuse in ClientMap::emergeSector and remove the exception throwing version of the method along with the "NoEx" suffixes in the names of these methods.
* Merge pull request #8776 from osjc/FixGetNodeJozef Behran2019-08-10
| | | Finish getNode cleanup
* Optimize string (mis)handling (#8128)Jozef Behran2019-05-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Optimize statbar drawing The texture name of the statbar is a string passed by value. That slows down the client and creates litter in the heap as the content of the string is allocated there. Convert the offending parameter to a const reference to avoid the performance hit. * Optimize texture cache There is an unnecessary temporary created when the texture path is being generated. This slows down the cache each time a new texture is encountered and it needs to be loaded into the cache. Additionally, the heap litter created by this unnecessary temporary is particularly troublesome here as the following code then piles another string (the resulting full path of the texture) on top of it, followed by the texture itself, which both are quite long term objects as they are subsequently inserted into the cache where they can remain for quite a while (especially if the texture turns out to be a common one like dirt, grass or stone). Use std::string.append to get rid of the temporary which solves both issues (speed and heap fragmentation). * Optimize animations in client Each time an animated node is updated, an unnecessary copy of the texture name is created, littering the heap with lots of fragments. This can be specifically troublesome when looking at oceans or large lava lakes as both of these nodes are usually animated (the lava animation is pretty visible). Convert the parameter of GenericCAO::updateTextures to a const reference to get rid of the unnecessary copy. There is a comment stating "std::string copy is mandatory as mod can be a class member and there is a swap on those class members ... do NOT pass by reference", reinforcing the belief that the unnecessary copy is in fact necessary. However one of the first things the code of the method does is to assign the parameter to its class member, creating another copy. By rearranging the code a little bit this "another copy" can then be used by the subsequent code, getting rid of the need to pass the parameter by value and thus saving that copying effort. * Optimize chat console history handling The GUIChatConsole::replaceAndAddToHistory was getting the line to work on by value which turns out to be unnecessary. Get rid of that unnecessary copy by converting the parameter to a const reference. * Optimize gui texture setting The code used to set the texture for GUI components was getting the name of the texture by value, creating unnecessary performance bottleneck for mods/games with heavily textured GUIs. Get rid of the bottleneck by passing the texture name as a const reference. * Optimize sound playing code in GUIEngine The GUIEngine's code receives the specification of the sound to be played by value, which turns out to be most likely a mistake as the underlying sound manager interface receives the same thing by reference. Convert the offending parameter to a const reference to get rid of the rather bulky copying effort and the associated performance hit. * Silence CLANG TIDY warnings for unit tests Change "std::string" to "const std::string &" to avoid an unnecessary local value copy, silencing the CLANG TIDY process. * Optimize formspec handling The "formspec prepend" parameter was passed to the formspec handling code by value, creating unnecessary copy of std::string and slowing down the game if mods add things like textured backgrounds for the player inventory and/or other forms. Get rid of that performance bottleneck by converting the parameter to a const reference. * Optimize hotbar image handling The code that sets the background images for the hotbar is getting the name of the image by value, creating an unnecessary std::string copying effort. Fix that by converting the relevant parameters to const references. * Optimize inventory deserialization The inventory manager deserialization code gets the serialized version of the inventory by value, slowing the server and the client down when there are inventory updates. This can get particularly troublesome with pipeworks which adds nodes that can mess around with inventories automatically or with mods that have mobs with inventories that actively use them. * Optimize texture scaling cache There is an io::path parameter passed by value in the procedure used to add images converted from textures, leading to slowdown when the image is not yet created and the conversion is thus needed. The performance hit is quite significant as io::path is similar to std::string so convert the parameter to a const reference to get rid of it. * Optimize translation file loader Use "std::string::append" when calculating the final index for the translation table to avoid unnecessary temporary strings. This speeds the translation file loader up significantly as std::string uses heap allocation which tends to be rather slow. Additionally, the heap is no longer being littered by these unnecessary string temporaries, increasing performance of code that gets executed after the translation file loader finishes. * Optimize server map saving When the directory structure for the world data is created during server map saving, an unnecessary value passing of the directory name slows things down. Remove that overhead by converting the offending parameter to a const reference.
* Send only changed node metadata to clients instead of whole mapblock (#5268)SmallJoker2018-12-04
| | | | | | | Includes newer style changes and fixes by est31 Improve the block position de-serialization Add type NodeMetadataMap
* Check node updates whether the blocks are known (#7568)SmallJoker2018-08-16
| | | * Remove unused ignore_id
* Allow an optional readonly base database (#7544)lhofhansl2018-07-25
| | | | | | * Allow an optional readonly base database * Added basic documentation
* SAO limits: Allow SAOs to exist outside the set 'mapgen limit'paramat2018-02-26
|
* map.cpp: Initialize NodeNeighbor, set NeighborType to u8 & cleanupLoic Blot2018-02-11
| | | | | | | Cleanup: * Drop unused Map::transforming_liquid_size() * NodeNeighbor must use const ref for v3s16 * Add a missing default in a switch case
* Node definition manager refactor (#7016)Dániel Juhász2018-02-10
| | | | | | | | | * Rename IWritableNodeDefManager to NodeDefManager * Make INodeDefManager functions const * Use "const *NodeDefManager" instead of "*INodeDefManager" * Remove unused INodeDefManager class * Merge NodeDefManager and CNodeDefManager * Document NodeDefManager
* ServerMap saving: cleanups (#6274)Loïc Blot2017-08-19
| | | | * remove sector meta loading/saving from files which targets dead code (differs_from_disk is always empty) * this remove empty ServerMapSector and ClientMapSector, remove MapSector childs
* Code modernization: src/m* (part 2)Loic Blot2017-08-19
| | | | | | | | | * empty function * default constructor/destructor * remove unused Map::emergeSector(a,b) * for range-based loops * migrate a dirs[7] table to direction tables * remove various old unused function
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
| | | | | | | | | | | | | | * Optimize headers (part 2) * less debug.h in headers * less remoteplayer.h for everybody * Cleanup (part 2) * camera.h: mesh.h * mapgen.h: mapnode.h * serverenvironment.h: mapblock.h * nodedef.h: shader.h
* Modernize various files (src/m*) (#6267)Loïc Blot2017-08-18
| | | | | | | | | | | | * Modernize various files (src/m*) * range-based for loops * code style * C++ headers instead of C headers * Default operators * empty function Thanks to clang-tidy
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
| | | | * Migrate cpp headers to pragma once
* Remove unused Map::getDayNightDiff + fix one undefined variable in mapblock.cppLoic Blot2017-07-26
|
* Cpp11 initializers 2 (#5999)Loïc Blot2017-06-17
| | | | | | | | | | * C++11 patchset 10: continue cleanup on constructors * Drop obsolete bool MainMenuData::enable_public (setting is called with cURL in server loop) * More classes cleanup * More classes cleanup + change NULL tests to boolean tests
* C++11 patchset 6: forbid object copy using assigment/copy function deleters ↵Loïc Blot2017-06-10
| | | | | | | (#5945) C++11 implement function deleting, it's generally used to prevent some object copy In script API use this function removal on ScriptApiBase instead of ScriptApiClient/Server/MainMenu, this affect all ScriptApis Move DISABLE_CLASS_COPY with constructor, the deleted function permit to replace function in its original place
* C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)Loïc Blot2017-06-04
|
* Properly remove SAO when worldedges are overtaken (#5889)Loïc Blot2017-06-03
| | | | | | | | | | | | * LuaEntitySAO: Remove beyond outermost mapchunk edges Based on a commit by, and with help from, nerzhul. Add 2 functions to class Mapgen: A function to calculate actual mapgen edges, called from the Mapgen constructor. A function called indirectly from content_sao.cpp per entity step to check SAO position is within mapgen edges. * Calculate borders from params not mapgen, which is not available everytime
* Time: Change old `u32` timestamps to 64-bit (#5818)SmallJoker2017-05-26
| | | | MacOSX build fix + cleanups
* Player data to Database (#5475)Loïc Blot2017-04-23
| | | | | | | | | | | | * Player data to Database Add player data into databases (SQLite3 & PG only) PostgreSQL & SQLite: better POO Design for databases Add --migrate-players argument to server + deprecation warning * Remove players directory if empty
* Add on_flood() callback.Auke Kok2017-04-22
| | | | | | | | | | | | | | | | | | | | | This callback is called if a liquid definitely floods a non-air node on the map. The callback arguments are (pos, oldnode, newnode) and can return a `bool` value indicating whether flooding the node should be cancelled (`return true` will prevent the node from flooding). Documentation is added, the callback function was tested with a modified minetest_game. Note that `return true` will likely cause the node's `on_flood()` callback to be called every second until the node gets removed, so care must be taken to prevent many callbacks from using this return value. The current default liquid update interval is 1.0 seconds, which isn't unmanageable. The larger aim of this patch is to remove the lava cooling ABM, which is a significant cost to idle servers that have lava on their map. This callback will be much more efficient.
* Light update for map blocksDániel Juhász2017-04-20
| | | | | | | | | This is not really different from the light update of a voxel manipulator. This update does not assume that the lighting was correct before, therefore it is useful for correction. Also expose this function to the Lua API for light correction, and allow voxel manipulators not to update the light.
* Fix various copy instead of const ref reported by cppcheck (part 3) (#5616)Loïc Blot2017-04-20
| | | | * Also remove 2 non declared but defined functions * Make some functions around const ref changes const
* Fix various variables passed by copy instead of const ref (#5610)Loïc Blot2017-04-19
| | | Pointed by cppcheck
* Map generation limit: Make per-worldparamat2017-03-27
| | | | | | | | | | | The setting limits map generation but affects nothing else. Add 'mapgen_limit' to global mapgen parameters. Move 'blockpos_over_mapgen_limit()' to the only place it is called from: map.cpp. Allow teleportation to any part of the world even if over the set mapgen limit. Simplify the reading of this limit in mgvalleys. Remove the 'map_generation_limit' setting.
* Allow server side occlusion culling.Lars Hofhansl2017-03-11
|
* Light calculation: New bulk node lighting codeDániel Juhász2017-03-11
| | | | | | | | | | | This commit introduces a new bulk node lighting algorithm to minimize lighting bugs during l-system tree generation, schematic placement and non-mapgen-object lua voxelmanip light calculation. If the block above the changed area is not loaded, it gets loaded to avoid lighting bugs. Light is updated as soon as write_to_map is called on a voxel manipulator, therefore update_map does nothing.
* Improve getPointedThing() (#4346)Dániel Juhász2017-01-04
| | | | | | | | | | | | | | | | | | | * Improved getPointedThing() The new algorithm checks every node exactly once. Now the point and normal vector of the collision is also returned in the PointedThing (currently they are not used outside of the function). Now the CNodeDefManager keeps the union of all possible nodeboxes, so the raycast won't miss any nodes. Also if there are only small nodeboxes, getPointedThing() is exceptionally fast. Also adds unit test for VoxelLineIterator. * Cleanup, code move This commit moves getPointedThing() and Client::getSelectedActiveObject() to ClientEnvironment. The map nodes now can decide which neighbors they are connecting to (MapNode::getNeighbors()).
* Improved lightingDániel Juhász2016-10-27
| | | | | | | | | | | | | | This commit rewrites the procedure that is responsible for light updating. this commit -provides iterative solutions for unlighting and light spreading -introduces a new priority queue-like container for the iteration -creates per-node MapBlock caching to reduce retrieving MapBlocks from the map -calculates with map block positions and in-block relative node coordinates -skips light updating if it is not necessary since the node's new light will be the same as its old light was
* use unordered containers where possible (patch 4 on X)Loic Blot2016-10-06
| | | | Also remove some unused parameters/functions
* Add MapSettingsManager and new mapgen setting script API functionskwolekr2016-07-03
| | | | | | | | | | | | | | | This commit refactors the majority of the Mapgen settings system. - MapgenParams is now owned by MapSettingsManager, itself a part of ServerMap, instead of the EmergeManager. - New Script API functions added: core.get_mapgen_setting core.get_mapgen_setting_noiseparams, core.set_mapgen_setting, and core.set_mapgen_setting_noiseparams. - minetest.get/set_mapgen_params are deprecated by the above new functions. - It is now possible to view and modify any arbitrary mapgen setting from a mod, rather than the base MapgenParams structure. - MapgenSpecificParams has been removed.
* Make node timers more efficientEkdohibs2016-06-11
|
* Add DISABLE_CLASS_COPY macro (and use it)kwolekr2015-10-27
| | | | | | | | | Use this macro to disallow copying of an object using the assignment operator or copy constructor. This catches otherwise silent-but-deadly mistakes such as "ServerMap map = env->getMap();" at compile time. If so desired, it is still possible to copy a class, but it now requires an explicit call to memcpy or std::copy.
* Add emerge completion callback mechanismkwolekr2015-10-04
| | | | Major refactor of emerge.cpp and Map::init/finishBlockMake
* Add count based unload limit for mapblocksest312015-08-13
|
* Add core.find_nodes_with_meta() script APIkwolekr2015-05-05
|
* For usages of assert() that are meant to persist in Release builds (when ↵Craig Robbins2015-03-07
| | | | NDEBUG is defined), replace those usages with persistent alternatives
* Don't start a server for map migrationShadowNinja2015-03-06
|
* Clean up database API and save the local map on an intervalShadowNinja2015-03-06
|
* ABMHandler and player_collisions use sequential read/write. Switch from ↵Loic Blot2015-03-04
| | | | | | std::list to std::vector * Also remove dead code Map::unloadUnusedData which is dead since a long time
* Replace std::list by std::vector into timerUpdate callsLoic Blot2015-02-17
|
* Replace std::list by std::vector into ServerMap::listAllLoadableBlocks ↵Loic Blot2015-02-17
| | | | | | ServerMap::listAllLoadedBlocks and their database backends. This adds a speedup on database migration and /clearobjects command
* Create empty default constructor for MapNodeCraig Robbins2015-01-18
|
include "daynightratio.h" #include "util/pointedthing.h" #include "content_sao.h" #include "mapgen/treegen.h" #include "emerge.h" #include "pathfinder.h" #include "face_position_cache.h" #include "remoteplayer.h" #ifndef SERVER #include "client.h" #endif struct EnumString ModApiEnvMod::es_ClearObjectsMode[] = { {CLEAR_OBJECTS_MODE_FULL, "full"}, {CLEAR_OBJECTS_MODE_QUICK, "quick"}, {0, NULL}, }; /////////////////////////////////////////////////////////////////////////////// void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, u32 active_object_count, u32 active_object_count_wider) { ServerScripting *scriptIface = env->getScriptIface(); scriptIface->realityCheck(); lua_State *L = scriptIface->getStack(); sanity_check(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); int error_handler = PUSH_ERROR_HANDLER(L); // Get registered_abms lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_abms"); luaL_checktype(L, -1, LUA_TTABLE); lua_remove(L, -2); // Remove core // Get registered_abms[m_id] lua_pushnumber(L, m_id); lua_gettable(L, -2); if(lua_isnil(L, -1)) FATAL_ERROR(""); lua_remove(L, -2); // Remove registered_abms scriptIface->setOriginFromTable(-1); // Call action luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_abms[m_id] push_v3s16(L, p); pushnode(L, n, env->getGameDef()->ndef()); lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count_wider); int result = lua_pcall(L, 4, 0, error_handler); if (result) scriptIface->scriptError(result, "LuaABM::trigger"); lua_pop(L, 1); // Pop error handler } void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) { ServerScripting *scriptIface = env->getScriptIface(); scriptIface->realityCheck(); lua_State *L = scriptIface->getStack(); sanity_check(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); int error_handler = PUSH_ERROR_HANDLER(L); // Get registered_lbms lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_lbms"); luaL_checktype(L, -1, LUA_TTABLE); lua_remove(L, -2); // Remove core // Get registered_lbms[m_id] lua_pushnumber(L, m_id); lua_gettable(L, -2); FATAL_ERROR_IF(lua_isnil(L, -1), "Entry with given id not found in registered_lbms table"); lua_remove(L, -2); // Remove registered_lbms scriptIface->setOriginFromTable(-1); // Call action luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_lbms[m_id] push_v3s16(L, p); pushnode(L, n, env->getGameDef()->ndef()); int result = lua_pcall(L, 2, 0, error_handler); if (result) scriptIface->scriptError(result, "LuaLBM::trigger"); lua_pop(L, 1); // Pop error handler } int LuaRaycast::l_next(lua_State *L) { MAP_LOCK_REQUIRED; ScriptApiItem *script = getScriptApi<ScriptApiItem>(L); GET_ENV_PTR; LuaRaycast *o = checkobject(L, 1); PointedThing pointed; env->continueRaycast(&o->state, &pointed); if (pointed.type == POINTEDTHING_NOTHING) lua_pushnil(L); else script->pushPointedThing(pointed); return 1; } int LuaRaycast::create_object(lua_State *L) { NO_MAP_LOCK_REQUIRED; bool objects = true; bool liquids = false; v3f pos1 = checkFloatPos(L, 1); v3f pos2 = checkFloatPos(L, 2); if (lua_isboolean(L, 3)) { objects = readParam<bool>(L, 3); } if (lua_isboolean(L, 4)) { liquids = readParam<bool>(L, 4); } LuaRaycast *o = new LuaRaycast(core::line3d<f32>(pos1, pos2), objects, liquids); *(void **) (lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); lua_setmetatable(L, -2); return 1; } LuaRaycast *LuaRaycast::checkobject(lua_State *L, int narg) { NO_MAP_LOCK_REQUIRED; luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); if (!ud) luaL_typerror(L, narg, className); return *(LuaRaycast **) ud; } int LuaRaycast::gc_object(lua_State *L) { LuaRaycast *o = *(LuaRaycast **) (lua_touserdata(L, 1)); delete o; return 0; } void LuaRaycast::Register(lua_State *L) { lua_newtable(L); int methodtable = lua_gettop(L); luaL_newmetatable(L, className); int metatable = lua_gettop(L); lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methodtable); lua_settable(L, metatable); lua_pushliteral(L, "__index"); lua_pushvalue(L, methodtable); lua_settable(L, metatable); lua_pushliteral(L, "__gc"); lua_pushcfunction(L, gc_object); lua_settable(L, metatable); lua_pushliteral(L, "__call"); lua_pushcfunction(L, l_next); lua_settable(L, metatable); lua_pop(L, 1); luaL_openlib(L, 0, methods, 0); lua_pop(L, 1); lua_register(L, className, create_object); } const char LuaRaycast::className[] = "Raycast"; const luaL_Reg LuaRaycast::methods[] = { luamethod(LuaRaycast, next), { 0, 0 } }; void LuaEmergeAreaCallback(v3s16 blockpos, EmergeAction action, void *param) { ScriptCallbackState *state = (ScriptCallbackState *)param; assert(state != NULL); assert(state->script != NULL); assert(state->refcount > 0); // state must be protected by envlock Server *server = state->script->getServer(); MutexAutoLock envlock(server->m_env_mutex); state->refcount--; state->script->on_emerge_area_completion(blockpos, action, state); if (state->refcount == 0) delete state; } // Exported functions // set_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_set_node(lua_State *L) { GET_ENV_PTR; const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters v3s16 pos = read_v3s16(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->setNode(pos, n); lua_pushboolean(L, succeeded); return 1; } // bulk_set_node([pos1, pos2, ...], node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_bulk_set_node(lua_State *L) { GET_ENV_PTR; const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters if (!lua_istable(L, 1)) { return 0; } s32 len = lua_objlen(L, 1); if (len == 0) { lua_pushboolean(L, true); return 1; } MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = true; for (s32 i = 1; i <= len; i++) { lua_rawgeti(L, 1, i); if (!env->setNode(read_v3s16(L, -1), n)) succeeded = false; lua_pop(L, 1); } lua_pushboolean(L, succeeded); return 1; } int ModApiEnvMod::l_add_node(lua_State *L) { return l_set_node(L); } // remove_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_remove_node(lua_State *L) { GET_ENV_PTR; // parameters v3s16 pos = read_v3s16(L, 1); // Do it bool succeeded = env->removeNode(pos); lua_pushboolean(L, succeeded); return 1; } // swap_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_swap_node(lua_State *L) { GET_ENV_PTR; const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters v3s16 pos = read_v3s16(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->swapNode(pos, n); lua_pushboolean(L, succeeded); return 1; } // get_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node(lua_State *L) { GET_ENV_PTR; // pos v3s16 pos = read_v3s16(L, 1); // Do it MapNode n = env->getMap().getNodeNoEx(pos); // Return node pushnode(L, n, env->getGameDef()->ndef()); return 1; } // get_node_or_nil(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_or_nil(lua_State *L) { GET_ENV_PTR; // pos v3s16 pos = read_v3s16(L, 1); // Do it bool pos_ok; MapNode n = env->getMap().getNodeNoEx(pos, &pos_ok); if (pos_ok) { // Return node pushnode(L, n, env->getGameDef()->ndef()); } else { lua_pushnil(L); } return 1; } // get_node_light(pos, timeofday) // pos = {x=num, y=num, z=num} // timeofday: nil = current time, 0 = night, 0.5 = day int ModApiEnvMod::l_get_node_light(lua_State *L) { GET_ENV_PTR; // Do it v3s16 pos = read_v3s16(L, 1); u32 time_of_day = env->getTimeOfDay(); if(lua_isnumber(L, 2)) time_of_day = 24000.0 * lua_tonumber(L, 2); time_of_day %= 24000; u32 dnr = time_to_daynight_ratio(time_of_day, true); bool is_position_ok; MapNode n = env->getMap().getNodeNoEx(pos, &is_position_ok); if (is_position_ok) { const NodeDefManager *ndef = env->getGameDef()->ndef(); lua_pushinteger(L, n.getLightBlend(dnr, ndef)); } else { lua_pushnil(L); } return 1; } // place_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_place_node(lua_State *L) { GET_ENV_PTR; ScriptApiItem *scriptIfaceItem = getScriptApi<ScriptApiItem>(L); Server *server = getServer(L); const NodeDefManager *ndef = server->ndef(); IItemDefManager *idef = server->idef(); v3s16 pos = read_v3s16(L, 1); MapNode n = readnode(L, 2, ndef); // Don't attempt to load non-loaded area as of now MapNode n_old = env->getMap().getNodeNoEx(pos); if(n_old.getContent() == CONTENT_IGNORE){ lua_pushboolean(L, false); return 1; } // Create item to place ItemStack item(ndef->get(n).name, 1, 0, idef); // Make pointed position PointedThing pointed; pointed.type = POINTEDTHING_NODE; pointed.node_abovesurface = pos; pointed.node_undersurface = pos + v3s16(0,-1,0); // Place it with a NULL placer (appears in Lua as nil) bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed); lua_pushboolean(L, success); return 1; } // dig_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_dig_node(lua_State *L) { GET_ENV_PTR; ScriptApiNode *scriptIfaceNode = getScriptApi<ScriptApiNode>(L); v3s16 pos = read_v3s16(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNodeNoEx(pos); if(n.getContent() == CONTENT_IGNORE){ lua_pushboolean(L, false); return 1; } // Dig it out with a NULL digger (appears in Lua as a // non-functional ObjectRef) bool success = scriptIfaceNode->node_on_dig(pos, n, NULL); lua_pushboolean(L, success); return 1; } // punch_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_punch_node(lua_State *L) { GET_ENV_PTR; ScriptApiNode *scriptIfaceNode = getScriptApi<ScriptApiNode>(L); v3s16 pos = read_v3s16(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNodeNoEx(pos); if(n.getContent() == CONTENT_IGNORE){ lua_pushboolean(L, false); return 1; } // Punch it with a NULL puncher (appears in Lua as a non-functional // ObjectRef) bool success = scriptIfaceNode->node_on_punch(pos, n, NULL, PointedThing()); lua_pushboolean(L, success); return 1; } // get_node_max_level(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_max_level(lua_State *L) { Environment *env = getEnv(L); if (!env) { return 0; } v3s16 pos = read_v3s16(L, 1); MapNode n = env->getMap().getNodeNoEx(pos); lua_pushnumber(L, n.getMaxLevel(env->getGameDef()->ndef())); return 1; } // get_node_level(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_level(lua_State *L) { Environment *env = getEnv(L); if (!env) { return 0; } v3s16 pos = read_v3s16(L, 1); MapNode n = env->getMap().getNodeNoEx(pos); lua_pushnumber(L, n.getLevel(env->getGameDef()->ndef())); return 1; } // set_node_level(pos, level) // pos = {x=num, y=num, z=num} // level: 0..63 int ModApiEnvMod::l_set_node_level(lua_State *L) { GET_ENV_PTR; v3s16 pos = read_v3s16(L, 1); u8 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); MapNode n = env->getMap().getNodeNoEx(pos); lua_pushnumber(L, n.setLevel(env->getGameDef()->ndef(), level)); env->setNode(pos, n); return 1; } // add_node_level(pos, level) // pos = {x=num, y=num, z=num} // level: 0..63 int ModApiEnvMod::l_add_node_level(lua_State *L) { GET_ENV_PTR; v3s16 pos = read_v3s16(L, 1); u8 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); MapNode n = env->getMap().getNodeNoEx(pos); lua_pushnumber(L, n.addLevel(env->getGameDef()->ndef(), level)); env->setNode(pos, n); return 1; } // find_nodes_with_meta(pos1, pos2) int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) { GET_ENV_PTR; std::vector<v3s16> positions = env->getMap().findNodesWithMetadata( check_v3s16(L, 1), check_v3s16(L, 2)); lua_newtable(L); for (size_t i = 0; i != positions.size(); i++) { push_v3s16(L, positions[i]); lua_rawseti(L, -2, i + 1); } return 1; } // get_meta(pos) int ModApiEnvMod::l_get_meta(lua_State *L) { GET_ENV_PTR; // Do it v3s16 p = read_v3s16(L, 1); NodeMetaRef::create(L, p, env); return 1; } // get_node_timer(pos) int ModApiEnvMod::l_get_node_timer(lua_State *L) { GET_ENV_PTR; // Do it v3s16 p = read_v3s16(L, 1); NodeTimerRef::create(L, p, env); return 1; } // add_entity(pos, entityname, [staticdata]) -> ObjectRef or nil // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_add_entity(lua_State *L) { GET_ENV_PTR; // pos v3f pos = checkFloatPos(L, 1); // content const char *name = luaL_checkstring(L, 2); // staticdata const char *staticdata = luaL_optstring(L, 3, ""); // Do it ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata); int objectid = env->addActiveObject(obj); // If failed to add, return nothing (reads as nil) if(objectid == 0) return 0; // Return ObjectRef getScriptApiBase(L)->objectrefGetOrCreate(L, obj); return 1; } // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_add_item(lua_State *L) { GET_ENV_PTR; // pos //v3f pos = checkFloatPos(L, 1); // item ItemStack item = read_item(L, 2,getServer(L)->idef()); if(item.empty() || !item.isKnown(getServer(L)->idef())) return 0; int error_handler = PUSH_ERROR_HANDLER(L); // Use spawn_item to spawn a __builtin:item lua_getglobal(L, "core"); lua_getfield(L, -1, "spawn_item"); lua_remove(L, -2); // Remove core if(lua_isnil(L, -1)) return 0; lua_pushvalue(L, 1); lua_pushstring(L, item.getItemString().c_str()); PCALL_RESL(L, lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); return 1; } // get_player_by_name(name) int ModApiEnvMod::l_get_player_by_name(lua_State *L) { GET_ENV_PTR; // Do it const char *name = luaL_checkstring(L, 1); RemotePlayer *player = dynamic_cast<RemotePlayer *>(env->getPlayer(name)); if (player == NULL){ lua_pushnil(L); return 1; } PlayerSAO *sao = player->getPlayerSAO(); if(sao == NULL){ lua_pushnil(L); return 1; } // Put player on stack getScriptApiBase(L)->objectrefGetOrCreate(L, sao); return 1; } // get_objects_inside_radius(pos, radius) int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L) { GET_ENV_PTR; // Do it v3f pos = checkFloatPos(L, 1); float radius = readParam<float>(L, 2) * BS; std::vector<u16> ids; env->getObjectsInsideRadius(ids, pos, radius); ScriptApiBase *script = getScriptApiBase(L); lua_createtable(L, ids.size(), 0); std::vector<u16>::const_iterator iter = ids.begin(); for(u32 i = 0; iter != ids.end(); ++iter) { ServerActiveObject *obj = env->getActiveObject(*iter); if (!obj->isGone()) { // Insert object reference into table script->objectrefGetOrCreate(L, obj); lua_rawseti(L, -2, ++i); } } return 1; } // set_timeofday(val) // val = 0...1 int ModApiEnvMod::l_set_timeofday(lua_State *L) { GET_ENV_PTR; // Do it float timeofday_f = readParam<float>(L, 1); sanity_check(timeofday_f >= 0.0 && timeofday_f <= 1.0); int timeofday_mh = (int)(timeofday_f * 24000.0); // This should be set directly in the environment but currently // such changes aren't immediately sent to the clients, so call // the server instead. //env->setTimeOfDay(timeofday_mh); getServer(L)->setTimeOfDay(timeofday_mh); return 0; } // get_timeofday() -> 0...1 int ModApiEnvMod::l_get_timeofday(lua_State *L) { Environment *env = getEnv(L); if (!env) { return 0; } // Do it int timeofday_mh = env->getTimeOfDay(); float timeofday_f = (float)timeofday_mh / 24000.0f; lua_pushnumber(L, timeofday_f); return 1; } // get_day_count() -> int int ModApiEnvMod::l_get_day_count(lua_State *L) { Environment *env = getEnv(L); if (!env) { return 0; } lua_pushnumber(L, env->getDayCount()); return 1; } // get_gametime() int ModApiEnvMod::l_get_gametime(lua_State *L) { GET_ENV_PTR; int game_time = env->getGameTime(); lua_pushnumber(L, game_time); return 1; } // find_node_near(pos, radius, nodenames, search_center) -> pos or nil // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_node_near(lua_State *L) { Environment *env = getEnv(L); if (!env) { return 0; } const NodeDefManager *ndef = getGameDef(L)->ndef(); v3s16 pos = read_v3s16(L, 1); int radius = luaL_checkinteger(L, 2); std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); ndef->getIds(readParam<std::string>(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { ndef->getIds(readParam<std::string>(L, 3), filter); } int start_radius = (lua_isboolean(L, 4) && readParam<bool>(L, 4)) ? 0 : 1; #ifndef SERVER // Client API limitations if (getClient(L) && getClient(L)->checkCSMRestrictionFlag( CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) { radius = std::max<int>(radius, getClient(L)->getCSMNodeRangeLimit()); } #endif for (int d = start_radius; d <= radius; d++) { std::vector<v3s16> list = FacePositionCache::getFacePositions(d); for (const v3s16 &i : list) { v3s16 p = pos + i; content_t c = env->getMap().getNodeNoEx(p).getContent(); if (CONTAINS(filter, c)) { push_v3s16(L, p); return 1; } } } return 0; } // find_nodes_in_area(minp, maxp, nodenames) -> list of positions // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { GET_ENV_PTR; const NodeDefManager *ndef = getServer(L)->ndef(); v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); v3s16 cube = maxp - minp + 1; // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) { luaL_error(L, "find_nodes_in_area(): area volume" " exceeds allowed value of 4096000"); return 0; } std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); ndef->getIds(readParam<std::string>(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { ndef->getIds(readParam<std::string>(L, 3), filter); } std::vector<u32> individual_count; individual_count.resize(filter.size()); lua_newtable(L); u64 i = 0; for (s16 x = minp.X; x <= maxp.X; x++) for (s16 y = minp.Y; y <= maxp.Y; y++) for (s16 z = minp.Z; z <= maxp.Z; z++) { v3s16 p(x, y, z); content_t c = env->getMap().getNodeNoEx(p).getContent(); std::vector<content_t>::iterator it = std::find(filter.begin(), filter.end(), c); if (it != filter.end()) { push_v3s16(L, p); lua_rawseti(L, -2, ++i); u32 filt_index = it - filter.begin(); individual_count[filt_index]++; } } lua_newtable(L); for (u32 i = 0; i < filter.size(); i++) { lua_pushnumber(L, individual_count[i]); lua_setfield(L, -2, ndef->get(filter[i]).name.c_str()); } return 2; } // find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions // nodenames: e.g. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) { /* Note: A similar but generalized (and therefore slower) version of this * function could be created -- e.g. find_nodes_in_area_under -- which * would accept a node name (or ID?) or list of names that the "above node" * should be. * TODO */ GET_ENV_PTR; const NodeDefManager *ndef = getServer(L)->ndef(); v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); v3s16 cube = maxp - minp + 1; // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) { luaL_error(L, "find_nodes_in_area_under_air(): area volume" " exceeds allowed value of 4096000"); return 0; } std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); ndef->getIds(readParam<std::string>(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { ndef->getIds(readParam<std::string>(L, 3), filter); } lua_newtable(L); u64 i = 0; for (s16 x = minp.X; x <= maxp.X; x++) for (s16 z = minp.Z; z <= maxp.Z; z++) { s16 y = minp.Y; v3s16 p(x, y, z); content_t c = env->getMap().getNodeNoEx(p).getContent(); for (; y <= maxp.Y; y++) { v3s16 psurf(x, y + 1, z); content_t csurf = env->getMap().getNodeNoEx(psurf).getContent(); if (c != CONTENT_AIR && csurf == CONTENT_AIR && CONTAINS(filter, c)) { push_v3s16(L, v3s16(x, y, z)); lua_rawseti(L, -2, ++i); } c = csurf; } } return 1; } // get_perlin(seeddiff, octaves, persistence, scale) // returns world-specific PerlinNoise int ModApiEnvMod::l_get_perlin(lua_State *L) { GET_ENV_PTR_NO_MAP_LOCK; NoiseParams params; if (lua_istable(L, 1)) { read_noiseparams(L, 1, &params); } else { params.seed = luaL_checkint(L, 1); params.octaves = luaL_checkint(L, 2); params.persist = readParam<float>(L, 3); params.spread = v3f(1, 1, 1) * readParam<float>(L, 4); } params.seed += (int)env->getServerMap().getSeed(); LuaPerlinNoise *n = new LuaPerlinNoise(&params); *(void **)(lua_newuserdata(L, sizeof(void *))) = n; luaL_getmetatable(L, "PerlinNoise"); lua_setmetatable(L, -2); return 1; } // get_perlin_map(noiseparams, size) // returns world-specific PerlinNoiseMap int ModApiEnvMod::l_get_perlin_map(lua_State *L) { GET_ENV_PTR_NO_MAP_LOCK; NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; v3s16 size = read_v3s16(L, 2); s32 seed = (s32)(env->getServerMap().getSeed()); LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size); *(void **)(lua_newuserdata(L, sizeof(void *))) = n; luaL_getmetatable(L, "PerlinNoiseMap"); lua_setmetatable(L, -2); return 1; } // get_voxel_manip() // returns voxel manipulator int ModApiEnvMod::l_get_voxel_manip(lua_State *L) { GET_ENV_PTR; Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, "VoxelManip"); lua_setmetatable(L, -2); return 1; } // clear_objects([options]) // clear all objects in the environment // where options = {mode = "full" or "quick"} int ModApiEnvMod::l_clear_objects(lua_State *L) { GET_ENV_PTR; ClearObjectsMode mode = CLEAR_OBJECTS_MODE_QUICK; if (lua_istable(L, 1)) { mode = (ClearObjectsMode)getenumfield(L, 1, "mode", ModApiEnvMod::es_ClearObjectsMode, mode); } env->clearObjects(mode); return 0; } // line_of_sight(pos1, pos2) -> true/false, pos int ModApiEnvMod::l_line_of_sight(lua_State *L) { GET_ENV_PTR; // read position 1 from lua v3f pos1 = checkFloatPos(L, 1); // read position 2 from lua v3f pos2 = checkFloatPos(L, 2); v3s16 p; bool success = env->line_of_sight(pos1, pos2, &p); lua_pushboolean(L, success); if (!success) { push_v3s16(L, p); return 2; } return 1; } // fix_light(p1, p2) int ModApiEnvMod::l_fix_light(lua_State *L) { GET_ENV_PTR; v3s16 blockpos1 = getContainerPos(read_v3s16(L, 1), MAP_BLOCKSIZE); v3s16 blockpos2 = getContainerPos(read_v3s16(L, 2), MAP_BLOCKSIZE); ServerMap &map = env->getServerMap(); std::map<v3s16, MapBlock *> modified_blocks; bool success = true; v3s16 blockpos; for (blockpos.X = blockpos1.X; blockpos.X <= blockpos2.X; blockpos.X++) for (blockpos.Y = blockpos1.Y; blockpos.Y <= blockpos2.Y; blockpos.Y++) for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { success = success & map.repairBlockLight(blockpos, &modified_blocks); } if (!modified_blocks.empty()) { MapEditEvent event; event.type = MEET_OTHER; for (auto &modified_block : modified_blocks) event.modified_blocks.insert(modified_block.first); map.dispatchEvent(&event); } lua_pushboolean(L, success); return 1; } int ModApiEnvMod::l_raycast(lua_State *L) { return LuaRaycast::create_object(L); } // emerge_area(p1, p2, [callback, context]) // emerge mapblocks in area p1..p2, calls callback with context upon completion int ModApiEnvMod::l_emerge_area(lua_State *L) { GET_ENV_PTR; EmergeCompletionCallback callback = NULL; ScriptCallbackState *state = NULL; EmergeManager *emerge = getServer(L)->getEmergeManager(); v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1)); v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2)); sortBoxVerticies(bpmin, bpmax); size_t num_blocks = VoxelArea(bpmin, bpmax).getVolume(); assert(num_blocks != 0); if (lua_isfunction(L, 3)) { callback = LuaEmergeAreaCallback; lua_pushvalue(L, 3); int callback_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_pushvalue(L, 4); int args_ref = luaL_ref(L, LUA_REGISTRYINDEX); state = new ScriptCallbackState; state->script = getServer(L)->getScriptIface(); state->callback_ref = callback_ref; state->args_ref = args_ref; state->refcount = num_blocks; state->origin = getScriptApiBase(L)->getOrigin(); } for (s16 z = bpmin.Z; z <= bpmax.Z; z++) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { emerge->enqueueBlockEmergeEx(v3s16(x, y, z), PEER_ID_INEXISTENT, BLOCK_EMERGE_ALLOW_GEN | BLOCK_EMERGE_FORCE_QUEUE, callback, state); } return 0; } // delete_area(p1, p2) // delete mapblocks in area p1..p2 int ModApiEnvMod::l_delete_area(lua_State *L) { GET_ENV_PTR; v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1)); v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2)); sortBoxVerticies(bpmin, bpmax); ServerMap &map = env->getServerMap(); MapEditEvent event; event.type = MEET_OTHER; bool success = true; for (s16 z = bpmin.Z; z <= bpmax.Z; z++) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { v3s16 bp(x, y, z); if (map.deleteBlock(bp)) { env->setStaticForActiveObjectsInBlock(bp, false); event.modified_blocks.insert(bp); } else { success = false; } } map.dispatchEvent(&event); lua_pushboolean(L, success); return 1; } // find_path(pos1, pos2, searchdistance, // max_jump, max_drop, algorithm) -> table containing path int ModApiEnvMod::l_find_path(lua_State *L) { GET_ENV_PTR; v3s16 pos1 = read_v3s16(L, 1); v3s16 pos2 = read_v3s16(L, 2); unsigned int searchdistance = luaL_checkint(L, 3); unsigned int max_jump = luaL_checkint(L, 4); unsigned int max_drop = luaL_checkint(L, 5); PathAlgorithm algo = PA_PLAIN_NP; if (!lua_isnil(L, 6)) { std::string algorithm = luaL_checkstring(L,6); if (algorithm == "A*") algo = PA_PLAIN; if (algorithm == "Dijkstra") algo = PA_DIJKSTRA; } std::vector<v3s16> path = get_path(env, pos1, pos2, searchdistance, max_jump, max_drop, algo); if (!path.empty()) { lua_newtable(L); int top = lua_gettop(L); unsigned int index = 1; for (const v3s16 &i : path) { lua_pushnumber(L,index); push_v3s16(L, i); lua_settable(L, top); index++; } return 1; } return 0; } // spawn_tree(pos, treedef) int ModApiEnvMod::l_spawn_tree(lua_State *L) { GET_ENV_PTR; v3s16 p0 = read_v3s16(L, 1); treegen::TreeDef tree_def; std::string trunk,leaves,fruit; const NodeDefManager *ndef = env->getGameDef()->ndef(); if(lua_istable(L, 2)) { getstringfield(L, 2, "axiom", tree_def.initial_axiom); getstringfield(L, 2, "rules_a", tree_def.rules_a); getstringfield(L, 2, "rules_b", tree_def.rules_b); getstringfield(L, 2, "rules_c", tree_def.rules_c); getstringfield(L, 2, "rules_d", tree_def.rules_d); getstringfield(L, 2, "trunk", trunk); tree_def.trunknode=ndef->getId(trunk); getstringfield(L, 2, "leaves", leaves); tree_def.leavesnode=ndef->getId(leaves); tree_def.leaves2_chance=0; getstringfield(L, 2, "leaves2", leaves); if (!leaves.empty()) { tree_def.leaves2node=ndef->getId(leaves); getintfield(L, 2, "leaves2_chance", tree_def.leaves2_chance); } getintfield(L, 2, "angle", tree_def.angle); getintfield(L, 2, "iterations", tree_def.iterations); if (!getintfield(L, 2, "random_level", tree_def.iterations_random_level)) tree_def.iterations_random_level = 0; getstringfield(L, 2, "trunk_type", tree_def.trunk_type); getboolfield(L, 2, "thin_branches", tree_def.thin_branches); tree_def.fruit_chance=0; getstringfield(L, 2, "fruit", fruit); if (!fruit.empty()) { tree_def.fruitnode=ndef->getId(fruit); getintfield(L, 2, "fruit_chance",tree_def.fruit_chance); } tree_def.explicit_seed = getintfield(L, 2, "seed", tree_def.seed); } else return 0; treegen::error e; if ((e = treegen::spawn_ltree (env, p0, ndef, tree_def)) != treegen::SUCCESS) { if (e == treegen::UNBALANCED_BRACKETS) { luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket"); } else { luaL_error(L, "spawn_tree(): unknown error"); } } return 1; } // transforming_liquid_add(pos) int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) { GET_ENV_PTR; v3s16 p0 = read_v3s16(L, 1); env->getMap().transforming_liquid_add(p0); return 1; } // forceload_block(blockpos) // blockpos = {x=num, y=num, z=num} int ModApiEnvMod::l_forceload_block(lua_State *L) { GET_ENV_PTR; v3s16 blockpos = read_v3s16(L, 1); env->getForceloadedBlocks()->insert(blockpos); return 0; } // forceload_free_block(blockpos) // blockpos = {x=num, y=num, z=num} int ModApiEnvMod::l_forceload_free_block(lua_State *L) { GET_ENV_PTR; v3s16 blockpos = read_v3s16(L, 1); env->getForceloadedBlocks()->erase(blockpos); return 0; } void ModApiEnvMod::Initialize(lua_State *L, int top) { API_FCT(set_node); API_FCT(bulk_set_node); API_FCT(add_node); API_FCT(swap_node); API_FCT(add_item); API_FCT(remove_node); API_FCT(get_node); API_FCT(get_node_or_nil); API_FCT(get_node_light); API_FCT(place_node); API_FCT(dig_node); API_FCT(punch_node); API_FCT(get_node_max_level); API_FCT(get_node_level); API_FCT(set_node_level); API_FCT(add_node_level); API_FCT(add_entity); API_FCT(find_nodes_with_meta); API_FCT(get_meta); API_FCT(get_node_timer); API_FCT(get_player_by_name); API_FCT(get_objects_inside_radius); API_FCT(set_timeofday); API_FCT(get_timeofday); API_FCT(get_gametime); API_FCT(get_day_count); API_FCT(find_node_near); API_FCT(find_nodes_in_area); API_FCT(find_nodes_in_area_under_air); API_FCT(fix_light); API_FCT(emerge_area); API_FCT(delete_area); API_FCT(get_perlin); API_FCT(get_perlin_map); API_FCT(get_voxel_manip); API_FCT(clear_objects); API_FCT(spawn_tree); API_FCT(find_path); API_FCT(line_of_sight); API_FCT(raycast); API_FCT(transforming_liquid_add); API_FCT(forceload_block); API_FCT(forceload_free_block); } void ModApiEnvMod::InitializeClient(lua_State *L, int top) { API_FCT(get_timeofday); API_FCT(get_day_count); API_FCT(get_node_max_level); API_FCT(get_node_level); API_FCT(find_node_near); }