mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
make swarm iter & fix new chunks not loading
This commit is contained in:
parent
8e7c21750c
commit
f747e6df0c
3 changed files with 36 additions and 23 deletions
|
@ -159,31 +159,27 @@ impl PartialChunkStorage {
|
|||
/// Get a [`Chunk`] within render distance, or `None` if it's not loaded.
|
||||
/// Use [`PartialChunkStorage::get`] to get a chunk from the shared storage.
|
||||
pub fn limited_get(&self, pos: &ChunkPos) -> Option<&Arc<Mutex<Chunk>>> {
|
||||
let index = self.get_index(pos);
|
||||
if index >= self.chunks.len() {
|
||||
if !self.in_range(pos) {
|
||||
warn!(
|
||||
"Chunk at {:?} is not in the render distance (center: {:?}, {} chunks, {} >= {})",
|
||||
pos,
|
||||
self.view_center,
|
||||
self.chunk_radius,
|
||||
index,
|
||||
self.chunks.len()
|
||||
"Chunk at {:?} is not in the render distance (center: {:?}, {} chunks)",
|
||||
pos, self.view_center, self.chunk_radius,
|
||||
);
|
||||
None
|
||||
} else {
|
||||
self.chunks[index].as_ref()
|
||||
return None;
|
||||
}
|
||||
|
||||
let index = self.get_index(pos);
|
||||
self.chunks[index].as_ref()
|
||||
}
|
||||
/// Get a mutable reference to a [`Chunk`] within render distance, or
|
||||
/// `None` if it's not loaded. Use [`PartialChunkStorage::get`] to get
|
||||
/// a chunk from the shared storage.
|
||||
pub fn limited_get_mut(&mut self, pos: &ChunkPos) -> Option<&mut Option<Arc<Mutex<Chunk>>>> {
|
||||
let index = self.get_index(pos);
|
||||
if index >= self.chunks.len() {
|
||||
None
|
||||
} else {
|
||||
Some(&mut self.chunks[index])
|
||||
if !self.in_range(pos) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let index = self.get_index(pos);
|
||||
Some(&mut self.chunks[index])
|
||||
}
|
||||
|
||||
/// Get a chunk,
|
||||
|
|
|
@ -327,6 +327,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> IntoIterator for Swarm<S>
|
||||
where
|
||||
S: Send + Sync + Clone + 'static,
|
||||
{
|
||||
type Item = (Client, S);
|
||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.bot_datas.lock().clone().into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct InternalSwarmState {
|
||||
/// The number of bots connected to the server
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea::pathfinder::BlockPosGoal;
|
||||
use azalea::ClientInformation;
|
||||
// use azalea::ClientInformation;
|
||||
use azalea::{prelude::*, BlockPos, Swarm, SwarmEvent, WalkDirection};
|
||||
use azalea::{Account, Client, Event};
|
||||
use azalea_protocol::packets::game::serverbound_client_command_packet::ServerboundClientCommandPacket;
|
||||
|
@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let mut accounts = Vec::new();
|
||||
let mut states = Vec::new();
|
||||
|
||||
for i in 0..10 {
|
||||
for i in 0..7 {
|
||||
accounts.push(Account::offline(&format!("bot{}", i)));
|
||||
states.push(State::default());
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ async fn main() -> anyhow::Result<()> {
|
|||
async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
|
||||
match event {
|
||||
Event::Init => {
|
||||
bot.set_client_information(ClientInformation {
|
||||
view_distance: 2,
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
// bot.set_client_information(ClientInformation {
|
||||
// view_distance: 2,
|
||||
// ..Default::default()
|
||||
// })
|
||||
// .await?;
|
||||
}
|
||||
Event::Login => {
|
||||
bot.chat("Hello world").await?;
|
||||
|
@ -149,6 +149,11 @@ async fn swarm_handle(
|
|||
}
|
||||
}
|
||||
}
|
||||
if m.message().to_string() == "<py5> hi" {
|
||||
for (bot, _) in swarm {
|
||||
bot.chat("hello").await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue