diff options
| author | mat <git@matdoes.dev> | 2024-12-19 02:31:08 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-12-19 02:52:41 +0000 |
| commit | e268c4929177e540baa9d2bb29bc171f49cc7a25 (patch) | |
| tree | 10146e529088ab823452a5971c0a37a8886b2a68 /azalea-client/src | |
| parent | 1f06a1540f46d8087907566d7c6c1ab397c517ec (diff) | |
| download | azalea-drasl-e268c4929177e540baa9d2bb29bc171f49cc7a25.tar.xz | |
fix incorrect packets
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/inventory.rs | 12 | ||||
| -rw-r--r-- | azalea-client/src/local_player.rs | 1 | ||||
| -rw-r--r-- | azalea-client/src/movement.rs | 10 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/game.rs | 84 |
4 files changed, 49 insertions, 58 deletions
diff --git a/azalea-client/src/inventory.rs b/azalea-client/src/inventory.rs index eb0b0675..2dd17853 100644 --- a/azalea-client/src/inventory.rs +++ b/azalea-client/src/inventory.rs @@ -85,7 +85,7 @@ pub struct Inventory { /// guaranteed to be anything specific, and may change every time you open a /// container (unless it's 0, in which case it means that no container is /// open). - pub id: u8, + pub id: i32, /// The current container menu that the player has open. If no container is /// open, this will be `None`. pub container_menu: Option<azalea_inventory::Menu>, @@ -584,7 +584,7 @@ impl Default for Inventory { #[derive(Event, Debug)] pub struct MenuOpenedEvent { pub entity: Entity, - pub window_id: u32, + pub window_id: i32, pub menu_type: MenuKind, pub title: FormattedText, } @@ -594,7 +594,7 @@ fn handle_menu_opened_event( ) { for event in events.read() { let mut inventory = query.get_mut(event.entity).unwrap(); - inventory.id = event.window_id as u8; + inventory.id = event.window_id; inventory.container_menu = Some(Menu::from_kind(event.menu_type)); inventory.container_menu_title = Some(event.title.clone()); } @@ -609,7 +609,7 @@ pub struct CloseContainerEvent { pub entity: Entity, /// The ID of the container to close. 0 for the player's inventory. If this /// is not the same as the currently open inventory, nothing will happen. - pub id: u8, + pub id: i32, } fn handle_container_close_event( query: Query<(Entity, &Inventory)>, @@ -661,7 +661,7 @@ pub fn handle_client_side_close_container_event( #[derive(Event, Debug)] pub struct ContainerClickEvent { pub entity: Entity, - pub window_id: u8, + pub window_id: i32, pub operation: ClickOperation, } pub fn handle_container_click_event( @@ -715,7 +715,7 @@ pub fn handle_container_click_event( pub struct SetContainerContentEvent { pub entity: Entity, pub slots: Vec<ItemStack>, - pub container_id: u8, + pub container_id: i32, } fn handle_set_container_content_event( mut events: EventReader<SetContainerContentEvent>, diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs index c01dcef6..0a8f006d 100644 --- a/azalea-client/src/local_player.rs +++ b/azalea-client/src/local_player.rs @@ -138,7 +138,6 @@ pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) { } #[derive(Error, Debug)] -#[expect(clippy::large_enum_variant)] pub enum HandlePacketError { #[error("{0}")] Poison(String), diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs index bdc29f2f..8801e2c6 100644 --- a/azalea-client/src/movement.rs +++ b/azalea-client/src/movement.rs @@ -193,8 +193,7 @@ pub fn send_position( Some( ServerboundMovePlayerPosRot { pos: **position, - x_rot: direction.x_rot, - y_rot: direction.y_rot, + look_direction: *direction, on_ground: physics.on_ground(), } .into_variant(), @@ -202,9 +201,7 @@ pub fn send_position( } else if sending_position { Some( ServerboundMovePlayerPos { - x: position.x, - y: position.y, - z: position.z, + pos: **position, on_ground: physics.on_ground(), } .into_variant(), @@ -212,8 +209,7 @@ pub fn send_position( } else if sending_direction { Some( ServerboundMovePlayerRot { - x_rot: direction.x_rot, - y_rot: direction.y_rot, + look_direction: *direction, on_ground: physics.on_ground(), } .into_variant(), diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 0c505d07..d92f2464 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -510,8 +510,7 @@ pub fn process_packet_events(ecs: &mut World) { player_entity, ServerboundMovePlayerPosRot { pos: new_pos, - y_rot: new_y_rot, - x_rot: new_x_rot, + look_direction: LookDirection::new(new_y_rot, new_x_rot), // this is always false on_ground: false, }, @@ -842,10 +841,10 @@ pub fn process_packet_events(ecs: &mut World) { continue; }; - let new_pos = p.position; + let new_pos = p.change.pos; let new_look_direction = LookDirection { - x_rot: (p.x_rot as i32 * 360) as f32 / 256., - y_rot: (p.y_rot as i32 * 360) as f32 / 256., + x_rot: (p.change.look_direction.x_rot as i32 * 360) as f32 / 256., + y_rot: (p.change.look_direction.y_rot as i32 * 360) as f32 / 256., }; commands.entity(entity).queue(RelativeEntityUpdate { partial_world: instance_holder.partial_instance.clone(), @@ -879,35 +878,34 @@ pub fn process_packet_events(ecs: &mut World) { debug!("Got move entity pos packet {p:?}"); - let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); - - if let Some(entity) = entity { - let new_delta = p.delta.clone(); - let new_on_ground = p.on_ground; - commands.entity(entity).queue(RelativeEntityUpdate { - partial_world: instance_holder.partial_instance.clone(), - update: Box::new(move |entity_mut| { - let mut physics = entity_mut.get_mut::<Physics>().unwrap(); - let new_pos = physics.vec_delta_codec.decode( - new_delta.xa as i64, - new_delta.ya as i64, - new_delta.za as i64, - ); - physics.vec_delta_codec.set_base(new_pos); - physics.set_on_ground(new_on_ground); - - let mut position = entity_mut.get_mut::<Position>().unwrap(); - if new_pos != **position { - **position = new_pos; - } - }), - }); - } else { + let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.entity_id)) else { warn!( "Got move entity pos packet for unknown entity id {}", p.entity_id ); - } + continue; + }; + + let new_delta = p.delta.clone(); + let new_on_ground = p.on_ground; + commands.entity(entity).queue(RelativeEntityUpdate { + partial_world: instance_holder.partial_instance.clone(), + update: Box::new(move |entity_mut| { + let mut physics = entity_mut.get_mut::<Physics>().unwrap(); + let new_pos = physics.vec_delta_codec.decode( + new_delta.xa as i64, + new_delta.ya as i64, + new_delta.za as i64, + ); + physics.vec_delta_codec.set_base(new_pos); + physics.set_on_ground(new_on_ground); + + let mut position = entity_mut.get_mut::<Position>().unwrap(); + if new_pos != **position { + **position = new_pos; + } + }), + }); system_state.apply(ecs); } @@ -1191,7 +1189,7 @@ pub fn process_packet_events(ecs: &mut World) { events.send(SetContainerContentEvent { entity: player_entity, slots: p.items.clone(), - container_id: p.container_id as u8, + container_id: p.container_id, }); } } @@ -1235,7 +1233,7 @@ pub fn process_packet_events(ecs: &mut World) { if let Some(slot) = inventory.inventory_menu.slot_mut(p.slot.into()) { *slot = p.item_stack.clone(); } - } else if p.container_id == (inventory.id as i8) + } else if p.container_id == inventory.id && (p.container_id != 0 || !is_creative_mode_and_inventory_closed) { // var2.containerMenu.setItem(var4, var1.getStateId(), var3); @@ -1260,20 +1258,18 @@ pub fn process_packet_events(ecs: &mut World) { ClientboundGamePacket::DeleteChat(_) => {} ClientboundGamePacket::Explode(p) => { trace!("Got explode packet {p:?}"); - let mut system_state: SystemState<EventWriter<KnockbackEvent>> = - SystemState::new(ecs); - let mut knockback_events = system_state.get_mut(ecs); + if let Some(knockback) = p.knockback { + let mut system_state: SystemState<EventWriter<KnockbackEvent>> = + SystemState::new(ecs); + let mut knockback_events = system_state.get_mut(ecs); - knockback_events.send(KnockbackEvent { - entity: player_entity, - knockback: KnockbackType::Set(Vec3 { - x: p.knockback_x as f64, - y: p.knockback_y as f64, - z: p.knockback_z as f64, - }), - }); + knockback_events.send(KnockbackEvent { + entity: player_entity, + knockback: KnockbackType::Set(knockback), + }); - system_state.apply(ecs); + system_state.apply(ecs); + } } ClientboundGamePacket::ForgetLevelChunk(p) => { debug!("Got forget level chunk packet {p:?}"); |
