mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
fix is_trapdoor_useable_as_ladder and add test
This commit is contained in:
parent
27945c8870
commit
74b52a1fc1
2 changed files with 60 additions and 4 deletions
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
/// Representations of various inventory data structures in Minecraft.
|
||||
pub mod components;
|
||||
pub mod item;
|
||||
|
|
Loading…
Add table
Reference in a new issue