This is the test code I wrote up.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local out_inventory = minetest.create_detached_inventory("out", {
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
print("out - allow_move")
return count
end,
allow_put = function(inv, listname, index, stack, player)
print("out - allow_put")
return stack:get_count()
end,
allow_take = function(inv, listname, index, stack, player)
print("out - allow_take")
return stack:get_count()
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
print("out - on_move")
end,
on_put = function(inv, listname, index, stack, player)
print("out - on_put")
end,
on_take = function(inv, listname, index, stack, player)
print("out - on_take")
end
})
out_inventory:set_size("out", 1)
local formspec = "size[10,8;]"
formspec = formspec .. "list[current_player;in;1,1;1,1;]"
formspec = formspec .. "list[detached:out;out;4,1;1,1;]"
formspec = formspec .. "list[current_player;main;1,3;8,4;]"
local timer = 0
minetest.register_globalstep(function(elapsed_time)
timer = timer + elapsed_time
if timer >= 0.33 then
if out_inventory:get_stack("out", 1):is_empty() then
print("output is empty")
end
-- Update the inventories of all players.
for index, player in ipairs(minetest.get_connected_players()) do
local inventory = player:get_inventory()
if inventory:is_empty("in") then
out_inventory:set_stack("out", 1, nil)
else
local input_stack = inventory:get_stack("in", 1)
input_stack:set_count(1)
out_inventory:set_stack("out", 1, input_stack)
end
end
timer = 0
end
end)
minetest.register_on_joinplayer(function(player)
player:get_inventory():set_size("in", 1)
player:set_inventory_formspec(formspec)
end)
This will replace the player inventory with the custom inventory which has two additional slots, the left for input, the right for output (it's basically copying the item you give it).
No if I take something from the output slot, none of the events of the inventory register, neither is the output directory empty. Only if I actually place the item in another inventory "something happens".