aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_env.cpp
Commit message (Expand)AuthorAge
* Add '/clearobjects quick'Kahrl2016-02-11
* Add callback parameter for core.emerge_area()kwolekr2015-11-02
* SAPI: Move core.get_us_time() to Util modulekwolekr2015-10-26
* SAPI: Mark all Lua API functions requiring envlockkwolekr2015-10-25
* Add /emergeblocks command and core.emerge_area() Lua APIkwolekr2015-09-23
* Push error handler afresh each time lua_pcall is usedKahrl2015-08-27
* SEnv: Remove static_exists from ActiveObjects in deleted blockskwolekr2015-08-16
* SAPI: Track last executed mod and include in error messageskwolekr2015-08-12
* Improve Script CPP API diagnosticskwolekr2015-08-05
* Add return list of individual counts to find_node_in_areaTeTpaAka2015-06-13
* Add core.find_nodes_with_meta() script APIkwolekr2015-05-05
* Use std::vector instead of std::set for Environment::getObjectsInsideRadiusLoic Blot2015-04-16
* For usages of assert() that are meant to persist in Release builds (when NDEB...Craig Robbins2015-03-07
* Change find_surface_nodes_in_area to find_nodes_in_area_under_airCraig Robbins2015-02-27
* Add find_surface_nodes_in_area LUA call which permit to only get the nodes wh...Loic Blot2015-02-27
* SAO work: ActiveObject types & SAO cleanup * Replace u8 types with ActiveObje...Loic Blot2015-02-17
* Performance Improvement: Use a cache which caches result for getFacePositions.Loic Blot2015-02-16
* Add ability to delete MapBlocks from mapkwolekr2015-01-15
* LuaVoxelManip: Remove blank allocatorkwolekr2014-12-29
* LuaVoxelManip: Add option to allocate blank datakwolekr2014-12-27
* Add support for NoiseParams in minetest.get_perlin() and add docs on NoisePar...kwolekr2014-12-12
* Add flags and lacunarity as new noise parameterskwolekr2014-12-07
* Remove most exceptions from getNode() (and variants)Craig Robbins2014-11-14
* Fix object reference pushing functions when called from coroutinesShadowNinja2014-10-07
* Add LuaVoxelManip methods: get_node_at() and set_node_at()kwolekr2014-09-01
* Fix seg fault if popping from empty stack (L-system trees)Craig Robbins2014-08-23
* Mod profiling supportsapier2014-08-19
* Use "core" namespace internallyShadowNinja2014-05-08
* Remove liquid_finite and weatherproller2014-04-18
* Pass pointed_thing to on_punch and minetest.register_on_punchnode callbacksShadowNinja2014-01-23
* Add forceloadingNovatux2014-01-11
* Make line_of_sight return blocking node positionstujones112013-12-12
* Optimize table creationShadowNinja2013-11-30
* Add minetest.swap_nodeNovatux2013-11-30
* Fix line_of_sight (AGAIN)sapier2013-11-25
* Pass a errfunc to lua_pcall to get a tracebackShadowNinja2013-11-15
* Weather: Clean up getHeat/getHumidity somewhatkwolekr2013-09-16
* Add minetest.get_gametime() API function, that returns the number of seconds ...Novatux2013-09-08
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Better snow fall, finite liquid transform, leveled nodes apiproller2013-07-28
* Weather supportproller2013-07-27
* LuaVoxelManip: Fix minor bug with set_lighting, remove coordinate params for ...kwolekr2013-06-29
* Apply various fixes to several thingskwolekr2013-06-27
* LuaVoxelManip: Separate VoxelManip data get/set from emerging/blitting data b...kwolekr2013-06-27
* Add Lua on_mapgen_init callback, and minetest.set_mapgen_params APIkwolekr2013-06-27
* Add minetest.get_mapgen_object to APIkwolekr2013-06-27
* Add LuaVoxelManipkwolekr2013-06-27
* Fix missing find_path and line_of_sightsapier2013-06-01
* Move scriptapi to separate folder (by sapier)sapier2013-05-25
pan class="hl kwd">itos(n_new.param2); os << ", " << serializeJsonString(n_new.meta); os << ')'; case TYPE_MODIFY_INVENTORY_STACK: os << "modify_inventory_stack ("; os << serializeJsonString(inventory_location); os << ", " << serializeJsonString(inventory_list); os << ", " << inventory_index; os << ", " << (inventory_add ? "add" : "remove"); os << ", " << serializeJsonString(inventory_stack.getItemString()); os << ')'; default: return "<unknown action>"; } return os.str(); } bool RollbackAction::isImportant(IGameDef *gamedef) const { if (type != TYPE_SET_NODE) return true; // If names differ, action is always important if(n_old.name != n_new.name) return true; // If metadata differs, action is always important if(n_old.meta != n_new.meta) return true; INodeDefManager *ndef = gamedef->ndef(); // Both are of the same name, so a single definition is needed const ContentFeatures &def = ndef->get(n_old.name); // If the type is flowing liquid, action is not important if (def.liquid_type == LIQUID_FLOWING) return false; // Otherwise action is important return true; } bool RollbackAction::getPosition(v3s16 *dst) const { switch (type) { case TYPE_SET_NODE: if (dst) *dst = p; return true; case TYPE_MODIFY_INVENTORY_STACK: { InventoryLocation loc; loc.deSerialize(inventory_location); if (loc.type != InventoryLocation::NODEMETA) { return false; } if (dst) *dst = loc.p; return true; } default: return false; } } bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const { try { switch (type) { case TYPE_NOTHING: return true; case TYPE_SET_NODE: { INodeDefManager *ndef = gamedef->ndef(); // Make sure position is loaded from disk map->emergeBlock(getContainerPos(p, MAP_BLOCKSIZE), false); // Check current node MapNode current_node = map->getNodeNoEx(p); std::string current_name = ndef->get(current_node).name; // If current node not the new node, it's bad if (current_name != n_new.name) { return false; } // Create rollback node MapNode n(ndef, n_old.name, n_old.param1, n_old.param2); // Set rollback node try { if (!map->addNodeWithEvent(p, n)) { infostream << "RollbackAction::applyRevert(): " << "AddNodeWithEvent failed at " << PP(p) << " for " << n_old.name << std::endl; return false; } if (n_old.meta.empty()) { map->removeNodeMetadata(p); } else { NodeMetadata *meta = map->getNodeMetadata(p); if (!meta) { meta = new NodeMetadata(gamedef->idef()); if (!map->setNodeMetadata(p, meta)) { delete meta; infostream << "RollbackAction::applyRevert(): " << "setNodeMetadata failed at " << PP(p) << " for " << n_old.name << std::endl; return false; } } std::istringstream is(n_old.meta, std::ios::binary); meta->deSerialize(is); } // Inform other things that the meta data has changed v3s16 blockpos = getContainerPos(p, MAP_BLOCKSIZE); MapEditEvent event; event.type = MEET_BLOCK_NODE_METADATA_CHANGED; event.p = blockpos; map->dispatchEvent(&event); // Set the block to be saved MapBlock *block = map->getBlockNoCreateNoEx(blockpos); if (block) { block->raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_REPORT_META_CHANGE); } } catch (InvalidPositionException &e) { infostream << "RollbackAction::applyRevert(): " << "InvalidPositionException: " << e.what() << std::endl; return false; } // Success return true; } case TYPE_MODIFY_INVENTORY_STACK: { InventoryLocation loc; loc.deSerialize(inventory_location); Inventory *inv = imgr->getInventory(loc); if (!inv) { infostream << "RollbackAction::applyRevert(): Could not get " "inventory at " << inventory_location << std::endl; return false; } InventoryList *list = inv->getList(inventory_list); if (!list) { infostream << "RollbackAction::applyRevert(): Could not get " "inventory list \"" << inventory_list << "\" in " << inventory_location << std::endl; return false; } if (list->getSize() <= inventory_index) { infostream << "RollbackAction::applyRevert(): List index " << inventory_index << " too large in " << "inventory list \"" << inventory_list << "\" in " << inventory_location << std::endl; return false; } // If item was added, take away item, otherwise add removed item if (inventory_add) { // Silently ignore different current item if (list->getItem(inventory_index).name != gamedef->idef()->getAlias(inventory_stack.name)) return false; list->takeItem(inventory_index, inventory_stack.count); } else { list->addItem(inventory_index, inventory_stack); } // Inventory was modified; send to clients imgr->setInventoryModified(loc); return true; } default: errorstream << "RollbackAction::applyRevert(): type not handled" << std::endl; return false; } } catch(SerializationError &e) { errorstream << "RollbackAction::applyRevert(): n_old.name=" << n_old.name << ", SerializationError: " << e.what() << std::endl; } return false; }