1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix sometimes not receiving chunks

This commit is contained in:
mat 2023-07-23 23:21:08 -05:00
parent 15acf13477
commit 22ea8c60fe
6 changed files with 35 additions and 20 deletions

View file

@ -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);
}
}

View file

@ -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),
))),

View file

@ -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,6 +284,18 @@ fn process_packet_events(ecs: &mut World) {
));
}
// brand
let mut brand_data = Vec::new();
// they don't have to know :)
"vanilla".write_into(&mut brand_data).unwrap();
local_player.write_packet(
ServerboundCustomPayloadPacket {
identifier: ResourceLocation::new("brand"),
data: brand_data.into(),
}
.get(),
);
// send the client information that we have set
log::debug!(
"Sending client information because login: {:?}",
@ -289,18 +303,6 @@ fn process_packet_events(ecs: &mut World) {
);
local_player.write_packet(client_information.clone().get());
// brand
let mut brand_data = Vec::new();
"vanilla".to_string().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(),
);
system_state.apply(ecs);
}
ClientboundGamePacket::SetChunkCacheRadius(p) => {

View file

@ -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 {

View file

@ -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::*;

View file

@ -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()
// })