Skip to content

Commit 68ee962

Browse files
committed
Fix errors on switching dimensions
1 parent 63b1036 commit 68ee962

File tree

13 files changed

+449
-177
lines changed

13 files changed

+449
-177
lines changed

azalea-client/src/chunks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
time::{Duration, Instant},
99
};
1010

11-
use azalea_core::position::ChunkPos;
1211
use azalea_protocol::packets::game::{
1312
c_level_chunk_with_light::ClientboundLevelChunkWithLight,
1413
s_chunk_batch_received::ServerboundChunkBatchReceived,
@@ -76,7 +75,7 @@ pub fn handle_receive_chunk_events(
7675
mut query: Query<&mut InstanceHolder>,
7776
) {
7877
for event in events.read() {
79-
let pos = ChunkPos::new(event.packet.x, event.packet.z);
78+
let pos = event.packet.pos;
8079

8180
let local_player = query.get_mut(event.entity).unwrap();
8281

azalea-client/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub mod respawn;
2929
pub mod send_client_end;
3030
pub mod task_pool;
3131

32+
#[doc(hidden)]
33+
pub mod test_simulation;
34+
3235
pub use account::{Account, AccountOpts};
3336
pub use azalea_protocol::common::client_information::ClientInformation;
3437
pub use client::{

azalea-client/src/packet_handling/game.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,20 @@ pub fn process_packet_events(ecs: &mut World) {
246246
.insert(InstanceName(new_instance_name.clone()));
247247
}
248248

249-
let Some(dimension_type_element) =
250-
instance_holder.instance.read().registries.dimension_type()
249+
let Some((_dimension_type, dimension_data)) = p
250+
.common
251+
.dimension_type(&instance_holder.instance.read().registries)
251252
else {
252-
error!("Server didn't send dimension type registry, can't log in");
253-
continue;
254-
};
255-
256-
let dimension_name = ResourceLocation::new(&p.common.dimension.to_string());
257-
258-
let Some(dimension) = dimension_type_element.map.get(&dimension_name) else {
259-
error!("No dimension_type with name {dimension_name}");
260253
continue;
261254
};
262255

263256
// add this world to the instance_container (or don't if it's already
264257
// there)
265258
let weak_instance = instance_container.insert(
266259
new_instance_name.clone(),
267-
dimension.height,
268-
dimension.min_y,
260+
dimension_data.height,
261+
dimension_data.min_y,
262+
&instance_holder.instance.read().registries,
269263
);
270264
instance_loaded_events.send(InstanceLoadedEvent {
271265
entity: player_entity,
@@ -610,7 +604,7 @@ pub fn process_packet_events(ecs: &mut World) {
610604
// debug!("Got light update packet {p:?}");
611605
}
612606
ClientboundGamePacket::LevelChunkWithLight(p) => {
613-
debug!("Got chunk with light packet {} {}", p.x, p.z);
607+
debug!("Got chunk with light packet {:?}", p.pos);
614608

615609
let mut system_state: SystemState<EventWriter<chunks::ReceiveChunkEvent>> =
616610
SystemState::new(ecs);
@@ -1387,26 +1381,20 @@ pub fn process_packet_events(ecs: &mut World) {
13871381
{
13881382
let new_instance_name = p.common.dimension.clone();
13891383

1390-
let Some(dimension_type_element) =
1391-
instance_holder.instance.read().registries.dimension_type()
1384+
let Some((_dimension_type, dimension_data)) = p
1385+
.common
1386+
.dimension_type(&instance_holder.instance.read().registries)
13921387
else {
1393-
error!("Server didn't send dimension type registry, can't log in.");
1394-
continue;
1395-
};
1396-
1397-
let dimension_name = ResourceLocation::new(&p.common.dimension.to_string());
1398-
1399-
let Some(dimension) = dimension_type_element.map.get(&dimension_name) else {
1400-
error!("No dimension_type with name {dimension_name}");
14011388
continue;
14021389
};
14031390

14041391
// add this world to the instance_container (or don't if it's already
14051392
// there)
14061393
let weak_instance = instance_container.insert(
14071394
new_instance_name.clone(),
1408-
dimension.height,
1409-
dimension.min_y,
1395+
dimension_data.height,
1396+
dimension_data.min_y,
1397+
&instance_holder.instance.read().registries,
14101398
);
14111399
instance_loaded_events.send(InstanceLoadedEvent {
14121400
entity: player_entity,

0 commit comments

Comments
 (0)