X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Frollback_interface.cpp;h=fef5389c1c29b8f69ca9606fb7a354a9ce7ca1f2;hb=5f1cd555cd9d1c64426e173b30b5b792d211c835;hp=bffe0a82c9b7caa6764424a90bfdfa0f7fd43e6c;hpb=452df1c723722183ebf3a332f7bcc355be5b2998;p=oweals%2Fminetest.git diff --git a/src/rollback_interface.cpp b/src/rollback_interface.cpp index bffe0a82c..fef5389c1 100644 --- a/src/rollback_interface.cpp +++ b/src/rollback_interface.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "util/string.h" #include "util/numeric.h" +#include "util/basic_macros.h" #include "map.h" #include "gamedef.h" #include "nodedef.h" @@ -32,12 +33,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "mapblock.h" -#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" - RollbackNode::RollbackNode(Map *map, v3s16 p, IGameDef *gamedef) { - INodeDefManager *ndef = gamedef->ndef(); + const NodeDefManager *ndef = gamedef->ndef(); MapNode n = map->getNodeNoEx(p); name = ndef->get(n).name; param1 = n.param1; @@ -45,7 +44,7 @@ RollbackNode::RollbackNode(Map *map, v3s16 p, IGameDef *gamedef) NodeMetadata *metap = map->getNodeMetadata(p); if (metap) { std::ostringstream os(std::ios::binary); - metap->serialize(os); + metap->serialize(os, 1); // FIXME: version bump?? meta = os.str(); } } @@ -91,7 +90,7 @@ bool RollbackAction::isImportant(IGameDef *gamedef) const // If metadata differs, action is always important if(n_old.meta != n_new.meta) return true; - INodeDefManager *ndef = gamedef->ndef(); + const NodeDefManager *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 @@ -129,7 +128,7 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam case TYPE_NOTHING: return true; case TYPE_SET_NODE: { - INodeDefManager *ndef = gamedef->ndef(); + const NodeDefManager *ndef = gamedef->ndef(); // Make sure position is loaded from disk map->emergeBlock(getContainerPos(p, MAP_BLOCKSIZE), false); // Check current node @@ -166,7 +165,7 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam } } std::istringstream is(n_old.meta, std::ios::binary); - meta->deSerialize(is); + meta->deSerialize(is, 1); // FIXME: version bump?? } // Inform other things that the meta data has changed v3s16 blockpos = getContainerPos(p, MAP_BLOCKSIZE); @@ -191,7 +190,6 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam case TYPE_MODIFY_INVENTORY_STACK: { InventoryLocation loc; loc.deSerialize(inventory_location); - std::string real_name = gamedef->idef()->getAlias(inventory_stack.name); Inventory *inv = imgr->getInventory(loc); if (!inv) { infostream << "RollbackAction::applyRevert(): Could not get " @@ -212,10 +210,12 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam << 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 != real_name) + if (list->getItem(inventory_index).name != + gamedef->idef()->getAlias(inventory_stack.name)) return false; list->takeItem(inventory_index, inventory_stack.count); } else {