2013-09-21 21:40:20 +02:00
|
|
|
-- Bags for Minetest
|
2012-12-02 10:08:32 +01:00
|
|
|
|
2013-09-21 21:40:20 +02:00
|
|
|
-- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
|
|
|
-- License: GPLv3
|
2012-12-02 10:08:32 +01:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
|
|
|
|
on_put = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, stack)
|
2013-09-21 21:40:20 +02:00
|
|
|
player:get_inventory():set_size(listname.."contents",
|
|
|
|
stack:get_definition().groups.bagslots)
|
2012-12-02 10:08:32 +01:00
|
|
|
end,
|
|
|
|
on_take = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, nil)
|
|
|
|
end,
|
|
|
|
allow_put = function(inv, listname, index, stack, player)
|
|
|
|
if stack:get_definition().groups.bagslots then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
allow_take = function(inv, listname, index, stack, player)
|
|
|
|
if player:get_inventory():is_empty(listname.."contents")==true then
|
|
|
|
return stack:get_count()
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
for i=1,4 do
|
|
|
|
local bag = "bag"..i
|
|
|
|
player_inv:set_size(bag, 1)
|
|
|
|
bags_inv:set_size(bag, 1)
|
2013-09-21 21:40:20 +02:00
|
|
|
bags_inv:set_stack(bag, 1, player_inv:get_stack(bag, 1))
|
2012-12-02 10:08:32 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- register bag tools
|
|
|
|
minetest.register_tool("unified_inventory:bag_small", {
|
|
|
|
description = "Small Bag",
|
|
|
|
inventory_image = "bags_small.png",
|
|
|
|
groups = {bagslots=8},
|
|
|
|
})
|
2013-09-21 21:40:20 +02:00
|
|
|
|
2012-12-02 10:08:32 +01:00
|
|
|
minetest.register_tool("unified_inventory:bag_medium", {
|
|
|
|
description = "Medium Bag",
|
|
|
|
inventory_image = "bags_medium.png",
|
|
|
|
groups = {bagslots=16},
|
|
|
|
})
|
2013-09-21 21:40:20 +02:00
|
|
|
|
2012-12-02 10:08:32 +01:00
|
|
|
minetest.register_tool("unified_inventory:bag_large", {
|
|
|
|
description = "Large Bag",
|
|
|
|
inventory_image = "bags_large.png",
|
|
|
|
groups = {bagslots=24},
|
|
|
|
})
|
|
|
|
|
|
|
|
-- register bag crafts
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "unified_inventory:bag_small",
|
|
|
|
recipe = {
|
2013-09-21 21:40:20 +02:00
|
|
|
{"", "default:stick", ""},
|
|
|
|
{"group:wood", "group:wood", "group:wood"},
|
|
|
|
{"group:wood", "group:wood", "group:wood"},
|
|
|
|
},
|
2012-12-02 10:08:32 +01:00
|
|
|
})
|
2013-09-21 21:40:20 +02:00
|
|
|
|
2012-12-02 10:08:32 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "unified_inventory:bag_medium",
|
|
|
|
recipe = {
|
2013-09-21 21:40:20 +02:00
|
|
|
{"", "", ""},
|
|
|
|
{"default:stick", "unified_inventory:bag_small", "default:stick"},
|
|
|
|
{"default:stick", "unified_inventory:bag_small", "default:stick"},
|
|
|
|
},
|
2012-12-02 10:08:32 +01:00
|
|
|
})
|
2013-09-21 21:40:20 +02:00
|
|
|
|
2012-12-02 10:08:32 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "unified_inventory:bag_large",
|
|
|
|
recipe = {
|
2013-09-21 21:40:20 +02:00
|
|
|
{"", "", ""},
|
|
|
|
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
|
|
|
|
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
|
2012-12-02 10:08:32 +01:00
|
|
|
},
|
|
|
|
})
|
2013-09-21 21:40:20 +02:00
|
|
|
|