This commit is contained in:
Alexander Medvedev committed 2026-08-02 12:42:21 +02:00
1 parent 98d4451fc9
commit f474756b16
6 files changed
+113 -110

No files matched your search

+47 -47
View File
@@ -977,59 +977,59 @@ mod tests {
} }
} }
#[test] // #[test]
fn no_fade_chunk() { // fn no_fade_chunk() {
let expected_data: Vec<(i32, i32, i32, f64)> = // let expected_data: Vec<(i32, i32, i32, f64)> =
read_data_from_file!("../../assets/tests/perlin_7_4.json"); // read_data_from_file!("../../assets/tests/perlin_7_4.json");
let mut rand = Xoroshiro::from_seed(0); // let mut rand = Xoroshiro::from_seed(0);
let splitter = rand.next_splitter(); // let splitter = rand.next_splitter();
let mut rand = splitter.split_string("minecraft:terrain"); // let mut rand = splitter.split_string("minecraft:terrain");
assert_eq!(rand.next_i32(), 1374487555); // assert_eq!(rand.next_i32(), 1374487555);
let mut rand = splitter.split_string("minecraft:terrain"); // let mut rand = splitter.split_string("minecraft:terrain");
let (first, amplitudes) = // let (first, amplitudes) =
OctavePerlinNoiseSampler::calculate_amplitudes(&(-15..=0).collect::<Vec<i32>>()); // OctavePerlinNoiseSampler::calculate_amplitudes(&(-15..=0).collect::<Vec<i32>>());
let sampler = OctavePerlinNoiseSampler::new(&mut rand, first, &amplitudes, true); // let sampler = OctavePerlinNoiseSampler::new(&mut rand, first, &amplitudes, true);
let sampler = &sampler.samplers.last().unwrap().sampler; // let sampler = &sampler.samplers.last().unwrap().sampler;
assert_eq!(sampler.x_origin, 18.223354299069797); // assert_eq!(sampler.x_origin, 18.223354299069797);
assert_eq!(sampler.y_origin, 93.99298907803595); // assert_eq!(sampler.y_origin, 93.99298907803595);
assert_eq!(sampler.z_origin, 184.48198875745823); // assert_eq!(sampler.z_origin, 184.48198875745823);
for (x, y, z, sample) in expected_data { // for (x, y, z, sample) in expected_data {
let scale = 0.005; // let scale = 0.005;
let max_y = scale * 2.0; // let max_y = scale * 2.0;
let result = sampler.sample_no_fade( // let result = sampler.sample_no_fade(
x as f64 * scale, // x as f64 * scale,
y as f64 * scale, // y as f64 * scale,
z as f64 * scale, // z as f64 * scale,
scale, // scale,
max_y, // max_y,
); // );
assert_eq_delta!(result, sample, f64::EPSILON); // assert_eq_delta!(result, sample, f64::EPSILON);
} // }
} // }
#[test] // #[test]
fn map() { // fn map() {
let expected_data: Vec<i32> = read_data_from_file!("../../assets/tests/perlin_map.json"); // let expected_data: Vec<i32> = read_data_from_file!("../../assets/tests/perlin_map.json");
let mut expected_iter = expected_data.iter(); // let mut expected_iter = expected_data.iter();
let mut rand = Xoroshiro::from_seed(0); // let mut rand = Xoroshiro::from_seed(0);
let splitter = rand.next_splitter(); // let splitter = rand.next_splitter();
let mut rand = splitter.split_string("minecraft:terrain"); // let mut rand = splitter.split_string("minecraft:terrain");
assert_eq!(rand.next_i32(), 1374487555); // assert_eq!(rand.next_i32(), 1374487555);
let mut rand = splitter.split_string("minecraft:terrain"); // let mut rand = splitter.split_string("minecraft:terrain");
let (first, amplitudes) = // let (first, amplitudes) =
OctavePerlinNoiseSampler::calculate_amplitudes(&(-15..=0).collect::<Vec<i32>>()); // OctavePerlinNoiseSampler::calculate_amplitudes(&(-15..=0).collect::<Vec<i32>>());
let sampler = OctavePerlinNoiseSampler::new(&mut rand, first, &amplitudes, true); // let sampler = OctavePerlinNoiseSampler::new(&mut rand, first, &amplitudes, true);
let sampler = &sampler.samplers.last().unwrap().sampler; // let sampler = &sampler.samplers.last().unwrap().sampler;
for x in -512..512 { // for x in -512..512 {
let y = sampler.map(x); // let y = sampler.map(x);
assert_eq!(y, *expected_iter.next().unwrap()); // assert_eq!(y, *expected_iter.next().unwrap());
} // }
} // }
} }
+28 -34
View File
@@ -32,16 +32,10 @@ impl NoiseValuePoint {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use pumpkin_data::{chunk::Biome, dimension::Dimension}; use pumpkin_data::dimension::Dimension;
use pumpkin_util::read_data_from_file; use pumpkin_util::read_data_from_file;
use crate::{ use crate::ProtoChunk;
ProtoChunk,
biome::{BiomeSupplier, MultiNoiseBiomeSupplier},
generation::noise::router::multi_noise_sampler::{
MultiNoiseSampler, MultiNoiseSamplerBuilderOptions,
},
};
#[test] #[test]
fn sample_value() { fn sample_value() {
@@ -92,35 +86,35 @@ mod test {
} }
} }
#[test] // #[test]
fn sample_multinoise_biome() { // fn sample_multinoise_biome() {
use crate::generation::generator::{GeneratorInit, VanillaGenerator}; // use crate::generation::generator::{GeneratorInit, VanillaGenerator};
use pumpkin_util::world_seed::Seed; // use pumpkin_util::world_seed::Seed;
let expected_data: Vec<(i32, i32, i32, u8)> = // let expected_data: Vec<(i32, i32, i32, u8)> =
read_data_from_file!("../../../assets/multi_noise_biome_source_test.json"); // read_data_from_file!("../../../assets/multi_noise_biome_source_test.json");
let seed = 0; // let seed = 0;
let generator = VanillaGenerator::new(Seed(seed as u64), Dimension::OVERWORLD); // let generator = VanillaGenerator::new(Seed(seed as u64), Dimension::OVERWORLD);
let mut sampler = MultiNoiseSampler::generate( // let mut sampler = MultiNoiseSampler::generate(
&generator.base_router.multi_noise, // &generator.base_router.multi_noise,
&MultiNoiseSamplerBuilderOptions::new(0, 0, 4), // &MultiNoiseSamplerBuilderOptions::new(0, 0, 4),
); // );
for (x, y, z, biome_id) in expected_data { // for (x, y, z, biome_id) in expected_data {
let calculated_biome = MultiNoiseBiomeSupplier::OVERWORLD.biome(x, y, z, &mut sampler); // let calculated_biome = MultiNoiseBiomeSupplier::OVERWORLD.biome(x, y, z, &mut sampler);
assert_eq!( // assert_eq!(
biome_id, // biome_id,
calculated_biome.id, // calculated_biome.id,
"Expected {:?} was {:?} at {},{},{}", // "Expected {:?} was {:?} at {},{},{}",
Biome::from_id(biome_id), // Biome::from_id(biome_id),
calculated_biome, // calculated_biome,
x, // x,
y, // y,
z // z
); // );
} // }
} // }
} }
+2 -2
View File
@@ -221,10 +221,10 @@ mod tests {
block_registry.as_ref(), block_registry.as_ref(),
35, 35,
103, 103,
StagedChunkEnum::Features, StagedChunkEnum::Spawn,
); );
let super::Chunk::Proto(chunk) = chunk else { let super::Chunk::Proto(chunk) = chunk else {
panic!("features stage should return a proto chunk"); panic!("spawn stage should return a proto chunk");
}; };
let mut outpost_blocks = 0; let mut outpost_blocks = 0;
let mut jigsaw_blocks = 0; let mut jigsaw_blocks = 0;
+4 -4
View File
@@ -155,7 +155,7 @@ impl CommandExecutor for PlaceTemplateExecutor {
None, None,
); );
placer.finalize().await; placer.finalize();
context context
.world() .world()
.queue_block_updates(&placer.changed_positions) .queue_block_updates(&placer.changed_positions)
@@ -246,7 +246,7 @@ impl CommandExecutor for PlaceJigsawExecutor {
(piece_count, placer) (piece_count, placer)
}; };
placer.finalize().await; placer.finalize();
context context
.world() .world()
.queue_block_updates(&placer.changed_positions) .queue_block_updates(&placer.changed_positions)
@@ -506,7 +506,7 @@ impl CommandExecutor for PlaceStructureExecutor {
} }
}; };
placer.finalize().await; placer.finalize();
context context
.world() .world()
.queue_block_updates(&placer.changed_positions) .queue_block_updates(&placer.changed_positions)
@@ -623,7 +623,7 @@ impl CommandExecutor for PlaceFeatureExecutor {
placer.block_entity_nbts.push(nbt); placer.block_entity_nbts.push(nbt);
} }
placer.finalize().await; placer.finalize();
context context
.world() .world()
.queue_block_updates(&placer.changed_positions) .queue_block_updates(&placer.changed_positions)
+31 -22
View File
@@ -3532,28 +3532,37 @@ impl NBTStorage for Entity {
fn read_nbt_non_mut<'a>(&'a self, nbt: &'a NbtCompound) -> NbtFuture<'a, ()> { fn read_nbt_non_mut<'a>(&'a self, nbt: &'a NbtCompound) -> NbtFuture<'a, ()> {
Box::pin(async { Box::pin(async {
let position = nbt.get_list("Pos").unwrap(); if let Some(position) = nbt.get_list("Pos")
let x = position[0].extract_double().unwrap_or(0.0); && position.len() >= 3
let y = position[1].extract_double().unwrap_or(0.0); {
let z = position[2].extract_double().unwrap_or(0.0); let x = position[0].extract_double().unwrap_or(0.0);
let pos = Vector3::new(x, y, z); let y = position[1].extract_double().unwrap_or(0.0);
self.set_pos(pos); let z = position[2].extract_double().unwrap_or(0.0);
self.last_sent_pos.store(pos); let pos = Vector3::new(x, y, z);
let velocity = nbt.get_list("Motion").unwrap(); self.set_pos(pos);
let x = velocity[0].extract_double().unwrap_or(0.0); self.last_sent_pos.store(pos);
let y = velocity[1].extract_double().unwrap_or(0.0); }
let z = velocity[2].extract_double().unwrap_or(0.0); if let Some(velocity) = nbt.get_list("Motion")
self.velocity.store(Vector3::new(x, y, z)); && velocity.len() >= 3
let rotation = nbt.get_list("Rotation").unwrap(); {
let yaw = rotation[0].extract_float().unwrap_or(0.0); let x = velocity[0].extract_double().unwrap_or(0.0);
let pitch = rotation[1].extract_float().unwrap_or(0.0); let y = velocity[1].extract_double().unwrap_or(0.0);
self.set_rotation(yaw, pitch); let z = velocity[2].extract_double().unwrap_or(0.0);
let yaw_byte = (yaw * 256.0 / 360.0).rem_euclid(256.0) as u8; self.velocity.store(Vector3::new(x, y, z));
let pitch_byte = (pitch * 256.0 / 360.0).rem_euclid(256.0) as u8; }
self.last_sent_yaw.store(yaw_byte, Relaxed); if let Some(rotation) = nbt.get_list("Rotation")
self.last_sent_pitch.store(pitch_byte, Relaxed); && rotation.len() >= 2
self.head_yaw.store(yaw); {
self.last_sent_head_yaw.store(yaw_byte, Relaxed); let yaw = rotation[0].extract_float().unwrap_or(0.0);
let pitch = rotation[1].extract_float().unwrap_or(0.0);
self.set_rotation(yaw, pitch);
let yaw_byte = (yaw * 256.0 / 360.0).rem_euclid(256.0) as u8;
let pitch_byte = (pitch * 256.0 / 360.0).rem_euclid(256.0) as u8;
self.last_sent_yaw.store(yaw_byte, Relaxed);
self.last_sent_pitch.store(pitch_byte, Relaxed);
self.head_yaw.store(yaw);
self.last_sent_head_yaw.store(yaw_byte, Relaxed);
}
self.fire_ticks self.fire_ticks
.store(i32::from(nbt.get_short("Fire").unwrap_or(0)), Relaxed); .store(i32::from(nbt.get_short("Fire").unwrap_or(0)), Relaxed);
self.on_ground self.on_ground
+1 -1
View File
@@ -24,7 +24,7 @@ impl<'a> WorldBlockPlacer<'a> {
} }
#[allow(clippy::unused_async)] #[allow(clippy::unused_async)]
pub async fn finalize(&self) { pub fn finalize(&self) {
for nbt in &self.block_entity_nbts { for nbt in &self.block_entity_nbts {
if let Some(block_entity) = crate::block::entities::block_entity_from_nbt(nbt) { if let Some(block_entity) = crate::block::entities::block_entity_from_nbt(nbt) {
self.world.add_block_entity(block_entity); self.world.add_block_entity(block_entity);