mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix overflow in PickupItem::amount and set persistence stack_size to i64
This commit is contained in:
parent
9264c10289
commit
7dd2072ced
@ -1585,7 +1585,12 @@ impl PickupItem {
|
|||||||
pub fn next_merge_check_mut(&mut self) -> &mut ProgramTime { &mut self.next_merge_check }
|
pub fn next_merge_check_mut(&mut self) -> &mut ProgramTime { &mut self.next_merge_check }
|
||||||
|
|
||||||
// Get the total amount of items in here
|
// 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
|
/// Remove any debug items if this is a container, used before dropping an
|
||||||
/// item from an inventory
|
/// item from an inventory
|
||||||
|
@ -187,7 +187,7 @@ pub fn convert_items_to_database_items(
|
|||||||
parent_container_item_id,
|
parent_container_item_id,
|
||||||
item_id,
|
item_id,
|
||||||
stack_size: if item.is_stackable() {
|
stack_size: if item.is_stackable() {
|
||||||
item.amount() as i32
|
item.amount().into()
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,8 @@ pub struct Item {
|
|||||||
pub item_id: i64,
|
pub item_id: i64,
|
||||||
pub parent_container_item_id: i64,
|
pub parent_container_item_id: i64,
|
||||||
pub item_definition_id: String,
|
pub item_definition_id: String,
|
||||||
pub stack_size: i32,
|
/// `u32::MAX` must fit inside this type
|
||||||
|
pub stack_size: i64,
|
||||||
pub position: String,
|
pub position: String,
|
||||||
pub properties: String,
|
pub properties: String,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user