1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

why does it think there is air

This commit is contained in:
mat 2022-10-31 23:59:23 -05:00
parent 88e1164daf
commit 53fb15528b
2 changed files with 68 additions and 8 deletions

View file

@ -47,6 +47,7 @@ impl Trait for azalea_client::Client {
println!("start: {:?}, end: {:?}", start, end);
let successors = |node: &Node| {
println!("successors for {:?}", node);
let mut edges = Vec::new();
let possible_moves: Vec<&dyn moves::Move> = vec![
&moves::NorthMove,
@ -56,15 +57,16 @@ impl Trait for azalea_client::Client {
];
let dimension = self.dimension.read();
for possible_move in possible_moves.iter() {
if possible_move.can_execute(&dimension, &node.pos) {
edges.push(Edge {
target: Node {
pos: node.pos + possible_move.offset(),
},
cost: 1.0,
});
}
let can_execute = possible_move.can_execute(&dimension, &node.pos);
edges.push(Edge {
target: Node {
pos: node.pos + possible_move.offset(),
},
cost: if can_execute { 1.0 } else { f32::INFINITY },
});
println!("can execute for {:?}: {}", node, can_execute);
}
println!("edges: {}", edges.len());
edges
};

View file

@ -1,3 +1,4 @@
use azalea_block::Block;
use azalea_core::BlockPos;
use azalea_physics::collision::{self, BlockWithShape};
use azalea_world::Dimension;
@ -5,6 +6,11 @@ use azalea_world::Dimension;
/// whether this block is passable
fn is_passable(pos: &BlockPos, dim: &Dimension) -> bool {
if let Some(block) = dim.get_block_state(pos) {
println!(
"is passable {pos:?} {} = {}",
Box::<dyn Block>::from(block).id(),
block.shape() == &collision::empty_shape()
);
block.shape() == &collision::empty_shape()
} else {
false
@ -14,6 +20,11 @@ fn is_passable(pos: &BlockPos, dim: &Dimension) -> bool {
/// whether this block has a solid hitbox (i.e. we can stand on it)
fn is_solid(pos: &BlockPos, dim: &Dimension) -> bool {
if let Some(block) = dim.get_block_state(pos) {
println!(
"is solid {pos:?} {} = {}",
Box::<dyn Block>::from(block).id(),
block.shape() == &collision::block_shape()
);
block.shape() == &collision::block_shape()
} else {
false
@ -71,3 +82,50 @@ impl Move for WestMove {
BlockPos::new(-1, 0, 0)
}
}
#[cfg(test)]
mod tests {
use super::*;
use azalea_block::BlockState;
use azalea_core::ChunkPos;
use azalea_world::Chunk;
#[test]
fn test_is_passable() {
let mut dim = Dimension::default();
dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()))
.unwrap();
dim.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone);
dim.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air);
assert_eq!(is_passable(&BlockPos::new(0, 0, 0), &dim), false);
assert_eq!(is_passable(&BlockPos::new(0, 1, 0), &dim), true);
}
#[test]
fn test_is_solid() {
let mut dim = Dimension::default();
dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()))
.unwrap();
dim.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone);
dim.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air);
assert_eq!(is_solid(&BlockPos::new(0, 0, 0), &dim), true);
assert_eq!(is_solid(&BlockPos::new(0, 1, 0), &dim), false);
}
#[test]
fn test_is_standable() {
let mut dim = Dimension::default();
dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()))
.unwrap();
dim.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone);
dim.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air);
dim.set_block_state(&BlockPos::new(0, 2, 0), BlockState::Air);
dim.set_block_state(&BlockPos::new(0, 3, 0), BlockState::Air);
assert!(is_standable(&BlockPos::new(0, 1, 0), &dim));
assert!(!is_standable(&BlockPos::new(0, 0, 0), &dim));
assert!(!is_standable(&BlockPos::new(0, 2, 0), &dim));
}
}