diff options
| author | mat <git@matdoes.dev> | 2023-11-18 20:44:49 -0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-11-18 20:44:49 -0600 |
| commit | f0b58c7e748e1e94ad0dd08124cfc186e865709c (patch) | |
| tree | e57770be77d78262f89cc146179122a0b849c6c2 /azalea/examples/testbot.rs | |
| parent | 000abfa13665abccf543b875d10c8c2a48dd75be (diff) | |
| download | azalea-drasl-f0b58c7e748e1e94ad0dd08124cfc186e865709c.tar.xz | |
share registries in swarms and fix some bugs
Diffstat (limited to 'azalea/examples/testbot.rs')
| -rw-r--r-- | azalea/examples/testbot.rs | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index c47aa061..2dd5b306 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -7,7 +7,7 @@ use azalea::inventory::ItemSlot; use azalea::pathfinder::goals::BlockPosGoal; use azalea::{prelude::*, swarm::prelude::*, BlockPos, GameProfileComponent, WalkDirection}; use azalea::{Account, Client, Event}; -use azalea_client::SprintDirection; +use azalea_client::{InstanceHolder, SprintDirection}; use azalea_core::position::{ChunkBlockPos, ChunkPos, Vec3}; use azalea_protocol::packets::game::ClientboundGamePacket; use azalea_world::heightmap::HeightmapKind; @@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> { let mut accounts = Vec::new(); - for i in 0..3 { + for i in 0..100 { accounts.push(Account::offline(&format!("bot{i}"))); } @@ -56,7 +56,7 @@ async fn main() -> anyhow::Result<()> { .add_accounts(accounts.clone()) .set_handler(handle) .set_swarm_handler(swarm_handle) - .join_delay(Duration::from_millis(100)) + // .join_delay(Duration::from_millis(1000)) .start("localhost") .await; // let e = azalea::ClientBuilder::new() @@ -80,7 +80,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< bot.chat("Hello world"); } Event::Chat(m) => { - println!("client chat message: {}", m.content()); + // println!("client chat message: {}", m.content()); if m.content() == bot.profile.name { bot.chat("Bye"); tokio::time::sleep(Duration::from_millis(50)).await; @@ -100,7 +100,6 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< let entity = bot.entity_by::<With<Player>, (&GameProfileComponent,)>( |(profile,): &(&GameProfileComponent,)| profile.name == sender, ); - println!("sender entity: {entity:?}"); match m.content().as_str() { "whereami" => { let Some(entity) = entity else { @@ -308,6 +307,45 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< bot.chat("no chunk found"); } } + "debugchunks" => { + println!("shared:"); + + let partial_instance_lock = bot.component::<InstanceHolder>().partial_instance; + let local_chunk_storage = &partial_instance_lock.read().chunks; + + let mut total_loaded_chunks_count = 0; + for (chunk_pos, chunk) in &bot.world().read().chunks.map { + if let Some(chunk) = chunk.upgrade() { + let in_range = local_chunk_storage.in_range(chunk_pos); + println!( + "{chunk_pos:?} has {} references{}", + std::sync::Arc::strong_count(&chunk) - 1, + if in_range { "" } else { " (out of range)" } + ); + total_loaded_chunks_count += 1; + } + } + + println!("local:"); + + let mut local_loaded_chunks_count = 0; + for (i, chunk) in local_chunk_storage.chunks().enumerate() { + if let Some(chunk) = chunk { + let chunk_pos = local_chunk_storage.chunk_pos_from_index(i); + println!( + "{chunk_pos:?} has {} references", + std::sync::Arc::strong_count(&chunk) + ); + local_loaded_chunks_count += 1; + } + } + + println!("total loaded chunks: {total_loaded_chunks_count}"); + println!( + "local loaded chunks: {local_loaded_chunks_count}/{}", + local_chunk_storage.chunks().collect::<Vec<_>>().len() + ); + } _ => {} } } |
