From aba7134301e0fe49cb3a6b157d226e1405753237 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 2 Jun 2012 00:33:51 +0300 Subject: on_metadata_inventory_{move,offer,take} --- src/inventorymanager.cpp | 91 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 17 deletions(-) (limited to 'src/inventorymanager.cpp') diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index b04a1c177..46f744f8b 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "utility.h" #include "craftdef.h" +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" + /* InventoryLocation */ @@ -197,27 +199,82 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame <<", to_list=\""<moveItem(from_i, list_to, to_i, count); + + // Handle node metadata move + if(from_inv.type == InventoryLocation::NODEMETA && + to_inv.type == InventoryLocation::NODEMETA && + from_inv.p == to_inv.p) + { + lua_State *L = player->getEnv()->getLua(); + int count0 = count; + if(count0 == 0) + count0 = list_from->getItem(from_i).count; + infostream<getDescription()<<" moving "<getEnv()->getLua(); + int count0 = count; + if(count0 == 0) + count0 = list_from->getItem(from_i).count; + infostream<getDescription()<<" taking "<addItem(to_i, return_stack); + list_to->addItem(return_stack); // Force return of everything + } + // Handle node metadata offer + else if(to_inv.type == InventoryLocation::NODEMETA) + { + lua_State *L = player->getEnv()->getLua(); + int count0 = count; + if(count0 == 0) + count0 = list_from->getItem(from_i).count; + ItemStack offer_stack = list_from->takeItem(from_i, count0); + infostream<getDescription()<<" offering " + <addItem(from_i, reject_stack); + list_from->addItem(reject_stack); // Force return of everything + } + // Handle regular move + else + { + /* + This performs the actual movement + + If something is wrong (source item is empty, destination is the + same as source), nothing happens + */ + list_from->moveItem(from_i, list_to, to_i, count); + + infostream<<"IMoveAction::apply(): moved " + <<" count="<