diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index a2cd0024ce..2e2e170baf 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -1585,7 +1585,12 @@ impl PickupItem { pub fn next_merge_check_mut(&mut self) -> &mut ProgramTime { &mut self.next_merge_check } // Get the total amount of items in here - pub fn amount(&self) -> u32 { self.items.iter().map(Item::amount).sum() } + pub fn amount(&self) -> u32 { + self.items + .iter() + .map(Item::amount) + .fold(0, |total, amount| total.saturating_add(amount)) + } /// Remove any debug items if this is a container, used before dropping an /// item from an inventory diff --git a/server/src/persistence/character/conversions.rs b/server/src/persistence/character/conversions.rs index b28232f6c9..e4b4c7acaf 100644 --- a/server/src/persistence/character/conversions.rs +++ b/server/src/persistence/character/conversions.rs @@ -187,7 +187,7 @@ pub fn convert_items_to_database_items( parent_container_item_id, item_id, stack_size: if item.is_stackable() { - item.amount() as i32 + item.amount().into() } else { 1 }, diff --git a/server/src/persistence/models.rs b/server/src/persistence/models.rs index 70baed424b..8e0fdff938 100644 --- a/server/src/persistence/models.rs +++ b/server/src/persistence/models.rs @@ -11,7 +11,8 @@ pub struct Item { pub item_id: i64, pub parent_container_item_id: i64, pub item_definition_id: String, - pub stack_size: i32, + /// `u32::MAX` must fit inside this type + pub stack_size: i64, pub position: String, pub properties: String, }