Fix give_initial_stuff overflowing stacks
This commit is contained in:
parent
01ba809ff4
commit
ce9760c7c8
1 changed files with 8 additions and 4 deletions
|
@ -23,10 +23,14 @@ function give_initial_stuff.give_item(inv, item)
|
||||||
|
|
||||||
-- Don't duplicate stacks
|
-- Don't duplicate stacks
|
||||||
if inv:contains_item("main", item:get_name()) then
|
if inv:contains_item("main", item:get_name()) then
|
||||||
local safeguard = 1
|
local safeguard = 0
|
||||||
-- Do a fast refill of stack if needed
|
local itemcount = item:get_count()-5
|
||||||
while not inv:contains_item("main", item:get_name().." "..item:get_stack_max()-5) do
|
if itemcount < 0 then itemcount = 0 end
|
||||||
|
|
||||||
|
-- Replace stack if it's smaller than what we want to add
|
||||||
|
while not inv:contains_item("main", ("%s %d"):format(item:get_name(), itemcount)) do
|
||||||
safeguard = safeguard + 1
|
safeguard = safeguard + 1
|
||||||
|
|
||||||
inv:add_item("main", item:get_name() .. " 5")
|
inv:add_item("main", item:get_name() .. " 5")
|
||||||
|
|
||||||
if safeguard >= 500 then
|
if safeguard >= 500 then
|
||||||
|
|
Loading…
Reference in a new issue