aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
Diffstat (limited to 'azalea')
-rw-r--r--azalea/src/pathfinder/mining.rs20
-rw-r--r--azalea/src/pathfinder/world.rs41
2 files changed, 22 insertions, 39 deletions
diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs
index 40cdf8a2..a985ca71 100644
--- a/azalea/src/pathfinder/mining.rs
+++ b/azalea/src/pathfinder/mining.rs
@@ -27,16 +27,16 @@ impl MiningCache {
let mut water_block_state_range_min = BlockStateIntegerRepr::MAX;
let mut water_block_state_range_max = BlockStateIntegerRepr::MIN;
for state in water_block_states {
- water_block_state_range_min = water_block_state_range_min.min(state.id);
- water_block_state_range_max = water_block_state_range_max.max(state.id);
+ water_block_state_range_min = water_block_state_range_min.min(state.id());
+ water_block_state_range_max = water_block_state_range_max.max(state.id());
}
let water_block_state_range = water_block_state_range_min..=water_block_state_range_max;
let mut lava_block_state_range_min = BlockStateIntegerRepr::MAX;
let mut lava_block_state_range_max = BlockStateIntegerRepr::MIN;
for state in lava_block_states {
- lava_block_state_range_min = lava_block_state_range_min.min(state.id);
- lava_block_state_range_max = lava_block_state_range_max.max(state.id);
+ lava_block_state_range_min = lava_block_state_range_min.min(state.id());
+ lava_block_state_range_max = lava_block_state_range_max.max(state.id());
}
let lava_block_state_range = lava_block_state_range_min..=lava_block_state_range_max;
@@ -65,7 +65,7 @@ impl MiningCache {
azalea_registry::Block::RedConcretePowder.into(),
azalea_registry::Block::BlackConcretePowder.into(),
];
- falling_blocks.sort_unstable_by_key(|block| block.id);
+ falling_blocks.sort_unstable_by_key(|block| block.id());
Self {
block_state_id_costs: UnsafeCell::new(IntMap::default()),
@@ -84,7 +84,7 @@ impl MiningCache {
// SAFETY: mining is single-threaded, so this is safe
let block_state_id_costs = unsafe { &mut *self.block_state_id_costs.get() };
- if let Some(cost) = block_state_id_costs.get(&block.id) {
+ if let Some(cost) = block_state_id_costs.get(&block.id()) {
*cost
} else {
let best_tool_result = best_tool_in_hotbar_for_block(block, inventory_menu);
@@ -92,7 +92,7 @@ impl MiningCache {
cost += BLOCK_BREAK_ADDITIONAL_PENALTY;
- block_state_id_costs.insert(block.id, cost);
+ block_state_id_costs.insert(block.id(), cost);
cost
}
}
@@ -101,14 +101,14 @@ impl MiningCache {
// this already runs in about 1 nanosecond, so if you wanna try optimizing it at
// least run the benchmarks (in benches/checks.rs)
- self.water_block_state_range.contains(&block.id)
- || self.lava_block_state_range.contains(&block.id)
+ self.water_block_state_range.contains(&block.id())
+ || self.lava_block_state_range.contains(&block.id())
|| is_waterlogged(block)
}
pub fn is_falling_block(&self, block: BlockState) -> bool {
self.falling_blocks
- .binary_search_by_key(&block.id, |block| block.id)
+ .binary_search_by_key(&block.id(), |block| block.id())
.is_ok()
}
}
diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs
index c50791b8..b89f0761 100644
--- a/azalea/src/pathfinder/world.rs
+++ b/azalea/src/pathfinder/world.rs
@@ -194,8 +194,7 @@ impl CachedWorld {
let mut passable_bitset = FixedBitSet::<{ 4096_usize.div_ceil(8) }>::new();
let mut solid_bitset = FixedBitSet::<{ 4096_usize.div_ceil(8) }>::new();
for i in 0..4096 {
- let block_state_id = section.get_at_index(i);
- let block_state = BlockState::try_from(block_state_id).unwrap_or(BlockState::AIR);
+ let block_state = section.get_at_index(i);
if is_block_state_passable(block_state) {
passable_bitset.set(i);
}
@@ -304,9 +303,7 @@ impl CachedWorld {
let west_is_in_same_section = section_block_pos.x != 0;
let Some(mining_cost) = self.with_section(section_pos, |section| {
- let block_state =
- BlockState::try_from(section.get_at_index(u16::from(section_block_pos) as usize))
- .unwrap_or_default();
+ let block_state = section.get_at_index(u16::from(section_block_pos) as usize);
let mining_cost = mining_cache.cost_for(block_state);
if mining_cost == f32::INFINITY {
@@ -316,10 +313,7 @@ impl CachedWorld {
// if there's a falling block or liquid above this block, abort
if up_is_in_same_section {
- let up_block = BlockState::try_from(
- section.get_at_index(u16::from(section_block_pos.up(1)) as usize),
- )
- .unwrap_or_default();
+ let up_block = section.get_at_index(u16::from(section_block_pos.up(1)) as usize);
if mining_cache.is_liquid(up_block) || mining_cache.is_falling_block(up_block) {
return f32::INFINITY;
}
@@ -327,10 +321,8 @@ impl CachedWorld {
// if there's a liquid to the north of this block, abort
if north_is_in_same_section {
- let north_block = BlockState::try_from(
- section.get_at_index(u16::from(section_block_pos.north(1)) as usize),
- )
- .unwrap_or_default();
+ let north_block =
+ section.get_at_index(u16::from(section_block_pos.north(1)) as usize);
if mining_cache.is_liquid(north_block) {
return f32::INFINITY;
}
@@ -338,10 +330,8 @@ impl CachedWorld {
// liquid to the east
if east_is_in_same_section {
- let east_block = BlockState::try_from(
- section.get_at_index(u16::from(section_block_pos.east(1)) as usize),
- )
- .unwrap_or_default();
+ let east_block =
+ section.get_at_index(u16::from(section_block_pos.east(1)) as usize);
if mining_cache.is_liquid(east_block) {
return f32::INFINITY;
}
@@ -349,10 +339,8 @@ impl CachedWorld {
// liquid to the south
if south_is_in_same_section {
- let south_block = BlockState::try_from(
- section.get_at_index(u16::from(section_block_pos.south(1)) as usize),
- )
- .unwrap_or_default();
+ let south_block =
+ section.get_at_index(u16::from(section_block_pos.south(1)) as usize);
if mining_cache.is_liquid(south_block) {
return f32::INFINITY;
}
@@ -360,10 +348,8 @@ impl CachedWorld {
// liquid to the west
if west_is_in_same_section {
- let west_block = BlockState::try_from(
- section.get_at_index(u16::from(section_block_pos.west(1)) as usize),
- )
- .unwrap_or_default();
+ let west_block =
+ section.get_at_index(u16::from(section_block_pos.west(1)) as usize);
if mining_cache.is_liquid(west_block) {
return f32::INFINITY;
}
@@ -391,10 +377,7 @@ impl CachedWorld {
let check_should_avoid_this_block = |pos: BlockPos, check: &dyn Fn(BlockState) -> bool| {
let block_state = self
.with_section(ChunkSectionPos::from(pos), |section| {
- BlockState::try_from(
- section.get_at_index(u16::from(ChunkSectionBlockPos::from(pos)) as usize),
- )
- .unwrap_or_default()
+ section.get_at_index(u16::from(ChunkSectionBlockPos::from(pos)) as usize)
})
.unwrap_or_default();
check(block_state)