mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'crab/pickupitem-amount-overflow' into 'master'
Fix overflow in PickupItem::amount See merge request veloren/veloren!4477
This commit is contained in:
commit
4c35ef95f7
@ -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
|
||||
|
@ -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
|
||||
},
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user