give_initial_stuff: Respect items' stack_max
This commit is contained in:
parent
3db5696889
commit
2268485cdf
2 changed files with 12 additions and 2 deletions
|
@ -54,7 +54,7 @@ ctf_classes.register_on_changed(function(player, old, new)
|
||||||
|
|
||||||
local items = new.properties.initial_stuff
|
local items = new.properties.initial_stuff
|
||||||
for i = 1, #items do
|
for i = 1, #items do
|
||||||
inv:add_item("main", ItemStack(items[i]))
|
give_initial_stuff.give_item(inv, ItemStack(items[i]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
give_initial_stuff = {}
|
give_initial_stuff = {}
|
||||||
|
|
||||||
|
-- Add item to inv. Split item if count > stack_max using recursion
|
||||||
|
function give_initial_stuff.give_item(inv, item)
|
||||||
|
inv:add_item("main", item:take_item(item:get_stack_max()))
|
||||||
|
|
||||||
|
-- If item isn't empty, add the leftovers again
|
||||||
|
if not item:is_empty() then
|
||||||
|
give_initial_stuff.give_item(inv, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
setmetatable(give_initial_stuff, {
|
setmetatable(give_initial_stuff, {
|
||||||
__call = function(self, player)
|
__call = function(self, player)
|
||||||
minetest.log("action", "Giving initial stuff to player "
|
minetest.log("action", "Giving initial stuff to player "
|
||||||
|
@ -15,7 +25,7 @@ setmetatable(give_initial_stuff, {
|
||||||
local items = give_initial_stuff.get_stuff(player)
|
local items = give_initial_stuff.get_stuff(player)
|
||||||
|
|
||||||
for _, item in pairs(items) do
|
for _, item in pairs(items) do
|
||||||
inv:add_item("main", item)
|
give_initial_stuff.give_item(inv, ItemStack(item))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue