diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2024-04-23 10:34:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 10:34:50 -0500 |
| commit | 1d80f531b74bc3b31023753acb81b35efcdadd73 (patch) | |
| tree | 675635c7c41fbb456e3e0dd7b9f09c7211d356f0 /azalea-client/src | |
| parent | 0ddad8bd9c7c0e8846aec8bc90c95416418c9a63 (diff) | |
| download | azalea-drasl-1d80f531b74bc3b31023753acb81b35efcdadd73.tar.xz | |
1.20.5 (#127)
* 23w51b
* make recalculate_near_end_of_path public
so other plugins can do .after(recalculate_near_end_of_path)
* update to 24w03a i think
* start implementing 24w13a
* registries work (but a lot of packets are still broken)
* fix recipes and commands packets
* i love codecs :D i am not going insane :D mojang's java is very readable :D
* item components are "implemented" meowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeow
* update to 1.20.5-pre3
* fix all the broken packets and clippy (mojang please don't do an update like this again or i will murder someone)
* 1.20.5-rc1
* fix failing tests
* 1.20.5
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/client.rs | 17 | ||||
| -rw-r--r-- | azalea-client/src/interact.rs | 13 | ||||
| -rw-r--r-- | azalea-client/src/inventory.rs | 18 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/configuration.rs | 55 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/game.rs | 43 |
5 files changed, 86 insertions, 60 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 93852c75..39cc504c 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -306,6 +306,14 @@ impl Client { run_schedule_sender.clone(), ); + let instance = Instance::default(); + let instance_holder = crate::local_player::InstanceHolder::new( + entity, + // default to an empty world, it'll be set correctly later when we + // get the login packet + Arc::new(RwLock::new(instance)), + ); + ecs.entity_mut(entity).insert(( // these stay when we switch to the game state LocalPlayerBundle { @@ -318,6 +326,7 @@ impl Client { local_player_events: LocalPlayerEvents(tx), game_profile: GameProfileComponent(game_profile), client_information: crate::ClientInformation::default(), + instance_holder, }, InConfigurationState, )); @@ -394,7 +403,7 @@ impl Client { match packet { ClientboundLoginPacket::Hello(p) => { debug!("Got encryption request"); - let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); + let e = azalea_crypto::encrypt(&p.public_key, &p.challenge).unwrap(); if let Some(access_token) = &account.access_token { // keep track of the number of times we tried @@ -436,7 +445,7 @@ impl Client { conn.write( ServerboundKeyPacket { key_bytes: e.encrypted_public_key, - encrypted_challenge: e.encrypted_nonce, + encrypted_challenge: e.encrypted_challenge, } .get(), ) @@ -466,6 +475,9 @@ impl Client { // replying to custom query is done in // packet_handling::login::process_packet_events } + ClientboundLoginPacket::CookieRequest(p) => { + debug!("Got cookie request {:?}", p); + } } }; @@ -666,6 +678,7 @@ pub struct LocalPlayerBundle { pub local_player_events: LocalPlayerEvents, pub game_profile: GameProfileComponent, pub client_information: ClientInformation, + pub instance_holder: InstanceHolder, } /// A bundle for the components that are present on a local player that is diff --git a/azalea-client/src/interact.rs b/azalea-client/src/interact.rs index 8a3aa49b..14fea407 100644 --- a/azalea-client/src/interact.rs +++ b/azalea-client/src/interact.rs @@ -17,6 +17,7 @@ use azalea_protocol::packets::game::{ serverbound_swing_packet::ServerboundSwingPacket, serverbound_use_item_on_packet::{BlockHit, ServerboundUseItemOnPacket}, }; +use azalea_registry::DataComponentKind; use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_app::{App, Plugin, Update}; use bevy_ecs::{ @@ -28,7 +29,6 @@ use bevy_ecs::{ system::{Commands, Query, Res}, }; use derive_more::{Deref, DerefMut}; -use simdnbt::owned::NbtList; use tracing::warn; use crate::{ @@ -269,20 +269,11 @@ pub fn check_block_can_be_broken_by_item_in_adventure_mode( // minecraft caches the last checked block but that's kind of an unnecessary // optimization and makes the code too complicated - let Some(can_destroy) = item - .nbt - .compound("tag") - .and_then(|nbt| nbt.list("CanDestroy")) - else { + let Some(_can_destroy) = item.components.get(DataComponentKind::CanBreak) else { // no CanDestroy tag return false; }; - let NbtList::String(_can_destroy) = can_destroy else { - // CanDestroy tag must be a list of strings - return false; - }; - false // for block_predicate in can_destroy { diff --git a/azalea-client/src/inventory.rs b/azalea-client/src/inventory.rs index 4bfed69f..97eb98ea 100644 --- a/azalea-client/src/inventory.rs +++ b/azalea-client/src/inventory.rs @@ -252,7 +252,7 @@ impl InventoryComponent { // && slot.may_place(item_stack) && ( self.quick_craft_kind == QuickCraftKind::Middle - || item_stack.count() as i32 >= self.quick_craft_slots.len() as i32 + || item_stack.count() >= self.quick_craft_slots.len() as i32 ) { break; @@ -273,9 +273,9 @@ impl InventoryComponent { &mut new_carried, slot_item_count, ); - let max_stack_size = i8::min( + let max_stack_size = i32::min( new_carried.kind.max_stack_size(), - i8::min( + i32::min( new_carried.kind.max_stack_size(), slot.kind.max_stack_size(), ), @@ -391,7 +391,7 @@ impl InventoryComponent { }; if self.menu().may_place(source_slot_index, target_item) { let source_max_stack = self.menu().max_stack_size(source_slot_index); - if target_slot.count() > source_max_stack as i8 { + if target_slot.count() > source_max_stack as i32 { // if there's more than the max stack size in the target slot let target_slot = self.menu_mut().slot_mut(target_slot_index).unwrap(); @@ -449,7 +449,7 @@ impl InventoryComponent { ThrowClick::All { .. } => slot_item.count, }; - let _dropping = slot_item.split(dropping_count as u8); + let _dropping = slot_item.split(dropping_count as u32); // player.drop(dropping, true); } ClickOperation::PickupAll(PickupAllClick { @@ -492,7 +492,7 @@ impl InventoryComponent { let checking_slot = self.menu_mut().slot_mut(i).unwrap(); let taken_item = - checking_slot.split(checking_slot.count() as u8); + checking_slot.split(checking_slot.count() as u32); // now extend the carried item let target_slot = &mut self.carried; @@ -537,7 +537,7 @@ fn can_item_quick_replace( return false; }; - if !item.is_same_item_and_nbt(target_slot) { + if !item.is_same_item_and_components(target_slot) { return false; } let count = target_slot.count as u16 @@ -553,10 +553,10 @@ fn get_quick_craft_slot_count( quick_craft_slots: &HashSet<u16>, quick_craft_kind: &QuickCraftKind, item: &mut ItemSlotData, - slot_item_count: i8, + slot_item_count: i32, ) { item.count = match quick_craft_kind { - QuickCraftKind::Left => item.count / quick_craft_slots.len() as i8, + QuickCraftKind::Left => item.count / quick_craft_slots.len() as i32, QuickCraftKind::Right => 1, QuickCraftKind::Middle => item.kind.max_stack_size(), }; diff --git a/azalea-client/src/packet_handling/configuration.rs b/azalea-client/src/packet_handling/configuration.rs index da5ce57f..add36c6e 100644 --- a/azalea-client/src/packet_handling/configuration.rs +++ b/azalea-client/src/packet_handling/configuration.rs @@ -1,20 +1,18 @@ use std::io::Cursor; -use std::sync::Arc; use azalea_entity::indexing::EntityIdIndex; use azalea_protocol::packets::configuration::serverbound_finish_configuration_packet::ServerboundFinishConfigurationPacket; use azalea_protocol::packets::configuration::serverbound_keep_alive_packet::ServerboundKeepAlivePacket; use azalea_protocol::packets::configuration::serverbound_pong_packet::ServerboundPongPacket; use azalea_protocol::packets::configuration::serverbound_resource_pack_packet::ServerboundResourcePackPacket; +use azalea_protocol::packets::configuration::serverbound_select_known_packs_packet::ServerboundSelectKnownPacksPacket; use azalea_protocol::packets::configuration::{ ClientboundConfigurationPacket, ServerboundConfigurationPacket, }; use azalea_protocol::packets::ConnectionProtocol; use azalea_protocol::read::deserialize_packet; -use azalea_world::Instance; use bevy_ecs::prelude::*; use bevy_ecs::system::SystemState; -use parking_lot::RwLock; use tracing::{debug, error, warn}; use crate::client::InConfigurationState; @@ -22,6 +20,7 @@ use crate::disconnect::DisconnectEvent; use crate::local_player::Hunger; use crate::packet_handling::game::KeepAliveEvent; use crate::raw_connection::RawConnection; +use crate::InstanceHolder; #[derive(Event, Debug, Clone)] pub struct ConfigurationPacketEvent { @@ -80,21 +79,14 @@ pub fn process_packet_events(ecs: &mut World) { for (player_entity, packet) in events_owned { match packet { ClientboundConfigurationPacket::RegistryData(p) => { - let mut instance = Instance::default(); - - // override the old registries with the new ones - // but if a registry wasn't sent, keep the old one - for (registry_name, registry) in p.registry_holder.map { - instance.registries.map.insert(registry_name, registry); - } + let mut system_state: SystemState<Query<&mut InstanceHolder>> = + SystemState::new(ecs); + let mut query = system_state.get_mut(ecs); + let instance_holder = query.get_mut(player_entity).unwrap(); + let mut instance = instance_holder.instance.write(); - let instance_holder = crate::local_player::InstanceHolder::new( - player_entity, - // default to an empty world, it'll be set correctly later when we - // get the login packet - Arc::new(RwLock::new(instance)), - ); - ecs.entity_mut(player_entity).insert(instance_holder); + // add the new registry data + instance.registries.append(p.registry_id, p.entries); } ClientboundConfigurationPacket::CustomPayload(p) => { @@ -200,6 +192,35 @@ pub fn process_packet_events(ecs: &mut World) { ClientboundConfigurationPacket::UpdateTags(_p) => { debug!("Got update tags packet"); } + ClientboundConfigurationPacket::CookieRequest(p) => { + debug!("Got cookie request packet {p:?}"); + } + ClientboundConfigurationPacket::ResetChat(p) => { + debug!("Got reset chat packet {p:?}"); + } + ClientboundConfigurationPacket::StoreCookie(p) => { + debug!("Got store cookie packet {p:?}"); + } + ClientboundConfigurationPacket::Transfer(p) => { + debug!("Got transfer packet {p:?}"); + } + ClientboundConfigurationPacket::SelectKnownPacks(p) => { + debug!("Got select known packs packet {p:?}"); + + let mut system_state: SystemState<Query<&RawConnection>> = SystemState::new(ecs); + let mut query = system_state.get_mut(ecs); + let raw_connection = query.get_mut(player_entity).unwrap(); + + // resource pack management isn't implemented + raw_connection + .write_packet( + ServerboundSelectKnownPacksPacket { + known_packs: vec![], + } + .get(), + ) + .unwrap(); + } } } } diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 1c913ba5..dd2695dc 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -243,20 +243,20 @@ pub fn process_packet_events(ecs: &mut World) { .insert(InstanceName(new_instance_name.clone())); } - let Some(dimension_type) = + 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"); continue; }; - let dimension = &dimension_type - .value - .iter() - .find(|t| t.name == p.common.dimension_type) - .unwrap_or_else(|| { - panic!("No dimension_type with name {}", p.common.dimension_type) - }) - .element; + + let dimension_type = + ResourceLocation::new(&p.common.dimension_type.to_string()); + + let dimension = dimension_type_element + .map + .get(&dimension_type) + .unwrap_or_else(|| panic!("No dimension_type with name {dimension_type}")); // add this world to the instance_container (or don't if it's already // there) @@ -1288,9 +1288,6 @@ pub fn process_packet_events(ecs: &mut World) { packet: ServerboundPongPacket { id: p.id }.get(), }); } - ClientboundGamePacket::PongResponse(p) => { - debug!("Got pong response packet {p:?}"); - } ClientboundGamePacket::PlaceGhostRecipe(_) => {} ClientboundGamePacket::PlayerCombatEnd(_) => {} ClientboundGamePacket::PlayerCombatEnter(_) => {} @@ -1359,21 +1356,20 @@ pub fn process_packet_events(ecs: &mut World) { { let new_instance_name = p.common.dimension.clone(); - let Some(dimension_type) = + 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"); continue; }; - let dimension = &dimension_type - .value - .iter() - .find(|t| t.name == p.common.dimension_type) - .unwrap_or_else(|| { - panic!("No dimension_type with name {}", p.common.dimension_type) - }) - .element; + let dimension_type = + ResourceLocation::new(&p.common.dimension_type.to_string()); + + let dimension = dimension_type_element + .map + .get(&dimension_type) + .unwrap_or_else(|| panic!("No dimension_type with name {dimension_type}")); // add this world to the instance_container (or don't if it's already // there) @@ -1475,6 +1471,11 @@ pub fn process_packet_events(ecs: &mut World) { ClientboundGamePacket::TickingStep(_) => {} ClientboundGamePacket::ResetScore(_) => {} + ClientboundGamePacket::CookieRequest(_) => {} + ClientboundGamePacket::DebugSample(_) => {} + ClientboundGamePacket::PongResponse(_) => {} + ClientboundGamePacket::StoreCookie(_) => {} + ClientboundGamePacket::Transfer(_) => {} } } } |
