Remove the inventory bonus raise on the armor inventory event

on_player_armor_inventory_changed for the restored armor is raised at
the end of the download's tick, after the inventory bonus of the armor's
equipment applied, so the raise is removed there instead of in the next
tick's on_tick. The raise is only made for armor with a grid, as the
event needs the armor to be restored.

A player leaving on the tick of a download no longer has the raise
removed from the character first, which shrank the main inventory
before the bonus applied and spilled the extra slots. The raise is
taken off the uploaded inventory bonus instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ILLISISandClaude Opus 5.5 committed 2026-10-18 22:34:34 +11:00
1 parent b32f5416a1
commit 4228b40562
2 files changed
+20 -20

No files matched your search

+5 -4
View File
@@ -83,7 +83,7 @@ local function last_slot_index(serialized)
end
--- Raise the inventory bonus of a character with its armor restored to fit a serialized main inventory
--- @return integer raise Slots added to character_inventory_slots_bonus, to be removed again on the next tick
--- @return integer raise Slots added to character_inventory_slots_bonus, removed again once the armor's bonus applies
local function raise_inventory_bonus(character, main)
local raise = math.max(0, last_slot_index(main) - #character.get_main_inventory())
character.character_inventory_slots_bonus = character.character_inventory_slots_bonus + raise
@@ -1386,12 +1386,13 @@ function serialize.deserialize_player(player, serialized, components, local_cont
serialize.deserialize_character(character, stats)
end
local craft = character and queue
-- The bonus of the armor's equipment (toolbelts) only applies on the next tick, so once the armor is
-- restored the main inventory is raised to fit the data
-- The bonus of the armor's equipment (toolbelts) only applies at the end of the tick, so once the armor is
-- restored the main inventory is raised to fit the data. Only for armor with a grid, restoring it raises
-- on_player_armor_inventory_changed which removes the raise.
spill = serialize.place_items(
serialize.item_destinations(player), inventories, not craft and queue and queue.ingredients or nil,
function()
if stats and inventories.main then
if stats and inventories.main and character and character.grid then
inventory_bonus_raise = raise_inventory_bonus(character, inventories.main)
end
end