aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-06-02 00:42:56 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-06-03 22:31:01 +0300
commit5f3c70061deea330a23be33164a34f675721d452 (patch)
tree12641af526dc7b4764cd4e4a0960fe470da21f1c
parentaba7134301e0fe49cb3a6b157d226e1405753237 (diff)
downloadminetest-5f3c70061deea330a23be33164a34f675721d452.tar.gz
minetest-5f3c70061deea330a23be33164a34f675721d452.tar.bz2
minetest-5f3c70061deea330a23be33164a34f675721d452.zip
Properly handle dropping of items from nodes, and disallow moving items directly between nodes
-rw-r--r--src/inventorymanager.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp
index 46f744f8b..b6740f1ba 100644
--- a/src/inventorymanager.cpp
+++ b/src/inventorymanager.cpp
@@ -203,6 +203,14 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
// Handle node metadata move
if(from_inv.type == InventoryLocation::NODEMETA &&
to_inv.type == InventoryLocation::NODEMETA &&
+ from_inv.p != to_inv.p)
+ {
+ errorstream<<"Directly moving items between two nodes is "
+ <<"disallowed."<<std::endl;
+ return;
+ }
+ else if(from_inv.type == InventoryLocation::NODEMETA &&
+ to_inv.type == InventoryLocation::NODEMETA &&
from_inv.p == to_inv.p)
{
lua_State *L = player->getEnv()->getLua();
@@ -354,12 +362,31 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
return;
}
- // Take item from source list
ItemStack item1;
- if(count == 0)
- item1 = list_from->changeItem(from_i, ItemStack());
+
+ // Handle node metadata take
+ if(from_inv.type == InventoryLocation::NODEMETA)
+ {
+ lua_State *L = player->getEnv()->getLua();
+ int count0 = count;
+ if(count0 == 0)
+ count0 = list_from->getItem(from_i).count;
+ infostream<<player->getDescription()<<" dropping "<<count0
+ <<" items from node at "<<PP(from_inv.p)<<std::endl;
+ ItemStack return_stack = scriptapi_node_on_metadata_inventory_take(
+ L, from_inv.p, from_list, from_i, count0, player);
+ if(return_stack.count == 0)
+ infostream<<"Node metadata gave no items"<<std::endl;
+ item1 = return_stack;
+ }
else
- item1 = list_from->takeItem(from_i, count);
+ {
+ // Take item from source list
+ if(count == 0)
+ item1 = list_from->changeItem(from_i, ItemStack());
+ else
+ item1 = list_from->takeItem(from_i, count);
+ }
// Drop the item and apply the returned ItemStack
ItemStack item2 = item1;