copy detached stacks

This commit is contained in:
Thomas Rudin 2018-07-24 09:42:11 +02:00
parent 6864c647ac
commit 080b30dc7f
3 changed files with 53 additions and 15 deletions

View File

@ -1,4 +1,31 @@
local get_inv_name = function(player)
return "mission_chestput_" .. player:get_player_name()
end
local get_inv = function(player)
return minetest.get_inventory({type="detached",name=get_inv_name(player)})
end
-- setup detached inv
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
local inv = minetest.create_detached_inventory(get_inv_name(player), {
on_put = function(inv, listname, index, stack, player)
-- copy stack
local playerInv = player:get_inventory()
playerInv:add_item("main", stack)
end,
allow_take = function(inv, listname, index, stack, player)
-- remove from det inv
inv:remove_item("main", stack)
-- give player nothing
return 0
end
})
inv:set_size("main", 1)
end)
missions.register_step({
@ -9,10 +36,19 @@ missions.register_step({
return {count=1, name="default:cobble"}
end,
validate = function(pos, node, player, step, stepdata)
-- TODO
end,
edit_formspec = function(pos, node, player, stepnumber, step, stepdata)
--TODO: populate inv
local formspec = "size[8,8;]" ..
"label[0,0;Put items in chest]" ..
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
--"button_exit[1,1;4,1;read;Read items]" ..
"list[current_player;main;0,6;8,1;]" ..
"button_exit[0,7;8,1;save;Save]"
return formspec;
@ -21,6 +57,9 @@ missions.register_step({
update = function(fields, player, step, stepdata, show_editor, show_mission)
--TODO
if fields.read then
end
if fields.save then
show_mission()
end

View File

@ -4,7 +4,7 @@ local counter = {} -- playername -> count
missions.register_step({
type = "simpledig",
name = "Dig nodes",
name = "Dig any nodes",
create = function()
return {count=100}

View File

@ -18,6 +18,17 @@ minetest.register_on_joinplayer(function(player)
return 1
end
return 0
end,
on_put = function(inv, listname, index, stack, player)
-- copy stack
local playerInv = player:get_inventory()
playerInv:add_item("main", stack)
end,
allow_take = function(inv, listname, index, stack, player)
-- remove from det inv
inv:remove_item("main", stack)
-- give player nothing
return 0
end
})
@ -64,7 +75,6 @@ missions.register_step({
"label[0,0;Walk to (Step #" .. stepnumber .. ")]" ..
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
"button_exit[1,1;4,1;read;Read position]" ..
--TODO: escape
"label[0,2;" .. name .. "]" ..
@ -103,7 +113,7 @@ missions.register_step({
stepdata.description = fields.description
end
if fields.read then
if fields.save then
local inv = get_inv(player)
local stack = inv:get_stack("main", 1)
@ -114,19 +124,8 @@ missions.register_step({
stepdata.pos = pos
stepdata.name = name
--move item back to user
inv:remove_item("main", stack)
local playerInv = player:get_inventory()
playerInv:add_item("main", stack)
end
show_editor()
end
if fields.save then
show_mission()
end
end,