ShadowNinja
2013-07-17 ee0765804c0a21deeb2f33c22ac1a36cb0db5f43
commit | author | age
ee0765 1 -- Bags for Minetest
a4a3c2 2
ee0765 3 -- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
S 4 -- License: GPLv3
a4a3c2 5
R 6 minetest.register_on_joinplayer(function(player)
7     local player_inv = player:get_inventory()
8     local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
9         on_put = function(inv, listname, index, stack, player)
10             player:get_inventory():set_stack(listname, index, stack)
ee0765 11             player:get_inventory():set_size(listname.."contents",
S 12                     stack:get_definition().groups.bagslots)
a4a3c2 13         end,
R 14         on_take = function(inv, listname, index, stack, player)
15             player:get_inventory():set_stack(listname, index, nil)
16         end,
17         allow_put = function(inv, listname, index, stack, player)
18             if stack:get_definition().groups.bagslots then
19                 return 1
20             else
21                 return 0
22             end
23         end,
24         allow_take = function(inv, listname, index, stack, player)
25             if player:get_inventory():is_empty(listname.."contents")==true then
26                 return stack:get_count()
27             else
28                 return 0
29             end
30         end,
31         allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
32             return 0
33         end,
34     })
35     for i=1,4 do
36         local bag = "bag"..i
37         player_inv:set_size(bag, 1)
38         bags_inv:set_size(bag, 1)
ee0765 39         bags_inv:set_stack(bag, 1, player_inv:get_stack(bag, 1))
a4a3c2 40     end
R 41 end)
42
43 -- register bag tools
44 minetest.register_tool("unified_inventory:bag_small", {
45     description = "Small Bag",
46     inventory_image = "bags_small.png",
47     groups = {bagslots=8},
48 })
ee0765 49
a4a3c2 50 minetest.register_tool("unified_inventory:bag_medium", {
R 51     description = "Medium Bag",
52     inventory_image = "bags_medium.png",
53     groups = {bagslots=16},
54 })
ee0765 55
a4a3c2 56 minetest.register_tool("unified_inventory:bag_large", {
R 57     description = "Large Bag",
58     inventory_image = "bags_large.png",
59     groups = {bagslots=24},
60 })
61
62 -- register bag crafts
63 minetest.register_craft({
64     output = "unified_inventory:bag_small",
65     recipe = {
ee0765 66         {"",           "default:stick", ""},
S 67         {"group:wood", "group:wood",    "group:wood"},
68         {"group:wood", "group:wood",    "group:wood"},
69     },
a4a3c2 70 })
ee0765 71
a4a3c2 72 minetest.register_craft({
R 73     output = "unified_inventory:bag_medium",
74     recipe = {
ee0765 75         {"",              "",                            ""},
S 76         {"default:stick", "unified_inventory:bag_small", "default:stick"},
77         {"default:stick", "unified_inventory:bag_small", "default:stick"},
78     },
a4a3c2 79 })
ee0765 80
a4a3c2 81 minetest.register_craft({
R 82     output = "unified_inventory:bag_large",
83     recipe = {
ee0765 84         {"",              "",                             ""},
S 85         {"default:stick", "unified_inventory:bag_medium", "default:stick"},
86         {"default:stick", "unified_inventory:bag_medium", "default:stick"},
a4a3c2 87     },
R 88 })
ee0765 89