mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 23:10:17 +01:00
Use full stacks in the creative inventory and add a trash field
This commit is contained in:
parent
e9ad8d06c8
commit
dfa0f096ce
@ -14,11 +14,7 @@ minetest.after(0, function()
|
||||
end
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
@ -54,8 +50,7 @@ minetest.after(0, function()
|
||||
if stack:get_stack_max() == 1 then
|
||||
stack2 = ItemStack(stack:get_name())
|
||||
else
|
||||
-- Insert half full so that a taken stack can be put back
|
||||
stack2 = ItemStack(stack:get_name().." "..(stack:get_stack_max()/2))
|
||||
stack2 = ItemStack(stack:get_name().." "..stack:get_stack_max())
|
||||
end
|
||||
inv:add_item("main", stack2)
|
||||
end
|
||||
@ -63,6 +58,24 @@ minetest.after(0, function()
|
||||
print("creative inventory size: "..dump(creative_inventory.creative_inventory_size))
|
||||
end)
|
||||
|
||||
-- Create the trash field
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
||||
pagenum = math.floor(pagenum)
|
||||
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
||||
@ -74,7 +87,9 @@ creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
||||
"list[detached:creative;main;0.3,0.5;4,6;"..tostring(start_i).."]"..
|
||||
"label[2.0,6.55;"..tostring(pagenum).."/"..tostring(pagemax).."]"..
|
||||
"button[0.3,6.5;1.6,1;creative_prev;<<]"..
|
||||
"button[2.7,6.5;1.6,1;creative_next;>>]")
|
||||
"button[2.7,6.5;1.6,1;creative_next;>>]"..
|
||||
"label[5,1.5;Trash:]"..
|
||||
"list[detached:creative_trash;main;5,2;1,1;]")
|
||||
end
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
-- If in creative mode, modify player's inventory forms
|
||||
|
Loading…
Reference in New Issue
Block a user