From 30b00b4715aef321dd469157f07fd5bbc60ae28e Mon Sep 17 00:00:00 2001 From: ILLISIS <92364928+ILLISIS@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:33:10 +1100 Subject: [PATCH] Keep spoil percent when serializing item stacks (#1096) serialize_item_stack did not store the spoil percent and deserialize_item_stack did not pass it to set_stack, so spoilable items arrived fresh after a transfer. Store it when above 0 and restore it. The percent is used instead of spoil_tick since tick counts differ between servers. Co-authored-by: ILLISIS Co-authored-by: Claude Opus 5.5 (1M context) --- packages/host/modules/clusterio/serialize.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/host/modules/clusterio/serialize.lua b/packages/host/modules/clusterio/serialize.lua index e1013f58..1d098cb7 100644 --- a/packages/host/modules/clusterio/serialize.lua +++ b/packages/host/modules/clusterio/serialize.lua @@ -17,6 +17,7 @@ end local has_create_grid = compat.version_ge("1.1.7") local has_quality = compat.version_ge("2.0.0") +local has_spoilage = compat.version_ge("2.0.0") -- Equipment Grids are serialized into an array of equipment entries -- where ench entry is a table with the following fields: @@ -106,6 +107,7 @@ end -- c: count -- q: quality (optional) -- h: health (optional) +-- p: spoil percent (optional) -- d: durability (optional) -- a: ammo count (optional) -- l: label (optional) @@ -139,6 +141,7 @@ function serialize.serialize_item_stack(slot, entry) entry.c = slot.count if has_quality and slot.quality.level ~= 0 then entry.q = slot.quality.name end if slot.health < 1 then entry.h = slot.health end + if has_spoilage and slot.spoil_percent > 0 then entry.p = slot.spoil_percent end if slot.type == "tool" and slot.durability then entry.d = slot.durability end if slot.type == "ammo" then entry.a = slot.ammo end if slot.is_item_with_label then @@ -177,6 +180,7 @@ function serialize.deserialize_item_stack(slot, entry) } if entry.q then item_stack.quality = entry.q end if entry.h then item_stack.health = entry.h end + if entry.p then item_stack.spoil_percent = entry.p end if entry.d then item_stack.durability = entry.d end if entry.a then item_stack.ammo = entry.a end