aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-12-28 02:10:05 +0000
committermat <git@matdoes.dev>2024-12-28 02:10:05 +0000
commit615d8f9d2ac56b3244d328587243301da253eafd (patch)
tree3cf08428ddeb29bcb58dbce04fee7bbbe4d2814d
parentebaf5128fbc87970b2ba1f6157e5da035ae379c8 (diff)
downloadazalea-drasl-615d8f9d2ac56b3244d328587243301da253eafd.tar.xz
bump minimum rust version and improve pathfinder docs
-rw-r--r--azalea-core/src/color.rs4
-rwxr-xr-xazalea-protocol/src/packets/game/c_section_blocks_update.rs8
-rwxr-xr-xazalea-world/src/bit_storage.rs8
-rw-r--r--azalea/examples/testbot/main.rs5
-rw-r--r--azalea/src/pathfinder/astar.rs31
-rw-r--r--azalea/src/pathfinder/mod.rs13
-rw-r--r--azalea/src/pathfinder/world.rs5
7 files changed, 46 insertions, 28 deletions
diff --git a/azalea-core/src/color.rs b/azalea-core/src/color.rs
index eddf5035..ff727ccd 100644
--- a/azalea-core/src/color.rs
+++ b/azalea-core/src/color.rs
@@ -8,7 +8,7 @@ pub struct RgbColor {
impl RgbColor {
pub fn new(r: u8, g: u8, b: u8) -> Self {
Self {
- value: (r as u32) << 16 | (g as u32) << 8 | b as u32,
+ value: ((r as u32) << 16) | ((g as u32) << 8) | (b as u32),
}
}
@@ -33,7 +33,7 @@ pub struct ArgbColor {
impl ArgbColor {
pub fn new(a: u8, r: u8, g: u8, b: u8) -> Self {
Self {
- value: (a as u32) << 24 | (r as u32) << 16 | (g as u32) << 8 | b as u32,
+ value: ((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | b as u32,
}
}
diff --git a/azalea-protocol/src/packets/game/c_section_blocks_update.rs b/azalea-protocol/src/packets/game/c_section_blocks_update.rs
index 4554c015..05ceb30c 100755
--- a/azalea-protocol/src/packets/game/c_section_blocks_update.rs
+++ b/azalea-protocol/src/packets/game/c_section_blocks_update.rs
@@ -25,9 +25,9 @@ impl AzaleaRead for BlockStateWithPosition {
let state = BlockState::try_from(state)
.map_err(|_| BufReadError::UnexpectedEnumVariant { id: state as i32 })?;
let pos = ChunkSectionBlockPos {
- x: (position_part >> 8 & 15) as u8,
+ x: ((position_part >> 8) & 15) as u8,
y: (position_part & 15) as u8,
- z: (position_part >> 4 & 15) as u8,
+ z: ((position_part >> 4) & 15) as u8,
};
Ok(BlockStateWithPosition { pos, state })
}
@@ -35,8 +35,8 @@ impl AzaleaRead for BlockStateWithPosition {
impl AzaleaWrite for BlockStateWithPosition {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- let data = (self.state.id as u64) << 12
- | (u64::from(self.pos.x) << 8 | u64::from(self.pos.z) << 4 | u64::from(self.pos.y));
+ let data = ((self.state.id as u64) << 12)
+ | ((u64::from(self.pos.x) << 8) | (u64::from(self.pos.z) << 4) | u64::from(self.pos.y));
u64::azalea_write_var(&data, buf)?;
Ok(())
}
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index cf3ee7e4..5d92f795 100755
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -176,7 +176,7 @@ impl BitStorage {
let cell_index = self.cell_index(index as u64);
let cell = &self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
- cell >> bit_index & self.mask
+ (cell >> bit_index) & self.mask
}
pub fn get_and_set(&mut self, index: usize, value: u64) -> u64 {
@@ -190,8 +190,8 @@ impl BitStorage {
let cell_index = self.cell_index(index as u64);
let cell = &mut self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
- let old_value = *cell >> (bit_index as u64) & self.mask;
- *cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
+ let old_value = (*cell >> (bit_index as u64)) & self.mask;
+ *cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
old_value
}
@@ -206,7 +206,7 @@ impl BitStorage {
let cell_index = self.cell_index(index as u64);
let cell = &mut self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
- *cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
+ *cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
}
/// The number of entries.
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index 680363e6..0034e946 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -20,7 +20,6 @@
//! only have this on if the bot has operator permissions, otherwise it'll
//! just spam the server console unnecessarily.
-#![feature(async_closure)]
#![feature(trivial_bounds)]
mod commands;
@@ -53,9 +52,9 @@ async fn main() {
for username_or_email in &args.accounts {
let account = if username_or_email.contains('@') {
- Account::microsoft(&username_or_email).await.unwrap()
+ Account::microsoft(username_or_email).await.unwrap()
} else {
- Account::offline(&username_or_email)
+ Account::offline(username_or_email)
};
let mut commands = CommandDispatcher::new();
diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs
index c36ea790..dbdc9836 100644
--- a/azalea/src/pathfinder/astar.rs
+++ b/azalea/src/pathfinder/astar.rs
@@ -25,19 +25,6 @@ const COEFFICIENTS: [f32; 7] = [1.5, 2., 2.5, 3., 4., 5., 10.];
const MIN_IMPROVEMENT: f32 = 0.01;
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum PathfinderTimeout {
- /// Time out after a certain duration has passed. This is a good default so
- /// you don't waste too much time calculating a path if you're on a slow
- /// computer.
- Time(Duration),
- /// Time out after this many nodes have been considered.
- ///
- /// This is useful as an alternative to a time limit if you're doing
- /// something like running tests where you want consistent results.
- Nodes(usize),
-}
-
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
// Sources:
@@ -300,3 +287,21 @@ impl PartialOrd for WeightedNode {
Some(self.cmp(other))
}
}
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum PathfinderTimeout {
+ /// Time out after a certain duration has passed. This is a good default so
+ /// you don't waste too much time calculating a path if you're on a slow
+ /// computer.
+ Time(Duration),
+ /// Time out after this many nodes have been considered.
+ ///
+ /// This is useful as an alternative to a time limit if you're doing
+ /// something like running tests where you want consistent results.
+ Nodes(usize),
+}
+impl Default for PathfinderTimeout {
+ fn default() -> Self {
+ Self::Time(Duration::from_secs(1))
+ }
+}
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 95982215..0c926d03 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -142,8 +142,21 @@ pub struct GotoEvent {
/// Whether the bot is allowed to break blocks while pathfinding.
pub allow_mining: bool,
+ /// The minimum amount of time that should pass before the A* pathfinder
+ /// function can return a timeout. It may take up to [`Self::max_timeout`]
+ /// if it can't immediately find a usable path.
+ ///
+ /// A good default value for this is
+ /// `PathfinderTimeout::Time(Duration::from_secs(1))`.
+ ///
/// Also see [`PathfinderTimeout::Nodes`]
pub min_timeout: PathfinderTimeout,
+ /// The absolute maximum amount of time that the pathfinder function can
+ /// take to find a path. If it takes this long, it means no usable path was
+ /// found (so it might be impossible).
+ ///
+ /// A good default value for this is
+ /// `PathfinderTimeout::Time(Duration::from_secs(5))`.
pub max_timeout: PathfinderTimeout,
}
#[derive(Event, Clone, Debug)]
diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs
index f518523f..c50791b8 100644
--- a/azalea/src/pathfinder/world.rs
+++ b/azalea/src/pathfinder/world.rs
@@ -262,8 +262,9 @@ impl CachedWorld {
let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() };
// 20 bits total:
// 8 bits for x, 4 bits for y, 8 bits for z
- let hash_index =
- (pos.x as usize & 0xff) << 12 | (pos.y as usize & 0xf) << 8 | (pos.z as usize & 0xff);
+ let hash_index = ((pos.x as usize & 0xff) << 12)
+ | ((pos.y as usize & 0xf) << 8)
+ | (pos.z as usize & 0xff);
debug_assert!(hash_index < 1048576);
let &(cached_pos, potential_cost) =
unsafe { cached_mining_costs.get_unchecked(hash_index) };