From ce9760c7c89db22bbc57a15acfe5f8faf8468a4e Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Mon, 16 Nov 2020 09:03:12 -0800 Subject: [PATCH] Fix give_initial_stuff overflowing stacks --- mods/other/give_initial_stuff/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mods/other/give_initial_stuff/init.lua b/mods/other/give_initial_stuff/init.lua index 13ef57f..20a697c 100644 --- a/mods/other/give_initial_stuff/init.lua +++ b/mods/other/give_initial_stuff/init.lua @@ -23,11 +23,15 @@ function give_initial_stuff.give_item(inv, item) -- Don't duplicate stacks if inv:contains_item("main", item:get_name()) then - local safeguard = 1 - -- Do a fast refill of stack if needed - while not inv:contains_item("main", item:get_name().." "..item:get_stack_max()-5) do + local safeguard = 0 + local itemcount = item:get_count()-5 + 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 - inv:add_item("main", item:get_name().." 5") + + inv:add_item("main", item:get_name() .. " 5") if safeguard >= 500 then minetest.log("error", "[give_initial_stuff] Something went wrong when filling stack "..dump(item:get_name()))