mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 08:22:33 +00:00
fix: prevent capacity overflow crash (#2348)
* fix: prevent capacity overflow crash when flying with elytra or in creative mode The NoiseBasedCountPlacementModifier::get_count() can return negative i32 values when foliage noise sampling produces negative results at certain world coordinates. The previous code cast this negative i32 directly to usize, causing an integer wrap to ~18 quintillion, which triggered a capacity overflow panic in Vec allocation during chunk feature generation. This aligns with vanilla Minecraft behavior which also clamps the count to a minimum of 0 before using it. Closes #2345 * Hi
This commit is contained in:
@@ -516,7 +516,7 @@ pub trait CountPlacementModifierBase {
|
||||
random: &mut RandomGenerator,
|
||||
pos: BlockPos,
|
||||
) -> Box<dyn Iterator<Item = BlockPos>> {
|
||||
let count = self.get_count(random, pos);
|
||||
let count = self.get_count(random, pos).max(0); // Vanilla treats negative counts as 0, but `i32 as usize` in Rust would wrap.
|
||||
Box::new(std::iter::repeat_n(pos, count as usize))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user