From 7a159bdee50146ced2a0026124e4d5b62356b0f7 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 31 Aug 2022 20:16:39 +0000 Subject: [PATCH] add collision test --- azalea-physics/src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index e1c585e7..c2aa607a 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -173,4 +173,29 @@ mod tests { entity.pos().y ); } + #[test] + fn test_collision() { + let mut dim = Dimension::default(); + + dim.add_entity( + 0, + EntityData::new( + Uuid::from_u128(0), + Vec3 { + x: 0.5, + y: 70., + z: 0.5, + }, + ), + ); + dim.set_block_state(&BlockPos { x: 0, y: 68, z: 0 }, BlockState::Stone); + let mut entity = dim.entity_mut(0).unwrap(); + entity.ai_step(); + // delta will change, but it won't move until next tick + assert_eq!(entity.pos().y, 70.); + assert!(entity.delta.y < 0.); + entity.ai_step(); + // the second tick applies the delta to the position, but it also does collision + assert_eq!(entity.pos().y, 70.); + } }