From: PilzAdam Date: Wed, 21 Nov 2012 17:39:31 +0000 (+0100) Subject: Use full stacks in the creative inventory and add a trash field X-Git-Tag: 0.4.4~21 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dfa0f096ce7f32ac5aa791ffae5923994174710f;p=oweals%2Fminetest_game.git Use full stacks in the creative inventory and add a trash field --- diff --git a/mods/creative/init.lua b/mods/creative/init.lua index a18140bb..22877b5a 100644 --- a/mods/creative/init.lua +++ b/mods/creative/init.lua @@ -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