aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-06-02 00:33:51 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-06-03 22:31:01 +0300
commitaba7134301e0fe49cb3a6b157d226e1405753237 (patch)
tree32b35873b359483a34babe416ea654f9fe9471ac /builtin
parentd7447cdf9e4df3c345218886ab2bae0e0cc4fc55 (diff)
downloadminetest-aba7134301e0fe49cb3a6b157d226e1405753237.tar.gz
minetest-aba7134301e0fe49cb3a6b157d226e1405753237.tar.bz2
minetest-aba7134301e0fe49cb3a6b157d226e1405753237.zip
on_metadata_inventory_{move,offer,take}
Diffstat (limited to 'builtin')
-rw-r--r--builtin/item.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/builtin/item.lua b/builtin/item.lua
index d30b439aa..eb8c556de 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -262,6 +262,41 @@ function minetest.node_dig(pos, node, digger)
end
end
+function minetest.node_metadata_inventory_move_allow_all(pos, from_list,
+ from_index, to_list, to_index, count, player)
+ minetest.log("verbose", "node_metadata_inventory_move_allow_all")
+ local meta = minetest.env:get_meta(pos)
+ local inv = meta:get_inventory()
+
+ local from_stack = inv:get_stack(from_list, from_index)
+ local taken_items = from_stack:take_item(count)
+ inv:set_stack(from_list, from_index, from_stack)
+
+ local to_stack = inv:get_stack(to_list, to_index)
+ to_stack:add_item(taken_items)
+ inv:set_stack(to_list, to_index, to_stack)
+end
+
+function minetest.node_metadata_inventory_offer_allow_all(pos, listname, index, stack, player)
+ minetest.log("verbose", "node_metadata_inventory_offer_allow_all")
+ local meta = minetest.env:get_meta(pos)
+ local inv = meta:get_inventory()
+ local the_stack = inv:get_stack(listname, index)
+ the_stack:add_item(stack)
+ inv:set_stack(listname, index, the_stack)
+ return ItemStack("")
+end
+
+function minetest.node_metadata_inventory_take_allow_all(pos, listname, index, count, player)
+ minetest.log("verbose", "node_metadata_inventory_take_allow_all")
+ local meta = minetest.env:get_meta(pos)
+ local inv = meta:get_inventory()
+ local the_stack = inv:get_stack(listname, index)
+ local taken_items = the_stack:take_item(count)
+ inv:set_stack(listname, index, the_stack)
+ return taken_items
+end
+
-- This is used to allow mods to redefine minetest.item_place and so on
local function redef_wrapper(table, name)
return function(...)
@@ -295,6 +330,12 @@ minetest.nodedef_default = {
on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch
on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig
+ on_receive_fields = nil,
+
+ on_metadata_inventory_move = minetest.node_metadata_inventory_move_allow_all,
+ on_metadata_inventory_offer = minetest.node_metadata_inventory_offer_allow_all,
+ on_metadata_inventory_take = minetest.node_metadata_inventory_take_allow_all,
+
-- Node properties
drawtype = "normal",
visual_scale = 1.0,