1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-12-26 03:05:28 +01:00

[u_inv] Apply our modifications again

This commit is contained in:
LeMagnesium
2016-02-28 22:47:29 +01:00
parent 8be24274b5
commit c547b4028a
81 changed files with 135 additions and 57 deletions

79
mods/unified_inventory/bags.lua Normal file → Executable file
View File

@@ -10,10 +10,10 @@ unified_inventory.register_page("bags", {
local player_name = player:get_player_name()
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
formspec = formspec.."label[0,0;"..S("Bags").."]"
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]"
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]"
formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]"
formspec = formspec.."button[6,2;2,0.5;bag4;Bag 4]"
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]" .. "button[0,3;2,0.5;unequip_bag1;Unequip]"
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]" .. "button[2,3;2,0.5;unequip_bag2;Unequip]"
formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]" .. "button[4,3;2,0.5;unequip_bag3;Unequip]"
formspec = formspec.."button[6,2;2,0.5;bag4;Bag 4]" .. "button[6,3;2,0.5;unequip_bag4;Unequip]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag1;0.5,1;1,1;]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag2;2.5,1;1,1;]"
@@ -27,7 +27,8 @@ unified_inventory.register_button("bags", {
type = "image",
image = "ui_bags_icon.png",
tooltip = S("Bags"),
hide_lite=true
hide_lite=true,
show_with = false, --Modif MFF (Crabman 30/06/2015)
})
@@ -128,6 +129,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
unified_inventory.set_inventory_formspec(player, "bag"..i)
return
elseif fields["unequip_bag" .. i] then
local stack = unified_inventory.extract_bag(player, i)
if not stack then
return
elseif not player:get_inventory():room_for_item("main", stack) then
minetest.chat_send_player(player:get_player_name(), "You need one free slot in your main inventory")
return
end
player:get_inventory():add_item("main", stack)
end
end
end)
@@ -136,12 +146,20 @@ 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)
player:get_inventory():set_size(listname.."contents",
local pinv = player:get_inventory()
pinv:set_stack(listname, index, stack)
pinv:set_size(listname.."contents",
stack:get_definition().groups.bagslots)
-- Retrieve the serialized inventory if any
if stack:get_metadata() ~= "" then
for i, item in pairs(minetest.deserialize(stack:get_metadata())) do
pinv:set_stack(listname .. "contents", i, ItemStack(item))
end
end
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil)
allow_take = function()
return 0
end,
allow_put = function(inv, listname, index, stack, player)
if stack:get_definition().groups.bagslots then
@@ -150,13 +168,6 @@ minetest.register_on_joinplayer(function(player)
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname.."contents") 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,
@@ -193,15 +204,15 @@ minetest.register_craft({
output = "unified_inventory:bag_small",
recipe = {
{"", "farming:cotton", ""},
{"group:wool", "group:wool", "group:wool"},
{"group:wool", "group:wool", "group:wool"},
{"group:wool", "group:wool", "group:wool"},
{"group:wool", "group:wool", "group:wool"},
},
})
minetest.register_craft({
output = "unified_inventory:bag_medium",
recipe = {
{"", "", ""},
{"", "", ""},
{"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
},
@@ -210,9 +221,37 @@ minetest.register_craft({
minetest.register_craft({
output = "unified_inventory:bag_large",
recipe = {
{"", "", ""},
{"", "", ""},
{"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
},
})
function unified_inventory.extract_bag(player, id)
if not player then
minetest.log("error", "[u_inv] Invalid player for bag extraction : nil")
return
end
if tonumber(id) == nil or id > 4 or id < 0 then
minetest.log("error", "Invalid id: " .. (id or 'nil'))
return
end
local stack = player:get_inventory():get_stack("bag"..id, 1)
if not stack:get_definition().groups.bagslots then
return
end
local pinv = player:get_inventory()
local inv = pinv:get_list("bag" .. id .. "contents")
local list = {}
for i, item in pairs(inv) do
list[i] = item:to_table()
end
pinv:remove_item("bag" .. id, stack)
minetest.get_inventory({type = "detached", name = minetest.formspec_escape(player:get_player_name()) .. "_bags"}):set_stack("bag" .. id, 1, nil)
pinv:set_list("bag" .. id .. "contents", {})
stack:set_metadata(minetest.serialize(list))
return stack
end