aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-07-23 23:21:08 -0500
committermat <git@matdoes.dev>2023-07-23 23:21:08 -0500
commit22ea8c60fed17e48a591bcbb82808fed55509386 (patch)
treea85be1738270f7fb2a133b20629f2db0464e58f2
parent15acf1347727b84472e6a8a1c7a4f51cd3163f01 (diff)
downloadazalea-drasl-22ea8c60fed17e48a591bcbb82808fed55509386.tar.xz
fix sometimes not receiving chunks
-rw-r--r--azalea-client/src/events.rs8
-rw-r--r--azalea-client/src/local_player.rs4
-rw-r--r--azalea-client/src/packet_handling.rs24
-rwxr-xr-xazalea-world/src/chunk_storage.rs6
-rw-r--r--azalea-world/src/lib.rs4
-rw-r--r--azalea/examples/testbot.rs3
6 files changed, 32 insertions, 17 deletions
diff --git a/azalea-client/src/events.rs b/azalea-client/src/events.rs
index b581fcee..d5a32449 100644
--- a/azalea-client/src/events.rs
+++ b/azalea-client/src/events.rs
@@ -7,11 +7,12 @@ use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
};
use azalea_world::{InstanceName, MinecraftEntityId};
-use bevy_app::{App, FixedUpdate, Plugin, Update};
+use bevy_app::{App, FixedUpdate, Plugin, PreUpdate, Update};
use bevy_ecs::{
component::Component,
event::EventReader,
query::{Added, With},
+ schedule::IntoSystemConfigs,
system::Query,
};
use derive_more::{Deref, DerefMut};
@@ -110,7 +111,6 @@ impl Plugin for EventPlugin {
(
chat_listener,
login_listener,
- init_listener,
packet_listener,
add_player_listener,
update_player_listener,
@@ -119,6 +119,10 @@ impl Plugin for EventPlugin {
keepalive_listener,
),
)
+ .add_systems(
+ PreUpdate,
+ init_listener.before(crate::packet_handling::process_packet_events),
+ )
.add_systems(FixedUpdate, tick_listener);
}
}
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 594513db..8317a72d 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -105,7 +105,9 @@ impl LocalPlayer {
world,
partial_instance: Arc::new(RwLock::new(PartialInstance::new(
- client_information.view_distance.into(),
+ azalea_world::calculate_chunk_storage_range(
+ client_information.view_distance.into(),
+ ),
Some(entity),
))),
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs
index bf438de0..158fbb83 100644
--- a/azalea-client/src/packet_handling.rs
+++ b/azalea-client/src/packet_handling.rs
@@ -188,7 +188,7 @@ pub fn send_packet_events(
}
}
-fn process_packet_events(ecs: &mut World) {
+pub fn process_packet_events(ecs: &mut World) {
let mut events_owned = Vec::new();
let mut system_state: SystemState<EventReader<PacketEvent>> = SystemState::new(ecs);
let mut events = system_state.get_mut(ecs);
@@ -254,7 +254,9 @@ fn process_packet_events(ecs: &mut World) {
// instance_container)
*local_player.partial_instance.write() = PartialInstance::new(
- client_information.view_distance.into(),
+ azalea_world::calculate_chunk_storage_range(
+ client_information.view_distance.into(),
+ ),
// this argument makes it so other clients don't update this
// player entity
// in a shared world
@@ -282,25 +284,25 @@ fn process_packet_events(ecs: &mut World) {
));
}
- // send the client information that we have set
- log::debug!(
- "Sending client information because login: {:?}",
- client_information
- );
- local_player.write_packet(client_information.clone().get());
-
// brand
let mut brand_data = Vec::new();
- "vanilla".to_string().write_into(&mut brand_data).unwrap();
+ // they don't have to know :)
+ "vanilla".write_into(&mut brand_data).unwrap();
local_player.write_packet(
ServerboundCustomPayloadPacket {
identifier: ResourceLocation::new("brand"),
- // they don't have to know :)
data: brand_data.into(),
}
.get(),
);
+ // send the client information that we have set
+ log::debug!(
+ "Sending client information because login: {:?}",
+ client_information
+ );
+ local_player.write_packet(client_information.clone().get());
+
system_state.apply(ecs);
}
ClientboundGamePacket::SetChunkCacheRadius(p) => {
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs
index 3c8d3555..d831770c 100755
--- a/azalea-world/src/chunk_storage.rs
+++ b/azalea-world/src/chunk_storage.rs
@@ -53,6 +53,12 @@ pub struct Section {
pub biomes: PalettedContainer,
}
+/// Get the actual stored view distance for the selected view distance. For some
+/// reason Minecraft actually stores an extra 3 chunks.
+pub fn calculate_chunk_storage_range(view_distance: u32) -> u32 {
+ u32::max(view_distance, 2) + 3
+}
+
impl Default for Section {
fn default() -> Self {
Section {
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index be2c46c1..9c1f5ff5 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -13,7 +13,9 @@ mod world;
use std::backtrace::Backtrace;
pub use bit_storage::BitStorage;
-pub use chunk_storage::{Chunk, ChunkStorage, PartialChunkStorage, Section};
+pub use chunk_storage::{
+ calculate_chunk_storage_range, Chunk, ChunkStorage, PartialChunkStorage, Section,
+};
pub use container::*;
use thiserror::Error;
pub use world::*;
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs
index 40ce7dce..9129eb3f 100644
--- a/azalea/examples/testbot.rs
+++ b/azalea/examples/testbot.rs
@@ -71,8 +71,7 @@ async fn main() -> anyhow::Result<()> {
async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
match event {
Event::Init => {
- println!("bot init");
- // bot.set_client_information(ClientInformation {
+ // bot.set_client_information(azalea_client::ClientInformation {
// view_distance: 2,
// ..Default::default()
// })