From 53fca5faf4878c7afcd65f1eb0811c2b8e02a214 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 21 Jan 2025 23:53:11 +0000 Subject: [PATCH] fix errors when switching worlds --- azalea-client/src/chunks.rs | 5 ++++- azalea-client/src/packet_handling/game.rs | 24 +++++++++++------------ azalea-core/src/registry_holder.rs | 4 ++-- azalea-physics/src/fluids.rs | 2 +- azalea-protocol/src/packets/common.rs | 2 +- azalea-world/src/container.rs | 5 +++-- registries.txt | 1 + 7 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 registries.txt diff --git a/azalea-client/src/chunks.rs b/azalea-client/src/chunks.rs index 7056efa4..0267c164 100644 --- a/azalea-client/src/chunks.rs +++ b/azalea-client/src/chunks.rs @@ -111,7 +111,10 @@ pub fn handle_receive_chunk_events( heightmaps, &mut instance.chunks, ) { - error!("Couldn't set chunk data: {e}"); + error!( + "Couldn't set chunk data: {e}. World height: {}", + instance.chunks.height + ); } } } diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 57e6ce68..4553ae6a 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -253,13 +253,12 @@ pub fn process_packet_events(ecs: &mut World) { continue; }; - let dimension_type = - ResourceLocation::new(&p.common.dimension_type.to_string()); + let dimension_name = ResourceLocation::new(&p.common.dimension.to_string()); - let dimension = dimension_type_element - .map - .get(&dimension_type) - .unwrap_or_else(|| panic!("No dimension_type with name {dimension_type}")); + let Some(dimension) = dimension_type_element.map.get(&dimension_name) else { + error!("No dimension_type with name {dimension_name}") + continue; + }; // add this world to the instance_container (or don't if it's already // there) @@ -1394,17 +1393,16 @@ pub fn process_packet_events(ecs: &mut World) { let Some(dimension_type_element) = instance_holder.instance.read().registries.dimension_type() else { - error!("Server didn't send dimension type registry, can't log in"); + error!("Server didn't send dimension type registry, can't log in."); continue; }; - let dimension_type = - ResourceLocation::new(&p.common.dimension_type.to_string()); + let dimension_name = ResourceLocation::new(&p.common.dimension.to_string()); - let dimension = dimension_type_element - .map - .get(&dimension_type) - .unwrap_or_else(|| panic!("No dimension_type with name {dimension_type}")); + let Some(dimension) = dimension_type_element.map.get(&dimension_name) else { + error!("No dimension_type with name {dimension_name}"); + continue; + }; // add this world to the instance_container (or don't if it's already // there) diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs index 0d2588cf..41cf0d05 100644 --- a/azalea-core/src/registry_holder.rs +++ b/azalea-core/src/registry_holder.rs @@ -152,7 +152,7 @@ pub struct DimensionTypeElement { pub natural: bool, pub piglin_safe: bool, pub respawn_anchor_works: bool, - pub ultrawarm: bool, + pub ultrawarm: Option, } /// Dimension attributes. @@ -161,7 +161,7 @@ pub struct DimensionTypeElement { pub struct DimensionTypeElement { pub height: u32, pub min_y: i32, - pub ultrawarm: bool, + pub ultrawarm: Option, #[simdnbt(flatten)] pub _extra: HashMap, } diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index 6e89cdea..78a9d467 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -35,7 +35,7 @@ pub fn update_in_water_state_and_do_fluid_pushing( .registries .dimension_type() .and_then(|d| d.map.get(instance_name).map(|d| d.ultrawarm)) - == Some(true); + == Some(Some(true)); let lava_push_factor = if is_ultrawarm { 0.007 } else { diff --git a/azalea-protocol/src/packets/common.rs b/azalea-protocol/src/packets/common.rs index fc78cd7a..a19c4f2a 100644 --- a/azalea-protocol/src/packets/common.rs +++ b/azalea-protocol/src/packets/common.rs @@ -7,7 +7,7 @@ use azalea_core::{ #[derive(Clone, Debug, AzBuf)] pub struct CommonPlayerSpawnInfo { - pub dimension_type: azalea_registry::DimensionType, + pub dimension: azalea_registry::DimensionType, pub dimension: ResourceLocation, pub seed: i64, pub game_type: GameMode, diff --git a/azalea-world/src/container.rs b/azalea-world/src/container.rs index 7e5927e3..9fa5d7f9 100644 --- a/azalea-world/src/container.rs +++ b/azalea-world/src/container.rs @@ -9,7 +9,7 @@ use derive_more::{Deref, DerefMut}; use nohash_hasher::IntMap; use parking_lot::RwLock; use rustc_hash::FxHashMap; -use tracing::error; +use tracing::{debug, error}; use crate::{ChunkStorage, Instance}; @@ -43,7 +43,7 @@ impl InstanceContainer { self.instances.get(name).and_then(|world| world.upgrade()) } - /// Add an empty world to the container (or not if it already exists) and + /// Add an empty world to the container (unless it already exists) and /// returns a strong reference to the world. #[must_use = "the world will be immediately forgotten if unused"] pub fn insert( @@ -74,6 +74,7 @@ impl InstanceContainer { entity_by_id: IntMap::default(), registries: RegistryHolder::default(), })); + debug!("Added new instance {name}"); self.instances.insert(name, Arc::downgrade(&world)); world } diff --git a/registries.txt b/registries.txt new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/registries.txt @@ -0,0 +1 @@ +{}