Use full stacks in the creative inventory and add a trash field
authorPilzAdam <adam-k@outlook.com>
Wed, 21 Nov 2012 17:39:31 +0000 (18:39 +0100)
committerPilzAdam <adam-k@outlook.com>
Sun, 25 Nov 2012 13:09:25 +0000 (14:09 +0100)
mods/creative/init.lua

index a18140bb7bdfbfaaa07b568e86fd764bfcf65516..22877b5aecb9f2e29dec3420c6e691d9ba032090 100644 (file)
@@ -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