Skip to content

Commit

Permalink
fix is_trapdoor_useable_as_ladder and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Feb 22, 2025
1 parent 27945c8 commit 74b52a1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
62 changes: 60 additions & 2 deletions azalea-entity/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<azalea_block::properties::Facing>()
.property::<azalea_block::properties::FacingCardinal>()
.expect("ladder block must have facing property");
let trapdoor_facing = block_state
.property::<azalea_block::properties::Facing>()
.property::<azalea_block::properties::FacingCardinal>()
.expect("trapdoor block must have facing property");
if ladder_facing != trapdoor_facing {
return false;
Expand Down Expand Up @@ -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);
}
}
2 changes: 0 additions & 2 deletions azalea-inventory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/// Representations of various inventory data structures in Minecraft.
pub mod components;
pub mod item;
Expand Down

0 comments on commit 74b52a1

Please sign in to comment.