From 74b52a1fc12334c54eb671c1340e5e835e7bd33b Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 22 Feb 2025 21:09:35 +0000 Subject: [PATCH] fix is_trapdoor_useable_as_ladder and add test --- azalea-entity/src/plugin/mod.rs | 62 +++++++++++++++++++++++++++++++-- azalea-inventory/src/lib.rs | 2 -- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index e8889637..560d0ec6 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -168,10 +168,10 @@ fn is_trapdoor_useable_as_ladder( } // and the ladder must be facing the same direction as the trapdoor let ladder_facing = block_below - .property::() + .property::() .expect("ladder block must have facing property"); let trapdoor_facing = block_state - .property::() + .property::() .expect("trapdoor block must have facing property"); if ladder_facing != trapdoor_facing { return false; @@ -230,3 +230,61 @@ pub fn update_in_loaded_chunk( } } } + +#[cfg(test)] +mod tests { + use azalea_block::{ + blocks::{Ladder, OakTrapdoor}, + properties::{FacingCardinal, TopBottom}, + }; + use azalea_core::position::{BlockPos, ChunkPos}; + use azalea_world::{Chunk, ChunkStorage, Instance, PartialInstance}; + + use super::is_trapdoor_useable_as_ladder; + + #[test] + fn test_is_trapdoor_useable_as_ladder() { + let mut partial_instance = PartialInstance::default(); + let mut chunks = ChunkStorage::default(); + partial_instance.chunks.set( + &ChunkPos { x: 0, z: 0 }, + Some(Chunk::default()), + &mut chunks, + ); + partial_instance.chunks.set_block_state( + &BlockPos::new(0, 0, 0), + azalea_registry::Block::Stone.into(), + &chunks, + ); + + let ladder = Ladder { + facing: FacingCardinal::East, + waterlogged: false, + }; + partial_instance + .chunks + .set_block_state(&BlockPos::new(0, 0, 0), ladder.into(), &chunks); + + let trapdoor = OakTrapdoor { + facing: FacingCardinal::East, + half: TopBottom::Bottom, + open: true, + powered: false, + waterlogged: false, + }; + partial_instance + .chunks + .set_block_state(&BlockPos::new(0, 1, 0), trapdoor.into(), &chunks); + + let instance = Instance::from(chunks); + let trapdoor_matches_ladder = is_trapdoor_useable_as_ladder( + instance + .get_block_state(&BlockPos::new(0, 1, 0)) + .unwrap_or_default(), + BlockPos::new(0, 1, 0), + &instance, + ); + + assert!(trapdoor_matches_ladder); + } +} diff --git a/azalea-inventory/src/lib.rs b/azalea-inventory/src/lib.rs index f844d955..91d9f48d 100644 --- a/azalea-inventory/src/lib.rs +++ b/azalea-inventory/src/lib.rs @@ -1,5 +1,3 @@ - - /// Representations of various inventory data structures in Minecraft. pub mod components; pub mod item;