Skip to content

Commit

Permalink
Merge branch 'main' into 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Apr 19, 2024
2 parents fb06830 + 8808ece commit 23e9506
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
1 change: 1 addition & 0 deletions azalea-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub struct MinecraftAuthResponse {
pub struct GameOwnershipResponse {
pub items: Vec<GameOwnershipItem>,
pub signature: String,
#[serde(rename = "keyId")]
pub key_id: String,
}

Expand Down
14 changes: 9 additions & 5 deletions azalea-physics/src/collision/world_collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec<VoxelShape> {
let mut block_collisions = Vec::new();

let initial_chunk_pos = ChunkPos::from(state.cursor.origin());
let initial_chunk = world.chunks.get(&initial_chunk_pos).unwrap();
let initial_chunk = initial_chunk.read();
let initial_chunk = world.chunks.get(&initial_chunk_pos);
let initial_chunk = initial_chunk.as_deref().map(RwLock::read);

while let Some(item) = state.cursor.next() {
if item.iteration_type == CursorIterationType::Corner {
Expand All @@ -25,9 +25,13 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec<VoxelShape> {

let item_chunk_pos = ChunkPos::from(item.pos);
let block_state: BlockState = if item_chunk_pos == initial_chunk_pos {
initial_chunk
.get(&ChunkBlockPos::from(item.pos), state.world.chunks.min_y)
.unwrap_or(BlockState::AIR)
if let Some(initial_chunk) = &initial_chunk {
initial_chunk
.get(&ChunkBlockPos::from(item.pos), state.world.chunks.min_y)
.unwrap_or(BlockState::AIR)
} else {
BlockState::AIR
}
} else {
state.get_block_state(item.pos)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pub enum EventType {
PufferFishSting = 9,
GuardianElderEffect = 10,
ImmediateRespawn = 11,
LimitedCrafting = 12,
WaitForLevelChunks = 13,
}
21 changes: 21 additions & 0 deletions azalea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub mod pathfinder;
pub mod prelude;
pub mod swarm;

use std::net::SocketAddr;

use app::Plugins;
pub use azalea_auth as auth;
pub use azalea_block as blocks;
Expand Down Expand Up @@ -189,6 +191,25 @@ where
}
self.swarm.start(address).await
}

/// Do the same as [`Self::start`], but allow passing in a custom resolved
/// address. This is useful if the address you're connecting to doesn't
/// resolve to anything, like if the server uses the address field to pass
/// custom data (like Bungeecord or Forge).
pub async fn start_with_custom_resolved_address(
mut self,
account: Account,
address: impl TryInto<ServerAddress>,
resolved_address: SocketAddr,
) -> Result<!, StartError> {
self.swarm.accounts = vec![account];
if self.swarm.states.is_empty() {
self.swarm.states = vec![S::default()];
}
self.swarm
.start_with_custom_resolved_address(address, resolved_address)
.await
}
}
impl Default for ClientBuilder<NoState> {
fn default() -> Self {
Expand Down
42 changes: 39 additions & 3 deletions azalea/src/swarm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,28 @@ where
///
/// [`ServerAddress`]: azalea_protocol::ServerAddress
pub async fn start(self, address: impl TryInto<ServerAddress>) -> Result<!, StartError> {
// convert the TryInto<ServerAddress> into a ServerAddress
let address: ServerAddress = match address.try_into() {
Ok(address) => address,
Err(_) => return Err(StartError::InvalidAddress),
};

// resolve the address
let resolved_address = resolver::resolve_address(&address).await?;

self.start_with_custom_resolved_address(address, resolved_address)
.await
}

/// Do the same as [`Self::start`], but allow passing in a custom resolved
/// address. This is useful if the address you're connecting to doesn't
/// resolve to anything, like if the server uses the address field to pass
/// custom data (like Bungeecord or Forge).
pub async fn start_with_custom_resolved_address(
self,
address: impl TryInto<ServerAddress>,
resolved_address: SocketAddr,
) -> Result<!, StartError> {
assert_eq!(
self.accounts.len(),
self.states.len(),
Expand All @@ -308,9 +330,6 @@ where
Err(_) => return Err(StartError::InvalidAddress),
};

// resolve the address
let resolved_address = resolver::resolve_address(&address).await?;

let instance_container = Arc::new(RwLock::new(InstanceContainer::default()));

// we can't modify the swarm plugins after this
Expand Down Expand Up @@ -528,6 +547,23 @@ impl Swarm {
let address = self.address.read().clone();
let resolved_address = *self.resolved_address.read();

self.add_with_custom_address(account, state, address, resolved_address)
.await
}
/// Add a new account to the swarm, using the given host and socket
/// address. This is useful if you want bots in the same swarm to connect to
/// different addresses. Usually you'll just want [`Self::add`] though.
///
/// # Errors
///
/// Returns an `Err` if the bot could not do a handshake successfully.
pub async fn add_with_custom_address<S: Component + Clone>(
&mut self,
account: &Account,
state: S,
address: ServerAddress,
resolved_address: SocketAddr,
) -> Result<Client, JoinError> {
let (bot, mut rx) = Client::start_client(
self.ecs_lock.clone(),
account,
Expand Down

0 comments on commit 23e9506

Please sign in to comment.