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

take BlockPos instead of &BlockPos in all function arguments

This commit is contained in:
mat 2025-06-11 16:55:33 +11:00
parent 2a6ac0764f
commit 9b0bd29db4
24 changed files with 106 additions and 98 deletions

View file

@ -343,7 +343,7 @@ pub fn pick_block(
/// adventure mode check.
pub fn check_is_interaction_restricted(
instance: &Instance,
block_pos: &BlockPos,
block_pos: BlockPos,
game_mode: &GameMode,
inventory: &Inventory,
) -> bool {

View file

@ -246,7 +246,7 @@ fn handle_mining_queued(
let instance = instance_holder.instance.read();
if check_is_interaction_restricted(
&instance,
&mining_queued.position,
mining_queued.position,
&game_mode.current,
inventory,
) {
@ -286,7 +286,7 @@ fn handle_mining_queued(
}
let target_block_state = instance
.get_block_state(&mining_queued.position)
.get_block_state(mining_queued.position)
.unwrap_or_default();
// we can't break blocks if they don't have a bounding box
@ -450,7 +450,7 @@ pub fn handle_finish_mining_block_observer(
query.get_mut(trigger.target()).unwrap();
let instance_lock = instances.get(instance_name).unwrap();
let instance = instance_lock.read();
if check_is_interaction_restricted(&instance, &event.position, &game_mode.current, inventory) {
if check_is_interaction_restricted(&instance, event.position, &game_mode.current, inventory) {
return;
}
@ -465,7 +465,7 @@ pub fn handle_finish_mining_block_observer(
}
}
let Some(block_state) = instance.get_block_state(&event.position) else {
let Some(block_state) = instance.get_block_state(event.position) else {
return;
};
@ -485,7 +485,7 @@ pub fn handle_finish_mining_block_observer(
// when we break a waterlogged block we want to keep the water there
let fluid_state = FluidState::from(block_state);
let block_state_for_fluid = BlockState::from(fluid_state);
instance.set_block_state(&event.position, block_state_for_fluid);
instance.set_block_state(event.position, block_state_for_fluid);
}
/// Abort mining a block.
@ -595,7 +595,7 @@ pub fn continue_mining_block(
trace!("continue mining block at {:?}", mining.pos);
let instance_lock = instances.get(instance_name).unwrap();
let instance = instance_lock.read();
let target_block_state = instance.get_block_state(&mining.pos).unwrap_or_default();
let target_block_state = instance.get_block_state(mining.pos).unwrap_or_default();
trace!("target_block_state: {target_block_state:?}");

View file

@ -1066,7 +1066,7 @@ impl GamePacketHandler<'_> {
let world = local_player.instance.write();
world.chunks.set_block_state(&p.pos, p.block_state);
world.chunks.set_block_state(p.pos, p.block_state);
});
}
@ -1083,7 +1083,7 @@ impl GamePacketHandler<'_> {
for state in &p.states {
world
.chunks
.set_block_state(&(p.section_pos + state.pos), state.state);
.set_block_state(p.section_pos + state.pos, state.state);
}
});
}

View file

@ -211,7 +211,7 @@ impl AABB {
boxes: &Vec<AABB>,
from: &Vec3,
to: &Vec3,
pos: &BlockPos,
pos: BlockPos,
) -> Option<BlockHitResult> {
let mut t = 1.0;
let mut dir = None;
@ -230,7 +230,7 @@ impl AABB {
Some(BlockHitResult {
location: from + &(delta * t),
direction: dir,
block_pos: *pos,
block_pos: pos,
inside: false,
miss: false,
world_border: false,
@ -500,7 +500,7 @@ mod tests {
}],
&Vec3::new(-1., -1., -1.),
&Vec3::new(1., 1., 1.),
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
),
None
);

View file

@ -589,6 +589,12 @@ impl From<&ChunkBiomePos> for ChunkSectionBiomePos {
}
}
}
impl From<ChunkBiomePos> for ChunkSectionBiomePos {
#[inline]
fn from(pos: ChunkBiomePos) -> Self {
Self::from(&pos)
}
}
vec3_impl!(ChunkSectionBiomePos, u8);
/// The coordinates of a biome inside a chunk. Biomes are 4x4 blocks.
@ -604,6 +610,12 @@ impl From<&BlockPos> for ChunkBiomePos {
ChunkBiomePos::from(&ChunkBlockPos::from(pos))
}
}
impl From<BlockPos> for ChunkBiomePos {
#[inline]
fn from(pos: BlockPos) -> Self {
ChunkBiomePos::from(&ChunkBlockPos::from(pos))
}
}
impl From<&ChunkBlockPos> for ChunkBiomePos {
#[inline]
fn from(pos: &ChunkBlockPos) -> Self {

View file

@ -106,10 +106,10 @@ pub fn on_pos(offset: f32, chunk_storage: &ChunkStorage, pos: &Position) -> Bloc
// TODO: check if block below is a fence, wall, or fence gate
let block_pos = pos.down(1);
let block_state = chunk_storage.get_block_state(&block_pos);
let block_state = chunk_storage.get_block_state(block_pos);
if block_state == Some(BlockState::AIR) {
let block_pos_below = block_pos.down(1);
let block_state_below = chunk_storage.get_block_state(&block_pos_below);
let block_state_below = chunk_storage.get_block_state(block_pos_below);
if let Some(_block_state_below) = block_state_below {
// if block_state_below.is_fence()
// || block_state_below.is_wall()

View file

@ -103,7 +103,7 @@ pub fn update_fluid_on_eyes(
let eye_block_pos = BlockPos::from(Vec3::new(position.x, adjusted_eye_y, position.z));
let fluid_at_eye = instance
.read()
.get_fluid_state(&eye_block_pos)
.get_fluid_state(eye_block_pos)
.unwrap_or_default();
let fluid_cutoff_y = (eye_block_pos.y as f32 + fluid_at_eye.height()) as f64;
if fluid_cutoff_y > adjusted_eye_y {
@ -134,7 +134,7 @@ pub fn update_on_climbable(
let instance = instance.read();
let block_pos = BlockPos::from(position);
let block_state_at_feet = instance.get_block_state(&block_pos).unwrap_or_default();
let block_state_at_feet = instance.get_block_state(block_pos).unwrap_or_default();
let block_at_feet = Box::<dyn azalea_block::BlockTrait>::from(block_state_at_feet);
let registry_block_at_feet = block_at_feet.as_registry_block();
@ -159,7 +159,7 @@ fn is_trapdoor_useable_as_ladder(
// block below must be a ladder
let block_below = instance
.get_block_state(&block_pos.down(1))
.get_block_state(block_pos.down(1))
.unwrap_or_default();
let registry_block_below =
Box::<dyn azalea_block::BlockTrait>::from(block_below).as_registry_block();
@ -255,7 +255,7 @@ mod tests {
&mut chunks,
);
partial_instance.chunks.set_block_state(
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
azalea_registry::Block::Stone.into(),
&chunks,
);
@ -266,7 +266,7 @@ mod tests {
};
partial_instance
.chunks
.set_block_state(&BlockPos::new(0, 0, 0), ladder.into(), &chunks);
.set_block_state(BlockPos::new(0, 0, 0), ladder.into(), &chunks);
let trapdoor = OakTrapdoor {
facing: FacingCardinal::East,
@ -277,12 +277,12 @@ mod tests {
};
partial_instance
.chunks
.set_block_state(&BlockPos::new(0, 1, 0), trapdoor.into(), &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))
.get_block_state(BlockPos::new(0, 1, 0))
.unwrap_or_default(),
BlockPos::new(0, 1, 0),
&instance,

View file

@ -49,7 +49,7 @@ impl ClipContext {
&self,
fluid_state: FluidState,
world: &ChunkStorage,
pos: &BlockPos,
pos: BlockPos,
) -> &VoxelShape {
if self.fluid_pick_type.can_pick(&fluid_state) {
crate::collision::fluid_shape(&fluid_state, world, pos)
@ -139,7 +139,7 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
fn clip_with_interaction_override(
from: &Vec3,
to: &Vec3,
block_pos: &BlockPos,
block_pos: BlockPos,
block_shape: &VoxelShape,
_block_state: &BlockState,
) -> Option<BlockHitResult> {
@ -168,7 +168,7 @@ pub fn traverse_blocks<C, T>(
from: Vec3,
to: Vec3,
context: C,
get_hit_result: impl Fn(&C, &BlockPos) -> Option<T>,
get_hit_result: impl Fn(&C, BlockPos) -> Option<T>,
get_miss_result: impl Fn(&C) -> T,
) -> T {
if from == to {
@ -188,7 +188,7 @@ pub fn traverse_blocks<C, T>(
};
let mut current_block = BlockPos::from(right_before_start);
if let Some(data) = get_hit_result(&context, &current_block) {
if let Some(data) = get_hit_result(&context, current_block) {
return data;
}
@ -249,7 +249,7 @@ pub fn traverse_blocks<C, T>(
percentage.z += percentage_step.z;
}
if let Some(data) = get_hit_result(&context, &current_block) {
if let Some(data) = get_hit_result(&context, current_block) {
return data;
}
}

View file

@ -322,13 +322,9 @@ fn collide_with_shapes(
///
/// The instance and position are required so it can check if the block above is
/// also the same fluid type.
pub fn fluid_shape(
fluid: &FluidState,
world: &ChunkStorage,
pos: &BlockPos,
) -> &'static VoxelShape {
pub fn fluid_shape(fluid: &FluidState, world: &ChunkStorage, pos: BlockPos) -> &'static VoxelShape {
if fluid.amount == 9 {
let fluid_state_above = world.get_fluid_state(&pos.up(1)).unwrap_or_default();
let fluid_state_above = world.get_fluid_state(pos.up(1)).unwrap_or_default();
if fluid_state_above.kind == fluid.kind {
return &BLOCK_SHAPE;
}

View file

@ -408,7 +408,7 @@ impl VoxelShape {
}
}
pub fn clip(&self, from: &Vec3, to: &Vec3, block_pos: &BlockPos) -> Option<BlockHitResult> {
pub fn clip(&self, from: &Vec3, to: &Vec3, block_pos: BlockPos) -> Option<BlockHitResult> {
if self.is_empty() {
return None;
}
@ -424,7 +424,7 @@ impl VoxelShape {
self.find_index(Axis::Z, right_after_start.z - block_pos.z as f64),
) {
Some(BlockHitResult {
block_pos: *block_pos,
block_pos,
direction: Direction::nearest(vector).opposite(),
location: right_after_start,
inside: true,
@ -755,7 +755,7 @@ mod tests {
.clip(
&Vec3::new(-0.3, 0.5, 0.),
&Vec3::new(5.3, 0.5, 0.),
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
)
.unwrap();

View file

@ -116,7 +116,7 @@ fn update_fluid_height_and_do_fluid_pushing(
for cur_y in min_y..max_y {
for cur_z in min_z..max_z {
let cur_pos = BlockPos::new(cur_x, cur_y, cur_z);
let Some(fluid_at_cur_pos) = world.get_fluid_state(&cur_pos) else {
let Some(fluid_at_cur_pos) = world.get_fluid_state(cur_pos) else {
continue;
};
if fluid_at_cur_pos.kind != checking_fluid {
@ -192,7 +192,7 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
let adjacent_block_pos = pos.offset_with_direction(direction);
let adjacent_block_state = world
.get_block_state(&adjacent_block_pos)
.get_block_state(adjacent_block_pos)
.unwrap_or_default();
let adjacent_fluid_state = FluidState::from(adjacent_block_state);
@ -206,7 +206,7 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
if !legacy_blocks_motion(adjacent_block_state) {
let block_pos_below_adjacent = adjacent_block_pos.down(1);
let fluid_below_adjacent = world
.get_fluid_state(&block_pos_below_adjacent)
.get_fluid_state(block_pos_below_adjacent)
.unwrap_or_default();
if fluid.affects_flow(&fluid_below_adjacent) {
@ -250,8 +250,8 @@ fn is_solid_face(
adjacent_pos: BlockPos,
direction: Direction,
) -> bool {
let block_state = world.get_block_state(&adjacent_pos).unwrap_or_default();
let fluid_state = world.get_fluid_state(&adjacent_pos).unwrap_or_default();
let block_state = world.get_block_state(adjacent_pos).unwrap_or_default();
let fluid_state = world.get_fluid_state(adjacent_pos).unwrap_or_default();
if fluid_state.is_same_kind(fluid) {
return false;
}

View file

@ -8,7 +8,7 @@ pub mod travel;
use std::collections::HashSet;
use azalea_block::{BlockTrait, BlockState, fluid_state::FluidState, properties};
use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState, properties};
use azalea_core::{
math,
position::{BlockPos, Vec3},
@ -197,7 +197,7 @@ fn check_inside_blocks(
// return;
// }
let traversed_block_state = world.get_block_state(&traversed_block).unwrap_or_default();
let traversed_block_state = world.get_block_state(traversed_block).unwrap_or_default();
if traversed_block_state.is_air() {
continue;
}
@ -268,7 +268,7 @@ fn handle_entity_inside_block(
#[allow(clippy::single_match)]
match registry_block {
azalea_registry::Block::BubbleColumn => {
let block_above = world.get_block_state(&block_pos.up(1)).unwrap_or_default();
let block_above = world.get_block_state(block_pos.up(1)).unwrap_or_default();
let is_block_above_empty =
block_above.is_collision_shape_empty() && FluidState::from(block_above).is_empty();
let drag_down = block
@ -417,7 +417,7 @@ fn handle_relative_friction_and_calculate_movement(
if physics.horizontal_collision || **jumping {
let block_at_feet: azalea_registry::Block = world
.chunks
.get_block_state(&(*position).into())
.get_block_state((*position).into())
.unwrap_or_default()
.into();
@ -454,7 +454,7 @@ fn handle_on_climbable(
&& azalea_registry::Block::from(
world
.chunks
.get_block_state(&position.into())
.get_block_state(position.into())
.unwrap_or_default(),
) != azalea_registry::Block::Scaffolding
{
@ -486,10 +486,10 @@ fn get_friction_influenced_speed(
/// Returns the what the entity's jump should be multiplied by based on the
/// block they're standing on.
fn block_jump_factor(world: &Instance, position: &Position) -> f32 {
let block_at_pos = world.chunks.get_block_state(&position.into());
let block_at_pos = world.chunks.get_block_state(position.into());
let block_below = world
.chunks
.get_block_state(&get_block_pos_below_that_affects_movement(position));
.get_block_state(get_block_pos_below_that_affects_movement(position));
let block_at_pos_jump_factor = if let Some(block) = block_at_pos {
Box::<dyn BlockTrait>::from(block).behavior().jump_factor

View file

@ -1,4 +1,4 @@
use azalea_block::{BlockTrait, BlockState, fluid_state::FluidState};
use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState};
use azalea_core::{
aabb::AABB,
position::{BlockPos, Vec3},
@ -122,7 +122,7 @@ fn travel_in_air(
let block_state_below = world
.chunks
.get_block_state(&block_pos_below)
.get_block_state(block_pos_below)
.unwrap_or(BlockState::AIR);
let block_below: Box<dyn BlockTrait> = block_state_below.into();
let block_friction = block_below.behavior().friction;
@ -392,7 +392,7 @@ fn contains_any_liquid(world: &Instance, bounding_box: AABB) -> bool {
for z in min.z..max.z {
let block_state = world
.chunks
.get_block_state(&BlockPos::new(x, y, z))
.get_block_state(BlockPos::new(x, y, z))
.unwrap_or_default();
if !FluidState::from(block_state).is_empty() {
return true;

View file

@ -121,7 +121,7 @@ fn test_collision() {
))
.id();
let block_state = partial_world.chunks.set_block_state(
&BlockPos { x: 0, y: 69, z: 0 },
BlockPos { x: 0, y: 69, z: 0 },
azalea_registry::Block::Stone.into(),
&world_lock.write().chunks,
);
@ -177,7 +177,7 @@ fn test_slab_collision() {
))
.id();
let block_state = partial_world.chunks.set_block_state(
&BlockPos { x: 0, y: 69, z: 0 },
BlockPos { x: 0, y: 69, z: 0 },
azalea_block::blocks::StoneSlab {
kind: azalea_block::properties::Type::Bottom,
waterlogged: false,
@ -227,7 +227,7 @@ fn test_top_slab_collision() {
))
.id();
let block_state = world_lock.write().chunks.set_block_state(
&BlockPos { x: 0, y: 69, z: 0 },
BlockPos { x: 0, y: 69, z: 0 },
azalea_block::blocks::StoneSlab {
kind: azalea_block::properties::Type::Top,
waterlogged: false,
@ -284,7 +284,7 @@ fn test_weird_wall_collision() {
))
.id();
let block_state = world_lock.write().chunks.set_block_state(
&BlockPos { x: 0, y: 69, z: 0 },
BlockPos { x: 0, y: 69, z: 0 },
azalea_block::blocks::CobblestoneWall {
east: azalea_block::properties::WallEast::Low,
north: azalea_block::properties::WallNorth::Low,
@ -346,7 +346,7 @@ fn test_negative_coordinates_weird_wall_collision() {
))
.id();
let block_state = world_lock.write().chunks.set_block_state(
&BlockPos {
BlockPos {
x: -8,
y: 69,
z: -8,
@ -440,7 +440,7 @@ fn test_afk_pool() {
world_lock
.write()
.chunks
.set_block_state(&BlockPos { x, y, z }, b);
.set_block_state(BlockPos { x, y, z }, b);
};
let stone = azalea_block::blocks::Stone {}.into();

View file

@ -155,7 +155,7 @@ impl PartialChunkStorage {
pub fn set_block_state(
&self,
pos: &BlockPos,
pos: BlockPos,
state: BlockState,
chunk_storage: &ChunkStorage,
) -> Option<BlockState> {
@ -293,26 +293,26 @@ impl ChunkStorage {
self.map.get(pos).and_then(|chunk| chunk.upgrade())
}
pub fn get_block_state(&self, pos: &BlockPos) -> Option<BlockState> {
pub fn get_block_state(&self, pos: BlockPos) -> Option<BlockState> {
let chunk_pos = ChunkPos::from(pos);
let chunk = self.get(&chunk_pos)?;
let chunk = chunk.read();
chunk.get_block_state(&ChunkBlockPos::from(pos), self.min_y)
}
pub fn get_fluid_state(&self, pos: &BlockPos) -> Option<FluidState> {
pub fn get_fluid_state(&self, pos: BlockPos) -> Option<FluidState> {
let block_state = self.get_block_state(pos)?;
Some(FluidState::from(block_state))
}
pub fn get_biome(&self, pos: &BlockPos) -> Option<Biome> {
pub fn get_biome(&self, pos: BlockPos) -> Option<Biome> {
let chunk_pos = ChunkPos::from(pos);
let chunk = self.get(&chunk_pos)?;
let chunk = chunk.read();
chunk.get_biome(&ChunkBiomePos::from(pos), self.min_y)
chunk.get_biome(ChunkBiomePos::from(pos), self.min_y)
}
pub fn set_block_state(&self, pos: &BlockPos, state: BlockState) -> Option<BlockState> {
pub fn set_block_state(&self, pos: BlockPos, state: BlockState) -> Option<BlockState> {
if pos.y < self.min_y || pos.y >= (self.min_y + self.height as i32) {
return None;
}
@ -404,7 +404,7 @@ impl Chunk {
}
}
pub fn get_biome(&self, pos: &ChunkBiomePos, min_y: i32) -> Option<Biome> {
pub fn get_biome(&self, pos: ChunkBiomePos, min_y: i32) -> Option<Biome> {
if pos.y < min_y {
// y position is out of bounds
return None;
@ -580,27 +580,27 @@ mod tests {
);
assert!(
chunk_storage
.get_block_state(&BlockPos { x: 0, y: 319, z: 0 })
.get_block_state(BlockPos { x: 0, y: 319, z: 0 })
.is_some()
);
assert!(
chunk_storage
.get_block_state(&BlockPos { x: 0, y: 320, z: 0 })
.get_block_state(BlockPos { x: 0, y: 320, z: 0 })
.is_none()
);
assert!(
chunk_storage
.get_block_state(&BlockPos { x: 0, y: 338, z: 0 })
.get_block_state(BlockPos { x: 0, y: 338, z: 0 })
.is_none()
);
assert!(
chunk_storage
.get_block_state(&BlockPos { x: 0, y: -64, z: 0 })
.get_block_state(BlockPos { x: 0, y: -64, z: 0 })
.is_some()
);
assert!(
chunk_storage
.get_block_state(&BlockPos { x: 0, y: -65, z: 0 })
.get_block_state(BlockPos { x: 0, y: -65, z: 0 })
.is_none()
);
}

View file

@ -7,7 +7,7 @@ impl Instance {
/// Find the coordinates of a block in the world.
///
/// Note that this is sorted by `x+y+z` and not `x^2+y^2+z^2` for
/// optimization purposes.
/// performance purposes.
///
/// ```
/// # fn example(client: &azalea_client::Client) {
@ -93,7 +93,7 @@ impl Instance {
/// are in the given block states.
///
/// Note that this is sorted by `x+y+z` and not `x^2+y^2+z^2` for
/// optimization purposes.
/// performance purposes.
pub fn find_blocks<'a>(
&'a self,
nearest_to: impl Into<BlockPos>,
@ -274,8 +274,8 @@ mod tests {
chunk_storage,
);
chunk_storage.set_block_state(&BlockPos { x: 17, y: 0, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(&BlockPos { x: 0, y: 18, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(BlockPos { x: 17, y: 0, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(BlockPos { x: 0, y: 18, z: 0 }, Block::Stone.into());
let pos = instance.find_block(BlockPos { x: 0, y: 0, z: 0 }, &Block::Stone.into());
assert_eq!(pos, Some(BlockPos { x: 17, y: 0, z: 0 }));
@ -301,8 +301,8 @@ mod tests {
chunk_storage,
);
chunk_storage.set_block_state(&BlockPos { x: -1, y: 0, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(&BlockPos { x: 15, y: 0, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(BlockPos { x: -1, y: 0, z: 0 }, Block::Stone.into());
chunk_storage.set_block_state(BlockPos { x: 15, y: 0, z: 0 }, Block::Stone.into());
let pos = instance.find_block(BlockPos { x: 0, y: 0, z: 0 }, &Block::Stone.into());
assert_eq!(pos, Some(BlockPos { x: -1, y: 0, z: 0 }));

View file

@ -171,11 +171,11 @@ pub struct Instance {
}
impl Instance {
pub fn get_block_state(&self, pos: &BlockPos) -> Option<BlockState> {
pub fn get_block_state(&self, pos: BlockPos) -> Option<BlockState> {
self.chunks.get_block_state(pos)
}
pub fn get_fluid_state(&self, pos: &BlockPos) -> Option<FluidState> {
pub fn get_fluid_state(&self, pos: BlockPos) -> Option<FluidState> {
self.chunks.get_block_state(pos).map(FluidState::from)
}
@ -187,11 +187,11 @@ impl Instance {
/// Note that biomes are internally stored as 4x4x4 blocks, so if you're
/// writing code that searches for a specific biome it'll probably be more
/// efficient to avoid scanning every single block.
pub fn get_biome(&self, pos: &BlockPos) -> Option<Biome> {
pub fn get_biome(&self, pos: BlockPos) -> Option<Biome> {
self.chunks.get_biome(pos)
}
pub fn set_block_state(&self, pos: &BlockPos, state: BlockState) -> Option<BlockState> {
pub fn set_block_state(&self, pos: BlockPos, state: BlockState) -> Option<BlockState> {
self.chunks.set_block_state(pos, state)
}
}

View file

@ -110,7 +110,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
};
let block_pos = hit_result.block_pos;
let block = source.bot.world().read().get_block_state(&block_pos);
let block = source.bot.world().read().get_block_state(block_pos);
source.reply(&format!("I'm looking at {block:?} at {block_pos:?}"));
@ -125,7 +125,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let z = get_integer(ctx, "z").unwrap();
println!("getblock xyz {x} {y} {z}");
let block_pos = BlockPos::new(x, y, z);
let block = source.bot.world().read().get_block_state(&block_pos);
let block = source.bot.world().read().get_block_state(block_pos);
source.reply(&format!("Block at {block_pos} is {block:?}"));
1
})),
@ -138,7 +138,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let z = get_integer(ctx, "z").unwrap();
println!("getfluid xyz {x} {y} {z}");
let block_pos = BlockPos::new(x, y, z);
let block = source.bot.world().read().get_fluid_state(&block_pos);
let block = source.bot.world().read().get_fluid_state(block_pos);
source.reply(&format!("Fluid at {block_pos} is {block:?}"));
1
})),

View file

@ -31,7 +31,7 @@ impl AutoToolClientExt for Client {
let block_state = self
.world()
.read()
.get_block_state(&block_pos)
.get_block_state(block_pos)
.unwrap_or_default();
let best_tool_result = self.best_tool_in_hotbar_for_block(block_state);
self.set_selected_hotbar_slot(best_tool_result.index as u8);

View file

@ -84,7 +84,7 @@ impl ContainerClientExt for Client {
if !self
.world()
.read()
.get_block_state(&pos)
.get_block_state(pos)
.unwrap_or_default()
.is_collision_shape_empty()
{

View file

@ -67,9 +67,9 @@ pub fn debug_render_path_with_particles(
let step_count = (start_vec3.distance_squared_to(&end_vec3).sqrt() * 4.0) as usize;
let target_block_state = chunks.get_block_state(&movement.target).unwrap_or_default();
let target_block_state = chunks.get_block_state(movement.target).unwrap_or_default();
let above_target_block_state = chunks
.get_block_state(&movement.target.up(1))
.get_block_state(movement.target.up(1))
.unwrap_or_default();
// this isn't foolproof, there might be another block that could be mined
// depending on the move, but it's good enough for debugging

View file

@ -1334,10 +1334,10 @@ mod tests {
partial_chunks.set(&chunk_pos, Some(Chunk::default()), &mut chunks);
}
for block_pos in solid_blocks {
chunks.set_block_state(block_pos, azalea_registry::Block::Stone.into());
chunks.set_block_state(*block_pos, azalea_registry::Block::Stone.into());
}
for (block_pos, block_state) in extra_blocks {
chunks.set_block_state(block_pos, *block_state);
chunks.set_block_state(*block_pos, *block_state);
}
let player = SimulatedPlayerBundle::new(Vec3::new(

View file

@ -122,7 +122,7 @@ impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_> {
let block_state = self
.instance
.read()
.get_block_state(&block)
.get_block_state(block)
.unwrap_or_default();
if is_block_state_passable(block_state) {
// block is already passable, no need to mine it
@ -138,7 +138,7 @@ impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_> {
let block_state = self
.instance
.read()
.get_block_state(&block)
.get_block_state(block)
.unwrap_or_default();
if is_block_state_passable(block_state) {
// block is already passable, no need to mine it
@ -191,7 +191,7 @@ impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_> {
pub fn get_block_state(&self, block: BlockPos) -> BlockState {
self.instance
.read()
.get_block_state(&block)
.get_block_state(block)
.unwrap_or_default()
}
}

View file

@ -625,13 +625,13 @@ mod tests {
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
partial_world.chunks.set_block_state(
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
azalea_registry::Block::Stone.into(),
&world,
);
partial_world
.chunks
.set_block_state(&BlockPos::new(0, 1, 0), BlockState::AIR, &world);
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);
let ctx = CachedWorld::new(Arc::new(RwLock::new(world.into())), BlockPos::default());
assert!(!ctx.is_block_pos_passable(BlockPos::new(0, 0, 0)));
@ -646,13 +646,13 @@ mod tests {
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
partial_world.chunks.set_block_state(
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
azalea_registry::Block::Stone.into(),
&world,
);
partial_world
.chunks
.set_block_state(&BlockPos::new(0, 1, 0), BlockState::AIR, &world);
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);
let ctx = CachedWorld::new(Arc::new(RwLock::new(world.into())), BlockPos::default());
assert!(ctx.is_block_pos_solid(BlockPos::new(0, 0, 0)));
@ -667,19 +667,19 @@ mod tests {
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
partial_world.chunks.set_block_state(
&BlockPos::new(0, 0, 0),
BlockPos::new(0, 0, 0),
azalea_registry::Block::Stone.into(),
&world,
);
partial_world
.chunks
.set_block_state(&BlockPos::new(0, 1, 0), BlockState::AIR, &world);
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);
partial_world
.chunks
.set_block_state(&BlockPos::new(0, 2, 0), BlockState::AIR, &world);
.set_block_state(BlockPos::new(0, 2, 0), BlockState::AIR, &world);
partial_world
.chunks
.set_block_state(&BlockPos::new(0, 3, 0), BlockState::AIR, &world);
.set_block_state(BlockPos::new(0, 3, 0), BlockState::AIR, &world);
let ctx = CachedWorld::new(Arc::new(RwLock::new(world.into())), BlockPos::default());
assert!(ctx.is_standable_at_block_pos(BlockPos::new(0, 1, 0)));