From 1e879ead47d1e9ca29b1ad77243ce332f1247298 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 16 Mar 2025 08:07:23 +0000 Subject: [PATCH] afk pool test --- azalea-physics/tests/physics.rs | 138 ++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index c9fcdf97..396c34f9 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -1,5 +1,9 @@ use std::sync::Arc; +use azalea_block::{ + BlockState, block_state::BlockStateIntegerRepr, fluid_state::to_or_from_legacy_fluid_level, + properties::WaterLevel, +}; use azalea_core::{ position::{BlockPos, ChunkPos, Vec3}, registry_holder::RegistryHolder, @@ -409,3 +413,137 @@ fn spawn_and_unload_world() { app.world_mut().run_schedule(GameTick); app.update(); } + +#[test] +fn test_afk_pool() { + let mut app = make_test_app(); + let world_lock = insert_overworld(&mut app); + let mut partial_world = PartialInstance::default(); + + partial_world.chunks.set( + &ChunkPos { x: 0, z: 0 }, + Some(Chunk::default()), + &mut world_lock.write().chunks, + ); + let setblock = |x: i32, y: i32, z: i32, b: BlockState| { + world_lock + .write() + .chunks + .set_block_state(&BlockPos { x, y, z }, b); + }; + + let stone = azalea_block::blocks::Stone {}.into(); + let sign = azalea_block::blocks::OakSign { + rotation: azalea_block::properties::OakSignRotation::_0, + waterlogged: false, + } + .into(); + let water = |level: u8| { + BlockState::from(azalea_block::blocks::Water { + level: WaterLevel::from(to_or_from_legacy_fluid_level(level) as BlockStateIntegerRepr), + }) + }; + + let mut y = 69; + + // first layer + { + setblock(1, y, 1, stone); + setblock(2, y, 1, stone); + setblock(3, y, 1, stone); + setblock(3, y, 2, stone); + setblock(3, y, 3, stone); + setblock(2, y, 3, stone); + setblock(1, y, 3, stone); + setblock(1, y, 2, stone); + } + // second layer + y += 1; + { + setblock(1, y, 0, stone); + setblock(2, y, 0, stone); + setblock(3, y, 0, stone); + + setblock(0, y, 1, stone); + setblock(0, y, 2, stone); + setblock(0, y, 3, stone); + + setblock(1, y, 4, stone); + setblock(2, y, 4, stone); + setblock(3, y, 4, stone); + + setblock(4, y, 1, stone); + setblock(4, y, 2, stone); + setblock(4, y, 3, stone); + + // middle block + setblock(2, y, 2, stone); + + // sign + setblock(1, y, 1, sign); + + // water + setblock(1, y, 2, water(8)); + setblock(1, y, 3, water(7)); + setblock(2, y, 3, water(6)); + setblock(3, y, 3, water(5)); + setblock(3, y, 2, water(4)); + setblock(3, y, 1, water(3)); + setblock(2, y, 1, water(2)); + } + // third layer + y += 1; + { + setblock(1, y, 1, water(8)); + setblock(2, y, 1, sign); + } + + let entity = app + .world_mut() + .spawn(( + EntityBundle::new( + Uuid::nil(), + Vec3 { + x: 3.5, + y: 70., + z: 1.5, + }, + azalea_registry::EntityKind::Player, + ResourceLocation::new("minecraft:overworld"), + ), + MinecraftEntityId(0), + LocalEntity, + )) + .id(); + + let mut blocks_visited = Vec::new(); + let mut loops_done = 0; + + for _ in 0..300 { + app.world_mut().run_schedule(GameTick); + app.update(); + + let entity_pos = app.world_mut().get::(entity).unwrap(); + let entity_block_pos = BlockPos::from(entity_pos); + + if !blocks_visited.contains(&entity_block_pos) { + blocks_visited.push(entity_block_pos); + + if blocks_visited.len() == 8 { + loops_done += 1; + blocks_visited.clear(); + } + } + } + + assert_eq!( + blocks_visited.into_iter().collect::>(), + vec![ + BlockPos::new(3, 70, 2), + BlockPos::new(3, 70, 1), + BlockPos::new(2, 70, 1), + BlockPos::new(1, 70, 1), + ] + ); + assert_eq!(loops_done, 1); +}