diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-15 14:52:26 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-15 14:52:26 -0600 |
| commit | 0d004b72ac22641978c6ef93ca8641eb621e2f48 (patch) | |
| tree | 61eca3b0bd0339b36b947afd76724b2b6447572c /azalea | |
| parent | b9da6f74756abb8daf7253765fdc5f5521381090 (diff) | |
| download | azalea-drasl-0d004b72ac22641978c6ef93ca8641eb621e2f48.tar.xz | |
Rename "dimension" to "world" (#39)
* rename "dimension" to "world"
* Update mod.rs
Diffstat (limited to 'azalea')
| -rwxr-xr-x | azalea/examples/potatobot/main.rs | 2 | ||||
| -rwxr-xr-x | azalea/examples/pvp.rs | 5 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves.rs | 93 |
4 files changed, 53 insertions, 51 deletions
diff --git a/azalea/examples/potatobot/main.rs b/azalea/examples/potatobot/main.rs index 66ddfcc0..e585c41d 100755 --- a/azalea/examples/potatobot/main.rs +++ b/azalea/examples/potatobot/main.rs @@ -49,7 +49,7 @@ async fn deposit(bot: &mut Client, state: State) -> anyhow::Result<()> { bot.goto(Vec3::new(0, 70, 0)).await?; let chest = bot - .open_container(&bot.dimension.block_at(BlockPos::new(0, 70, 0))) + .open_container(&bot.world.block_at(BlockPos::new(0, 70, 0))) .await .unwrap(); diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs index 435c335c..87d83c6d 100755 --- a/azalea/examples/pvp.rs +++ b/azalea/examples/pvp.rs @@ -36,10 +36,7 @@ async fn swarm_handle(swarm: Swarm, event: Event, state: State) { match event { Event::Tick => { // choose an arbitrary player within render distance to target - if let Some(target) = swarm - .dimension - .find_one_entity(|e| e.id == "minecraft:player") - { + if let Some(target) = swarm.world.find_one_entity(|e| e.id == "minecraft:player") { for bot in swarm { bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box)); // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() { diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 9fd9fe90..6f31512e 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -74,11 +74,11 @@ impl Trait for azalea_client::Client { let successors = |node: &Node| { let mut edges = Vec::new(); - let dimension = self.dimension.read(); + let world = self.world.read(); for possible_move in possible_moves.iter() { edges.push(Edge { target: possible_move.next_node(node), - cost: possible_move.cost(&dimension, node), + cost: possible_move.cost(&world, node), }); } edges diff --git a/azalea/src/pathfinder/moves.rs b/azalea/src/pathfinder/moves.rs index a08d4b80..63e24412 100644 --- a/azalea/src/pathfinder/moves.rs +++ b/azalea/src/pathfinder/moves.rs @@ -1,11 +1,11 @@ use super::{Node, VerticalVel}; use azalea_core::{BlockPos, CardinalDirection}; use azalea_physics::collision::{self, BlockWithShape}; -use azalea_world::Dimension; +use azalea_world::World; /// whether this block is passable -fn is_block_passable(pos: &BlockPos, dim: &Dimension) -> bool { - if let Some(block) = dim.get_block_state(pos) { +fn is_block_passable(pos: &BlockPos, world: &World) -> bool { + if let Some(block) = world.get_block_state(pos) { block.shape() == &collision::empty_shape() } else { false @@ -13,8 +13,8 @@ fn is_block_passable(pos: &BlockPos, dim: &Dimension) -> bool { } /// whether this block has a solid hitbox (i.e. we can stand on it) -fn is_block_solid(pos: &BlockPos, dim: &Dimension) -> bool { - if let Some(block) = dim.get_block_state(pos) { +fn is_block_solid(pos: &BlockPos, world: &World) -> bool { + if let Some(block) = world.get_block_state(pos) { block.shape() == &collision::block_shape() } else { false @@ -22,21 +22,22 @@ fn is_block_solid(pos: &BlockPos, dim: &Dimension) -> bool { } /// Whether this block and the block above are passable -fn is_passable(pos: &BlockPos, dim: &Dimension) -> bool { - is_block_passable(pos, dim) && is_block_passable(&pos.up(1), dim) +fn is_passable(pos: &BlockPos, world: &World) -> bool { + is_block_passable(pos, world) && is_block_passable(&pos.up(1), world) } /// Whether we can stand in this position. Checks if the block below is solid, /// and that the two blocks above that are passable. -fn is_standable(pos: &BlockPos, dim: &Dimension) -> bool { - is_block_solid(&pos.down(1), dim) && is_passable(pos, dim) + +fn is_standable(pos: &BlockPos, world: &World) -> bool { + is_block_solid(&pos.down(1), world) && is_passable(pos, world) } const JUMP_COST: f32 = 0.5; const WALK_ONE_BLOCK_COST: f32 = 1.0; pub trait Move { - fn cost(&self, dim: &Dimension, node: &Node) -> f32; + fn cost(&self, world: &World, node: &Node) -> f32; /// Returns by how much the entity's position should be changed when this move is executed. fn offset(&self) -> BlockPos; fn next_node(&self, node: &Node) -> Node { @@ -49,8 +50,9 @@ pub trait Move { pub struct ForwardMove(pub CardinalDirection); impl Move for ForwardMove { - fn cost(&self, dim: &Dimension, node: &Node) -> f32 { - if is_standable(&(node.pos + self.offset()), dim) && node.vertical_vel == VerticalVel::None + fn cost(&self, world: &World, node: &Node) -> f32 { + if is_standable(&(node.pos + self.offset()), world) + && node.vertical_vel == VerticalVel::None { WALK_ONE_BLOCK_COST } else { @@ -64,10 +66,10 @@ impl Move for ForwardMove { pub struct AscendMove(pub CardinalDirection); impl Move for AscendMove { - fn cost(&self, dim: &Dimension, node: &Node) -> f32 { + fn cost(&self, world: &World, node: &Node) -> f32 { if node.vertical_vel == VerticalVel::None - && is_block_passable(&node.pos.up(2), dim) - && is_standable(&(node.pos + self.offset()), dim) + && is_block_passable(&node.pos.up(2), world) + && is_standable(&(node.pos + self.offset()), world) { WALK_ONE_BLOCK_COST + JUMP_COST } else { @@ -86,11 +88,11 @@ impl Move for AscendMove { } pub struct DescendMove(pub CardinalDirection); impl Move for DescendMove { - fn cost(&self, dim: &Dimension, node: &Node) -> f32 { + fn cost(&self, world: &World, node: &Node) -> f32 { // check whether 3 blocks vertically forward are passable if node.vertical_vel == VerticalVel::None - && is_standable(&(node.pos + self.offset()), dim) - && is_block_passable(&(node.pos + self.offset().up(2)), dim) + && is_standable(&(node.pos + self.offset()), world) + && is_block_passable(&(node.pos + self.offset().up(2)), world) { WALK_ONE_BLOCK_COST } else { @@ -109,24 +111,24 @@ impl Move for DescendMove { } pub struct DiagonalMove(pub CardinalDirection); impl Move for DiagonalMove { - fn cost(&self, dim: &Dimension, node: &Node) -> f32 { + fn cost(&self, world: &World, node: &Node) -> f32 { if node.vertical_vel != VerticalVel::None { return f32::INFINITY; } if !is_passable( &BlockPos::new(node.pos.x + self.0.x(), node.pos.y, node.pos.z + self.0.z()), - dim, + world, ) && !is_passable( &BlockPos::new( node.pos.x + self.0.right().x(), node.pos.y, node.pos.z + self.0.right().z(), ), - dim, + world, ) { return f32::INFINITY; } - if !is_standable(&(node.pos + self.offset()), dim) { + if !is_standable(&(node.pos + self.offset()), world) { return f32::INFINITY; } WALK_ONE_BLOCK_COST * 1.4 @@ -152,40 +154,43 @@ mod tests { #[test] fn test_is_passable() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .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); + world.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone); + world.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air); - assert_eq!(is_block_passable(&BlockPos::new(0, 0, 0), &dim), false); - assert_eq!(is_block_passable(&BlockPos::new(0, 1, 0), &dim), true); + assert_eq!(is_block_passable(&BlockPos::new(0, 0, 0), &world), false); + assert_eq!(is_block_passable(&BlockPos::new(0, 1, 0), &world), true); } #[test] fn test_is_solid() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .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); + world.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone); + world.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air); - assert_eq!(is_block_solid(&BlockPos::new(0, 0, 0), &dim), true); - assert_eq!(is_block_solid(&BlockPos::new(0, 1, 0), &dim), false); + assert_eq!(is_block_solid(&BlockPos::new(0, 0, 0), &world), true); + assert_eq!(is_block_solid(&BlockPos::new(0, 1, 0), &world), false); } #[test] fn test_is_standable() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .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)); + world.set_block_state(&BlockPos::new(0, 0, 0), BlockState::Stone); + world.set_block_state(&BlockPos::new(0, 1, 0), BlockState::Air); + world.set_block_state(&BlockPos::new(0, 2, 0), BlockState::Air); + world.set_block_state(&BlockPos::new(0, 3, 0), BlockState::Air); + + assert!(is_standable(&BlockPos::new(0, 1, 0), &world)); + assert!(!is_standable(&BlockPos::new(0, 0, 0), &world)); + assert!(!is_standable(&BlockPos::new(0, 2, 0), &world)); } } |
