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

fix incorrect packets

This commit is contained in:
mat 2024-12-19 02:31:08 +00:00
parent 1f06a1540f
commit e268c49291
46 changed files with 543 additions and 691 deletions

View file

@ -85,7 +85,7 @@ pub struct Inventory {
/// guaranteed to be anything specific, and may change every time you open a /// 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 /// container (unless it's 0, in which case it means that no container is
/// open). /// open).
pub id: u8, pub id: i32,
/// The current container menu that the player has open. If no container is /// The current container menu that the player has open. If no container is
/// open, this will be `None`. /// open, this will be `None`.
pub container_menu: Option<azalea_inventory::Menu>, pub container_menu: Option<azalea_inventory::Menu>,
@ -584,7 +584,7 @@ impl Default for Inventory {
#[derive(Event, Debug)] #[derive(Event, Debug)]
pub struct MenuOpenedEvent { pub struct MenuOpenedEvent {
pub entity: Entity, pub entity: Entity,
pub window_id: u32, pub window_id: i32,
pub menu_type: MenuKind, pub menu_type: MenuKind,
pub title: FormattedText, pub title: FormattedText,
} }
@ -594,7 +594,7 @@ fn handle_menu_opened_event(
) { ) {
for event in events.read() { for event in events.read() {
let mut inventory = query.get_mut(event.entity).unwrap(); 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 = Some(Menu::from_kind(event.menu_type));
inventory.container_menu_title = Some(event.title.clone()); inventory.container_menu_title = Some(event.title.clone());
} }
@ -609,7 +609,7 @@ pub struct CloseContainerEvent {
pub entity: Entity, pub entity: Entity,
/// The ID of the container to close. 0 for the player's inventory. If this /// 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. /// is not the same as the currently open inventory, nothing will happen.
pub id: u8, pub id: i32,
} }
fn handle_container_close_event( fn handle_container_close_event(
query: Query<(Entity, &Inventory)>, query: Query<(Entity, &Inventory)>,
@ -661,7 +661,7 @@ pub fn handle_client_side_close_container_event(
#[derive(Event, Debug)] #[derive(Event, Debug)]
pub struct ContainerClickEvent { pub struct ContainerClickEvent {
pub entity: Entity, pub entity: Entity,
pub window_id: u8, pub window_id: i32,
pub operation: ClickOperation, pub operation: ClickOperation,
} }
pub fn handle_container_click_event( pub fn handle_container_click_event(
@ -715,7 +715,7 @@ pub fn handle_container_click_event(
pub struct SetContainerContentEvent { pub struct SetContainerContentEvent {
pub entity: Entity, pub entity: Entity,
pub slots: Vec<ItemStack>, pub slots: Vec<ItemStack>,
pub container_id: u8, pub container_id: i32,
} }
fn handle_set_container_content_event( fn handle_set_container_content_event(
mut events: EventReader<SetContainerContentEvent>, mut events: EventReader<SetContainerContentEvent>,

View file

@ -138,7 +138,6 @@ pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) {
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
#[expect(clippy::large_enum_variant)]
pub enum HandlePacketError { pub enum HandlePacketError {
#[error("{0}")] #[error("{0}")]
Poison(String), Poison(String),

View file

@ -193,8 +193,7 @@ pub fn send_position(
Some( Some(
ServerboundMovePlayerPosRot { ServerboundMovePlayerPosRot {
pos: **position, pos: **position,
x_rot: direction.x_rot, look_direction: *direction,
y_rot: direction.y_rot,
on_ground: physics.on_ground(), on_ground: physics.on_ground(),
} }
.into_variant(), .into_variant(),
@ -202,9 +201,7 @@ pub fn send_position(
} else if sending_position { } else if sending_position {
Some( Some(
ServerboundMovePlayerPos { ServerboundMovePlayerPos {
x: position.x, pos: **position,
y: position.y,
z: position.z,
on_ground: physics.on_ground(), on_ground: physics.on_ground(),
} }
.into_variant(), .into_variant(),
@ -212,8 +209,7 @@ pub fn send_position(
} else if sending_direction { } else if sending_direction {
Some( Some(
ServerboundMovePlayerRot { ServerboundMovePlayerRot {
x_rot: direction.x_rot, look_direction: *direction,
y_rot: direction.y_rot,
on_ground: physics.on_ground(), on_ground: physics.on_ground(),
} }
.into_variant(), .into_variant(),

View file

@ -510,8 +510,7 @@ pub fn process_packet_events(ecs: &mut World) {
player_entity, player_entity,
ServerboundMovePlayerPosRot { ServerboundMovePlayerPosRot {
pos: new_pos, pos: new_pos,
y_rot: new_y_rot, look_direction: LookDirection::new(new_y_rot, new_x_rot),
x_rot: new_x_rot,
// this is always false // this is always false
on_ground: false, on_ground: false,
}, },
@ -842,10 +841,10 @@ pub fn process_packet_events(ecs: &mut World) {
continue; continue;
}; };
let new_pos = p.position; let new_pos = p.change.pos;
let new_look_direction = LookDirection { let new_look_direction = LookDirection {
x_rot: (p.x_rot as i32 * 360) as f32 / 256., x_rot: (p.change.look_direction.x_rot as i32 * 360) as f32 / 256.,
y_rot: (p.y_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 { commands.entity(entity).queue(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(), partial_world: instance_holder.partial_instance.clone(),
@ -879,9 +878,14 @@ pub fn process_packet_events(ecs: &mut World) {
debug!("Got move entity pos packet {p:?}"); debug!("Got move entity pos packet {p:?}");
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); 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;
};
if let Some(entity) = entity {
let new_delta = p.delta.clone(); let new_delta = p.delta.clone();
let new_on_ground = p.on_ground; let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate { commands.entity(entity).queue(RelativeEntityUpdate {
@ -902,12 +906,6 @@ pub fn process_packet_events(ecs: &mut World) {
} }
}), }),
}); });
} else {
warn!(
"Got move entity pos packet for unknown entity id {}",
p.entity_id
);
}
system_state.apply(ecs); system_state.apply(ecs);
} }
@ -1191,7 +1189,7 @@ pub fn process_packet_events(ecs: &mut World) {
events.send(SetContainerContentEvent { events.send(SetContainerContentEvent {
entity: player_entity, entity: player_entity,
slots: p.items.clone(), 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()) { if let Some(slot) = inventory.inventory_menu.slot_mut(p.slot.into()) {
*slot = p.item_stack.clone(); *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) && (p.container_id != 0 || !is_creative_mode_and_inventory_closed)
{ {
// var2.containerMenu.setItem(var4, var1.getStateId(), var3); // var2.containerMenu.setItem(var4, var1.getStateId(), var3);
@ -1260,21 +1258,19 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::DeleteChat(_) => {} ClientboundGamePacket::DeleteChat(_) => {}
ClientboundGamePacket::Explode(p) => { ClientboundGamePacket::Explode(p) => {
trace!("Got explode packet {p:?}"); trace!("Got explode packet {p:?}");
if let Some(knockback) = p.knockback {
let mut system_state: SystemState<EventWriter<KnockbackEvent>> = let mut system_state: SystemState<EventWriter<KnockbackEvent>> =
SystemState::new(ecs); SystemState::new(ecs);
let mut knockback_events = system_state.get_mut(ecs); let mut knockback_events = system_state.get_mut(ecs);
knockback_events.send(KnockbackEvent { knockback_events.send(KnockbackEvent {
entity: player_entity, entity: player_entity,
knockback: KnockbackType::Set(Vec3 { knockback: KnockbackType::Set(knockback),
x: p.knockback_x as f64,
y: p.knockback_y as f64,
z: p.knockback_z as f64,
}),
}); });
system_state.apply(ecs); system_state.apply(ecs);
} }
}
ClientboundGamePacket::ForgetLevelChunk(p) => { ClientboundGamePacket::ForgetLevelChunk(p) => {
debug!("Got forget level chunk packet {p:?}"); debug!("Got forget level chunk packet {p:?}");

View file

@ -1,4 +1,6 @@
//! Some serializable data types that are used by several packets. //! Some serializable data types that are used by several packets.
pub mod client_information; pub mod client_information;
pub mod movements;
pub mod recipe;
pub mod server_links; pub mod server_links;

View file

@ -0,0 +1,71 @@
use std::io::{self, Cursor, Write};
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
use azalea_core::{bitset::FixedBitSet, position::Vec3};
use azalea_entity::LookDirection;
/// The updated position, velocity, and rotations for an entity.
///
/// Often, this field comes alongside a [`RelativeMovements`] field, which
/// specifies which parts of this struct should be treated as relative.
#[derive(AzBuf, Clone, Debug)]
pub struct PositionMoveRotation {
pub pos: Vec3,
/// The updated delta movement (velocity).
pub delta: Vec3,
pub look_direction: LookDirection,
}
#[derive(Debug, Clone)]
pub struct RelativeMovements {
pub x: bool,
pub y: bool,
pub z: bool,
pub y_rot: bool,
pub x_rot: bool,
pub delta_x: bool,
pub delta_y: bool,
pub delta_z: bool,
pub rotate_delta: bool,
}
impl AzaleaRead for RelativeMovements {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
// yes minecraft seriously wastes that many bits, smh
let set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::azalea_read(buf)?;
Ok(RelativeMovements {
x: set.index(0),
y: set.index(1),
z: set.index(2),
y_rot: set.index(3),
x_rot: set.index(4),
delta_x: set.index(5),
delta_y: set.index(6),
delta_z: set.index(7),
rotate_delta: set.index(8),
})
}
}
impl AzaleaWrite for RelativeMovements {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
let mut set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::new();
let mut set_bit = |index: usize, value: bool| {
if value {
set.set(index);
}
};
set_bit(0, self.x);
set_bit(1, self.y);
set_bit(2, self.z);
set_bit(3, self.y_rot);
set_bit(4, self.x_rot);
set_bit(5, self.delta_x);
set_bit(6, self.delta_y);
set_bit(7, self.delta_z);
set_bit(8, self.rotate_delta);
set.azalea_write(buf)
}
}

View file

@ -0,0 +1,101 @@
use azalea_buf::AzBuf;
use azalea_core::resource_location::ResourceLocation;
use azalea_inventory::ItemStack;
use azalea_registry::HolderSet;
/// [`azalea_registry::RecipeDisplay`]
#[derive(Clone, Debug, AzBuf)]
pub enum RecipeDisplayData {
Shapeless(ShapelessCraftingRecipeDisplay),
Shaped(ShapedCraftingRecipeDisplay),
Furnace(FurnaceRecipeDisplay),
Stonecutter(StonecutterRecipeDisplay),
Smithing(SmithingRecipeDisplay),
}
#[derive(Clone, Debug, AzBuf)]
pub struct ShapelessCraftingRecipeDisplay {
pub ingredients: Vec<SlotDisplayData>,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct ShapedCraftingRecipeDisplay {
#[var]
pub width: u32,
#[var]
pub height: u32,
pub ingredients: Vec<SlotDisplayData>,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct FurnaceRecipeDisplay {
pub ingredient: SlotDisplayData,
pub fuel: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
#[var]
pub duration: u32,
pub experience: f32,
}
#[derive(Clone, Debug, AzBuf)]
pub struct StonecutterRecipeDisplay {
pub input: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct SmithingRecipeDisplay {
pub template: SlotDisplayData,
pub base: SlotDisplayData,
pub addition: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct Ingredient {
pub allowed: HolderSet<azalea_registry::Item, ResourceLocation>,
}
/// [`azalea_registry::SlotDisplay`]
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub enum SlotDisplayData {
Empty,
AnyFuel,
Item(ItemStackDisplay),
ItemStack(ItemStackSlotDisplay),
Tag(ResourceLocation),
SmithingTrim(Box<SmithingTrimDemoSlotDisplay>),
WithRemainder(Box<WithRemainderSlotDisplay>),
Composite(CompositeSlotDisplay),
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ItemStackDisplay {
pub item: azalea_registry::Item,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ItemStackSlotDisplay {
pub stack: ItemStack,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct TagSlotDisplay {
pub tag: azalea_registry::Item,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct SmithingTrimDemoSlotDisplay {
pub base: SlotDisplayData,
pub material: SlotDisplayData,
pub pattern: SlotDisplayData,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct WithRemainderSlotDisplay {
pub input: SlotDisplayData,
pub remainder: SlotDisplayData,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct CompositeSlotDisplay {
pub contents: Vec<SlotDisplayData>,
}

View file

@ -5,32 +5,32 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(ConfigPacket, declare_state_packets!(ConfigPacket,
Clientbound => [ Clientbound => [
cookie_request, cookie_request, // 0x00
custom_payload, custom_payload, // 0x01
disconnect, disconnect, // 0x02
finish_configuration, finish_configuration, // 0x03
keep_alive, keep_alive, // 0x04
ping, ping, // 0x05
reset_chat, reset_chat, // 0x06
registry_data, registry_data, // 0x07
resource_pack_pop, resource_pack_pop, // 0x08
resource_pack_push, resource_pack_push, // 0x09
store_cookie, store_cookie, // 0x0A
transfer, transfer, // 0x0B
update_enabled_features, update_enabled_features, // 0x0C
update_tags, update_tags, // 0x0D
select_known_packs, select_known_packs, // 0x0E
custom_report_details, custom_report_details, // 0x0F
server_links, server_links, // 0x10
], ],
Serverbound => [ Serverbound => [
client_information, client_information, // 0x00
cookie_response, cookie_response, // 0x01
custom_payload, custom_payload, // 0x02
finish_configuration, finish_configuration, // 0x03
keep_alive, keep_alive, // 0x04
pong, pong, // 0x05
resource_pack, resource_pack, // 0x06
select_known_packs, select_known_packs, // 0x07
] ]
); );

View file

@ -1,12 +1,11 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundAddExperienceOrb { pub struct ClientboundAddExperienceOrb {
#[var] #[var]
pub id: u32, pub id: u32,
pub x: f64, pub pos: Vec3,
pub y: f64,
pub z: f64,
pub value: u16, pub value: u16,
} }

View file

@ -3,5 +3,6 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundContainerClose { pub struct ClientboundContainerClose {
pub container_id: u8, #[var]
pub container_id: i32,
} }

View file

@ -4,7 +4,8 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetContent { pub struct ClientboundContainerSetContent {
pub container_id: i8, #[var]
pub container_id: i32,
#[var] #[var]
pub state_id: u32, pub state_id: u32,
pub items: Vec<ItemStack>, pub items: Vec<ItemStack>,

View file

@ -3,7 +3,8 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetData { pub struct ClientboundContainerSetData {
pub container_id: i8, #[var]
pub container_id: i32,
pub id: u16, pub id: u16,
pub value: u16, pub value: u16,
} }

View file

@ -4,7 +4,8 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetSlot { pub struct ClientboundContainerSetSlot {
pub container_id: i8, #[var]
pub container_id: i32,
#[var] #[var]
pub state_id: u32, pub state_id: u32,
pub slot: u16, pub slot: u16,

View file

@ -1,7 +1,7 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use super::c_player_position::PositionMoveRotation; use crate::common::movements::PositionMoveRotation;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundEntityPositionSync { pub struct ClientboundEntityPositionSync {

View file

@ -1,164 +1,13 @@
use std::{ use azalea_buf::AzBuf;
io::{Cursor, Write}, use azalea_core::position::Vec3;
str::FromStr, use azalea_entity::particle::Particle;
};
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
use azalea_core::{position::BlockPos, resource_location::ResourceLocation};
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::{ParticleKind, SoundEvent}; use azalea_registry::SoundEvent;
#[derive(Clone, Debug, PartialEq, ClientboundGamePacket)] #[derive(Clone, Debug, ClientboundGamePacket, AzBuf)]
pub struct ClientboundExplode { pub struct ClientboundExplode {
pub x: f64, pub center: Vec3,
pub y: f64, pub knockback: Option<Vec3>,
pub z: f64, pub explosion_particle: Particle,
pub power: f32,
pub to_blow: Vec<BlockPos>,
pub knockback_x: f32,
pub knockback_y: f32,
pub knockback_z: f32,
pub block_interaction: BlockInteraction,
pub small_explosion_particles: ParticleKind,
pub large_explosion_particles: ParticleKind,
pub explosion_sound: SoundEvent, pub explosion_sound: SoundEvent,
} }
#[derive(Clone, Copy, Debug, PartialEq, AzBuf)]
pub enum BlockInteraction {
Keep,
Destroy,
DestroyWithDecay,
TriggerBlock,
}
impl AzaleaRead for ClientboundExplode {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let x = f64::azalea_read(buf)?;
let y = f64::azalea_read(buf)?;
let z = f64::azalea_read(buf)?;
let power = f32::azalea_read(buf)?;
let x_floor = x.floor() as i32;
let y_floor = y.floor() as i32;
let z_floor = z.floor() as i32;
let to_blow_len = u32::azalea_read_var(buf)?;
let mut to_blow = Vec::with_capacity(to_blow_len as usize);
for _ in 0..to_blow_len {
// the bytes are offsets from the main x y z
let x = x_floor + i32::from(i8::azalea_read(buf)?);
let y = y_floor + i32::from(i8::azalea_read(buf)?);
let z = z_floor + i32::from(i8::azalea_read(buf)?);
to_blow.push(BlockPos { x, y, z });
}
let knockback_x = f32::azalea_read(buf)?;
let knockback_y = f32::azalea_read(buf)?;
let knockback_z = f32::azalea_read(buf)?;
let block_interaction = BlockInteraction::azalea_read(buf)?;
let small_explosion_particles = ParticleKind::azalea_read(buf)?;
let large_explosion_particles = ParticleKind::azalea_read(buf)?;
let sound_event_resource_location = ResourceLocation::azalea_read(buf)?.to_string();
let explosion_sound =
SoundEvent::from_str(&sound_event_resource_location).map_err(|_| {
BufReadError::UnexpectedStringEnumVariant {
id: sound_event_resource_location,
}
})?;
Ok(Self {
x,
y,
z,
power,
to_blow,
knockback_x,
knockback_y,
knockback_z,
block_interaction,
small_explosion_particles,
large_explosion_particles,
explosion_sound,
})
}
}
impl AzaleaWrite for ClientboundExplode {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
self.x.azalea_write(buf)?;
self.y.azalea_write(buf)?;
self.z.azalea_write(buf)?;
self.power.azalea_write(buf)?;
let to_blow_len = self.to_blow.len() as u32;
to_blow_len.azalea_write_var(buf)?;
let x_floor = self.x.floor() as i32;
let y_floor = self.y.floor() as i32;
let z_floor = self.z.floor() as i32;
for pos in &self.to_blow {
let x = (pos.x - x_floor) as i8;
let y = (pos.y - y_floor) as i8;
let z = (pos.z - z_floor) as i8;
x.azalea_write(buf)?;
y.azalea_write(buf)?;
z.azalea_write(buf)?;
}
self.knockback_x.azalea_write(buf)?;
self.knockback_y.azalea_write(buf)?;
self.knockback_z.azalea_write(buf)?;
self.block_interaction.azalea_write(buf)?;
self.small_explosion_particles.azalea_write(buf)?;
self.large_explosion_particles.azalea_write(buf)?;
let sound_event_resource_location =
ResourceLocation::new(&self.explosion_sound.to_string());
sound_event_resource_location.azalea_write(buf)?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_read_write() {
let packet = ClientboundExplode {
x: 123_456.0,
y: 789_012.0,
z: 345_678.0,
power: 1_000.0,
to_blow: vec![
BlockPos {
x: 123_456 + 1,
y: 789_012 + 2,
z: 345_678 - 127,
},
BlockPos {
x: 123_456 + 4,
y: 789_012 - 5,
z: 345_678 + 6,
},
],
knockback_x: 1_000.0,
knockback_y: 2_000.0,
knockback_z: 3_000.0,
block_interaction: BlockInteraction::Destroy,
small_explosion_particles: ParticleKind::Explosion,
large_explosion_particles: ParticleKind::ExplosionEmitter,
explosion_sound: SoundEvent::EntityGenericExplode,
};
let mut buf = Vec::new();
packet.azalea_write(&mut buf).unwrap();
let packet2 = ClientboundExplode::azalea_read(&mut Cursor::new(&buf)).unwrap();
assert_eq!(packet, packet2);
}
}

View file

@ -3,8 +3,9 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundHorseScreenOpen { pub struct ClientboundHorseScreenOpen {
pub container_id: u8,
#[var] #[var]
pub size: u32, pub container_id: i32,
#[var]
pub inventory_columns: u32,
pub entity_id: u32, pub entity_id: u32,
} }

View file

@ -1,4 +1,5 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_entity::particle::Particle; use azalea_entity::particle::Particle;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
@ -6,9 +7,7 @@ use azalea_protocol_macros::ClientboundGamePacket;
pub struct ClientboundLevelParticles { pub struct ClientboundLevelParticles {
pub override_limiter: bool, pub override_limiter: bool,
pub always_show: bool, pub always_show: bool,
pub x: f64, pub pos: Vec3,
pub y: f64,
pub z: f64,
pub x_dist: f32, pub x_dist: f32,
pub y_dist: f32, pub y_dist: f32,
pub z_dist: f32, pub z_dist: f32,

View file

@ -5,7 +5,7 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundMerchantOffers { pub struct ClientboundMerchantOffers {
#[var] #[var]
pub container_id: u32, pub container_id: i32,
pub offers: Vec<MerchantOffer>, pub offers: Vec<MerchantOffer>,
#[var] #[var]
pub villager_level: u32, pub villager_level: u32,

View file

@ -1,11 +1,10 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_entity::LookDirection;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundMoveVehicle { pub struct ClientboundMoveVehicle {
pub x: f64, pub pos: Vec3,
pub y: f64, pub look_direction: LookDirection,
pub z: f64,
pub y_rot: f32,
pub x_rot: f32,
} }

View file

@ -5,7 +5,7 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundOpenScreen { pub struct ClientboundOpenScreen {
#[var] #[var]
pub container_id: u32, pub container_id: i32,
pub menu_type: azalea_registry::MenuKind, pub menu_type: azalea_registry::MenuKind,
pub title: FormattedText, pub title: FormattedText,
} }

View file

@ -1,9 +1,11 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::resource_location::ResourceLocation;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use crate::common::recipe::RecipeDisplayData;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundPlaceGhostRecipe { pub struct ClientboundPlaceGhostRecipe {
pub container_id: u8, #[var]
pub recipe: ResourceLocation, pub container_id: i32,
pub recipe: RecipeDisplayData,
} }

View file

@ -1,12 +1,11 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundPlayerLookAt { pub struct ClientboundPlayerLookAt {
pub from_anchor: Anchor, pub from_anchor: Anchor,
pub x: f64, pub pos: Vec3,
pub y: f64,
pub z: f64,
pub entity: Option<AtEntity>, pub entity: Option<AtEntity>,
} }

View file

@ -1,10 +1,8 @@
use std::io::{Cursor, Write}; use azalea_buf::AzBuf;
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
use azalea_core::{bitset::FixedBitSet, position::Vec3};
use azalea_entity::LookDirection;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use crate::common::movements::{PositionMoveRotation, RelativeMovements};
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundPlayerPosition { pub struct ClientboundPlayerPosition {
#[var] #[var]
@ -12,71 +10,3 @@ pub struct ClientboundPlayerPosition {
pub change: PositionMoveRotation, pub change: PositionMoveRotation,
pub relative: RelativeMovements, pub relative: RelativeMovements,
} }
/// These values are either absolute or relative, depending on the fields from
/// the [`RelativeMovements`].
#[derive(Clone, Debug, AzBuf)]
pub struct PositionMoveRotation {
pub pos: Vec3,
/// The updated delta movement (velocity).
///
/// This is unused when included in a [`ClientboundEntityPositionSync`].
///
/// [`ClientboundEntityPositionSync`]: super::c_entity_position_sync::ClientboundEntityPositionSync
pub delta: Vec3,
pub look_direction: LookDirection,
}
#[derive(Debug, Clone)]
pub struct RelativeMovements {
pub x: bool,
pub y: bool,
pub z: bool,
pub y_rot: bool,
pub x_rot: bool,
pub delta_x: bool,
pub delta_y: bool,
pub delta_z: bool,
pub rotate_delta: bool,
}
impl AzaleaRead for RelativeMovements {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
// yes minecraft seriously wastes that many bits, smh
let set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::azalea_read(buf)?;
Ok(RelativeMovements {
x: set.index(0),
y: set.index(1),
z: set.index(2),
y_rot: set.index(3),
x_rot: set.index(4),
delta_x: set.index(5),
delta_y: set.index(6),
delta_z: set.index(7),
rotate_delta: set.index(8),
})
}
}
impl AzaleaWrite for RelativeMovements {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::new();
let mut set_bit = |index: usize, value: bool| {
if value {
set.set(index);
}
};
set_bit(0, self.x);
set_bit(1, self.y);
set_bit(2, self.z);
set_bit(3, self.y_rot);
set_bit(4, self.x_rot);
set_bit(5, self.delta_x);
set_bit(6, self.delta_y);
set_bit(7, self.delta_z);
set_bit(8, self.rotate_delta);
set.azalea_write(buf)
}
}

View file

@ -1,8 +1,8 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_entity::LookDirection;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundPlayerRotation { pub struct ClientboundPlayerRotation {
pub y_rot: f32, pub look_direction: LookDirection,
pub x_rot: f32,
} }

View file

@ -1,7 +1,7 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use super::c_update_recipes::{Ingredient, SlotDisplayData}; use crate::common::recipe::{Ingredient, RecipeDisplayData};
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundRecipeBookAdd { pub struct ClientboundRecipeBookAdd {
@ -20,60 +20,9 @@ pub struct RecipeDisplayEntry {
#[var] #[var]
pub id: u32, pub id: u32,
pub display: RecipeDisplayData, pub display: RecipeDisplayData,
// ByteBufCodecs.OPTIONAL_VAR_INT // optional varint
#[var] #[var]
pub group: u32, pub group: u32,
pub category: azalea_registry::RecipeBookCategory, pub category: azalea_registry::RecipeBookCategory,
pub crafting_requirements: Option<Vec<Ingredient>>, pub crafting_requirements: Option<Vec<Ingredient>>,
} }
/// [`azalea_registry::RecipeDisplay`]
#[derive(Clone, Debug, AzBuf)]
pub enum RecipeDisplayData {
Shapeless(ShapelessCraftingRecipeDisplay),
Shaped(ShapedCraftingRecipeDisplay),
Furnace(FurnaceRecipeDisplay),
Stonecutter(StonecutterRecipeDisplay),
Smithing(SmithingRecipeDisplay),
}
#[derive(Clone, Debug, AzBuf)]
pub struct ShapelessCraftingRecipeDisplay {
pub ingredients: Vec<SlotDisplayData>,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct ShapedCraftingRecipeDisplay {
#[var]
pub width: u32,
#[var]
pub height: u32,
pub ingredients: Vec<SlotDisplayData>,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct FurnaceRecipeDisplay {
pub ingredient: SlotDisplayData,
pub fuel: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
#[var]
pub duration: u32,
pub experience: f32,
}
#[derive(Clone, Debug, AzBuf)]
pub struct StonecutterRecipeDisplay {
pub input: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}
#[derive(Clone, Debug, AzBuf)]
pub struct SmithingRecipeDisplay {
pub template: SlotDisplayData,
pub base: SlotDisplayData,
pub addition: SlotDisplayData,
pub result: SlotDisplayData,
pub crafting_station: SlotDisplayData,
}

View file

@ -4,5 +4,5 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundSetCursorItem { pub struct ClientboundSetCursorItem {
pub contents: Option<ItemStack>, pub contents: ItemStack,
} }

View file

@ -3,5 +3,6 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundSetHeldSlot { pub struct ClientboundSetHeldSlot {
pub slot: u8, #[var]
pub slot: u32,
} }

View file

@ -5,6 +5,6 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundSetPlayerInventory { pub struct ClientboundSetPlayerInventory {
#[var] #[var]
pub slot: i32, pub slot: u32,
pub contents: Option<ItemStack>, pub contents: ItemStack,
} }

View file

@ -1,13 +1,14 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use crate::common::movements::{PositionMoveRotation, RelativeMovements};
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundTeleportEntity { pub struct ClientboundTeleportEntity {
#[var] #[var]
pub id: u32, pub id: u32,
pub position: Vec3, pub change: PositionMoveRotation,
pub y_rot: i8, pub relatives: RelativeMovements,
pub x_rot: i8,
pub on_ground: bool, pub on_ground: bool,
} }

View file

@ -2,9 +2,9 @@ use std::collections::HashMap;
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::resource_location::ResourceLocation; use azalea_core::resource_location::ResourceLocation;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::HolderSet;
use crate::common::recipe::{Ingredient, SlotDisplayData};
#[derive(Clone, Debug, PartialEq, AzBuf, ClientboundGamePacket)] #[derive(Clone, Debug, PartialEq, AzBuf, ClientboundGamePacket)]
pub struct ClientboundUpdateRecipes { pub struct ClientboundUpdateRecipes {
@ -22,53 +22,7 @@ pub struct SelectableRecipe {
pub option_display: SlotDisplayData, pub option_display: SlotDisplayData,
} }
/// [`azalea_registry::SlotDisplay`]
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub enum SlotDisplayData {
Empty,
AnyFuel,
Item(ItemStackDisplay),
ItemStack(ItemStackSlotDisplay),
Tag(ResourceLocation),
SmithingTrim(Box<SmithingTrimDemoSlotDisplay>),
WithRemainder(Box<WithRemainderSlotDisplay>),
Composite(CompositeSlotDisplay),
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ItemStackDisplay {
pub item: azalea_registry::Item,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ItemStackSlotDisplay {
pub stack: ItemStack,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct TagSlotDisplay {
pub tag: azalea_registry::Item,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct SmithingTrimDemoSlotDisplay {
pub base: SlotDisplayData,
pub material: SlotDisplayData,
pub pattern: SlotDisplayData,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct WithRemainderSlotDisplay {
pub input: SlotDisplayData,
pub remainder: SlotDisplayData,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct CompositeSlotDisplay {
pub contents: Vec<SlotDisplayData>,
}
#[derive(Clone, Debug, PartialEq, AzBuf)] #[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct RecipePropertySet { pub struct RecipePropertySet {
pub items: Vec<azalea_registry::Item>, pub items: Vec<azalea_registry::Item>,
} }
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct Ingredient {
pub allowed: HolderSet<azalea_registry::Item, ResourceLocation>,
}

View file

@ -5,200 +5,200 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(GamePacket, declare_state_packets!(GamePacket,
Clientbound => [ Clientbound => [
bundle_delimiter, bundle_delimiter, // 0x00
add_entity, add_entity, // 0x01
add_experience_orb, add_experience_orb, // 0x02
animate, animate, // 0x03
award_stats, award_stats, // 0x04
block_changed_ack, block_changed_ack, // 0x05
block_destruction, block_destruction, // 0x06
block_entity_data, block_entity_data, // 0x07
block_event, block_event, // 0x08
block_update, block_update, // 0x09
boss_event, boss_event, // 0x0A
change_difficulty, change_difficulty, // 0x0B
chunk_batch_finished, chunk_batch_finished, // 0x0C
chunk_batch_start, chunk_batch_start, // 0x0D
chunks_biomes, chunks_biomes, // 0x0E
clear_titles, clear_titles, // 0x0F
command_suggestions, command_suggestions, // 0x10
commands, commands, // 0x11
container_close, container_close, // 0x12
container_set_content, container_set_content, // 0x13
container_set_data, container_set_data, // 0x14
container_set_slot, container_set_slot, // 0x15
cookie_request, cookie_request, // 0x16
cooldown, cooldown, // 0x17
custom_chat_completions, custom_chat_completions, // 0x18
custom_payload, custom_payload, // 0x19
damage_event, damage_event, // 0x1A
debug_sample, debug_sample, // 0x1B
delete_chat, delete_chat, // 0x1C
disconnect, disconnect, // 0x1D
disguised_chat, disguised_chat, // 0x1E
entity_event, entity_event, // 0x1F
entity_position_sync, entity_position_sync, // 0x20
explode, explode, // 0x21
forget_level_chunk, forget_level_chunk, // 0x22
game_event, game_event, // 0x23
horse_screen_open, horse_screen_open, // 0x24
hurt_animation, hurt_animation, // 0x25
initialize_border, initialize_border, // 0x26
keep_alive, keep_alive, // 0x27
level_chunk_with_light, level_chunk_with_light, // 0x28
level_event, level_event, // 0x29
level_particles, level_particles, // 0x2A
light_update, light_update, // 0x2B
login, login, // 0x2C
map_item_data, map_item_data, // 0x2D
merchant_offers, merchant_offers, // 0x2E
move_entity_pos, move_entity_pos, // 0x2F
move_entity_pos_rot, move_entity_pos_rot, // 0x30
move_minecart_along_track, move_minecart_along_track, // 0x31
move_entity_rot, move_entity_rot, // 0x32
move_vehicle, move_vehicle, // 0x33
open_book, open_book, // 0x34
open_screen, open_screen, // 0x35
open_sign_editor, open_sign_editor, // 0x36
ping, ping, // 0x37
pong_response, pong_response, // 0x38
place_ghost_recipe, place_ghost_recipe, // 0x39
player_abilities, player_abilities, // 0x3A
player_chat, player_chat, // 0x3B
player_combat_end, player_combat_end, // 0x3C
player_combat_enter, player_combat_enter, // 0x3D
player_combat_kill, player_combat_kill, // 0x3E
player_info_remove, player_info_remove, // 0x3F
player_info_update, player_info_update, // 0x40
player_look_at, player_look_at, // 0x41
player_position, player_position, // 0x42
player_rotation, player_rotation, // 0x43
recipe_book_add, recipe_book_add, // 0x44
recipe_book_remove, recipe_book_remove, // 0x45
recipe_book_settings, recipe_book_settings, // 0x46
remove_entities, remove_entities, // 0x47
remove_mob_effect, remove_mob_effect, // 0x48
reset_score, reset_score, // 0x49
resource_pack_pop, resource_pack_pop, // 0x4A
resource_pack_push, resource_pack_push, // 0x4B
respawn, respawn, // 0x4C
rotate_head, rotate_head, // 0x4D
section_blocks_update, section_blocks_update, // 0x4E
select_advancements_tab, select_advancements_tab, // 0x4F
server_data, server_data, // 0x50
set_action_bar_text, set_action_bar_text, // 0x51
set_border_center, set_border_center, // 0x52
set_border_lerp_size, set_border_lerp_size, // 0x53
set_border_size, set_border_size, // 0x54
set_border_warning_delay, set_border_warning_delay, // 0x55
set_border_warning_distance, set_border_warning_distance, // 0x56
set_camera, set_camera, // 0x57
set_chunk_cache_center, set_chunk_cache_center, // 0x58
set_chunk_cache_radius, set_chunk_cache_radius, // 0x59
set_cursor_item, set_cursor_item, // 0x5A
set_default_spawn_position, set_default_spawn_position, // 0x5B
set_display_objective, set_display_objective, // 0x5C
set_entity_data, set_entity_data, // 0x5D
set_entity_link, set_entity_link, // 0x5E
set_entity_motion, set_entity_motion, // 0x5F
set_equipment, set_equipment, // 0x60
set_experience, set_experience, // 0x61
set_health, set_health, // 0x62
set_held_slot, set_held_slot, // 0x63
set_objective, set_objective, // 0x64
set_passengers, set_passengers, // 0x65
set_player_inventory, set_player_inventory, // 0x66
set_player_team, set_player_team, // 0x67
set_score, set_score, // 0x68
set_simulation_distance, set_simulation_distance, // 0x69
set_subtitle_text, set_subtitle_text, // 0x6A
set_time, set_time, // 0x6B
set_title_text, set_title_text, // 0x6C
set_titles_animation, set_titles_animation, // 0x6D
sound_entity, sound_entity, // 0x6E
sound, sound, // 0x6F
start_configuration, start_configuration, // 0x70
stop_sound, stop_sound, // 0x71
store_cookie, store_cookie, // 0x72
system_chat, system_chat, // 0x73
tab_list, tab_list, // 0x74
tag_query, tag_query, // 0x75
take_item_entity, take_item_entity, // 0x76
teleport_entity, teleport_entity, // 0x77
ticking_state, ticking_state, // 0x78
ticking_step, ticking_step, // 0x79
transfer, transfer, // 0x7A
update_advancements, update_advancements, // 0x7B
update_attributes, update_attributes, // 0x7C
update_mob_effect, update_mob_effect, // 0x7D
update_recipes, update_recipes, // 0x7E
update_tags, update_tags, // 0x7F
projectile_power, projectile_power, // 0x80
custom_report_details, custom_report_details, // 0x81
server_links, server_links, // 0x82
], ],
Serverbound => [ Serverbound => [
accept_teleportation, accept_teleportation, // 0x00
block_entity_tag_query, block_entity_tag_query, // 0x01
bundle_item_selected, bundle_item_selected, // 0x02
change_difficulty, change_difficulty, // 0x03
chat_ack, chat_ack, // 0x04
chat_command, chat_command, // 0x05
chat_command_signed, chat_command_signed, // 0x06
chat, chat, // 0x07
chat_session_update, chat_session_update, // 0x08
chunk_batch_received, chunk_batch_received, // 0x09
client_command, client_command, // 0x0A
client_tick_end, client_tick_end, // 0x0B
client_information, client_information, // 0x0C
command_suggestion, command_suggestion, // 0x0D
configuration_acknowledged, configuration_acknowledged, // 0x0E
container_button_click, container_button_click, // 0x0F
container_click, container_click, // 0x10
container_close, container_close, // 0x11
container_slot_state_changed, container_slot_state_changed, // 0x12
cookie_response, cookie_response, // 0x13
custom_payload, custom_payload, // 0x14
debug_sample_subscription, debug_sample_subscription, // 0x15
edit_book, edit_book, // 0x16
entity_tag_query, entity_tag_query, // 0x17
interact, interact, // 0x18
jigsaw_generate, jigsaw_generate, // 0x19
keep_alive, keep_alive, // 0x1A
lock_difficulty, lock_difficulty, // 0x1B
move_player_pos, move_player_pos, // 0x1C
move_player_pos_rot, move_player_pos_rot, // 0x1D
move_player_rot, move_player_rot, // 0x1E
move_player_status_only, move_player_status_only, // 0x1F
move_vehicle, move_vehicle, // 0x20
paddle_boat, paddle_boat, // 0x21
pick_item_from_block, pick_item_from_block, // 0x22
pick_item_from_entity, pick_item_from_entity, // 0x23
ping_request, ping_request, // 0x24
place_recipe, place_recipe, // 0x25
player_abilities, player_abilities, // 0x26
player_action, player_action, // 0x27
player_command, player_command, // 0x28
player_input, player_input, // 0x29
player_loaded, player_loaded, // 0x2A
pong, pong, // 0x2B
recipe_book_change_settings, recipe_book_change_settings, // 0x2C
recipe_book_seen_recipe, recipe_book_seen_recipe, // 0x2D
rename_item, rename_item, // 0x2E
resource_pack, resource_pack, // 0x2F
seen_advancements, seen_advancements, // 0x30
select_trade, select_trade, // 0x31
set_beacon, set_beacon, // 0x32
set_carried_item, set_carried_item, // 0x33
set_command_block, set_command_block, // 0x34
set_command_minecart, set_command_minecart, // 0x35
set_creative_mode_slot, set_creative_mode_slot, // 0x36
set_jigsaw_block, set_jigsaw_block, // 0x37
set_structure_block, set_structure_block, // 0x38
sign_update, sign_update, // 0x39
swing, swing, // 0x3A
teleport_to_entity, teleport_to_entity, // 0x3B
use_item_on, use_item_on, // 0x3C
use_item, use_item, // 0x3D
] ]
); );

View file

@ -3,6 +3,8 @@ use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundContainerButtonClick { pub struct ServerboundContainerButtonClick {
pub container_id: u8, #[var]
pub button_id: u8, pub container_id: i32,
#[var]
pub button_id: u32,
} }

View file

@ -6,7 +6,8 @@ use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundContainerClick { pub struct ServerboundContainerClick {
pub container_id: u8, #[var]
pub container_id: i32,
#[var] #[var]
pub state_id: u32, pub state_id: u32,
pub slot_num: i16, pub slot_num: i16,

View file

@ -3,5 +3,6 @@ use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundContainerClose { pub struct ServerboundContainerClose {
pub container_id: u8, #[var]
pub container_id: i32,
} }

View file

@ -6,6 +6,6 @@ pub struct ServerboundContainerSlotStateChanged {
#[var] #[var]
pub slot_id: u32, pub slot_id: u32,
#[var] #[var]
pub container_id: u32, pub container_id: i32,
pub new_state: bool, pub new_state: bool,
} }

View file

@ -1,10 +1,9 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_protocol_macros::ServerboundGamePacket; use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundMovePlayerPos { pub struct ServerboundMovePlayerPos {
pub x: f64, pub pos: Vec3,
pub y: f64,
pub z: f64,
pub on_ground: bool, pub on_ground: bool,
} }

View file

@ -1,11 +1,11 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3; use azalea_core::position::Vec3;
use azalea_entity::LookDirection;
use azalea_protocol_macros::ServerboundGamePacket; use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundMovePlayerPosRot { pub struct ServerboundMovePlayerPosRot {
pub pos: Vec3, pub pos: Vec3,
pub y_rot: f32, pub look_direction: LookDirection,
pub x_rot: f32,
pub on_ground: bool, pub on_ground: bool,
} }

View file

@ -1,9 +1,9 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_entity::LookDirection;
use azalea_protocol_macros::ServerboundGamePacket; use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundMovePlayerRot { pub struct ServerboundMovePlayerRot {
pub y_rot: f32, pub look_direction: LookDirection,
pub x_rot: f32,
pub on_ground: bool, pub on_ground: bool,
} }

View file

@ -1,11 +1,10 @@
use azalea_buf::AzBuf; use azalea_buf::AzBuf;
use azalea_core::position::Vec3;
use azalea_entity::LookDirection;
use azalea_protocol_macros::ServerboundGamePacket; use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundMoveVehicle { pub struct ServerboundMoveVehicle {
pub x: f64, pub pos: Vec3,
pub y: f64, pub look_direction: LookDirection,
pub z: f64,
pub y_rot: f32,
pub x_rot: f32,
} }

View file

@ -4,7 +4,8 @@ use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundPlaceRecipe { pub struct ServerboundPlaceRecipe {
pub container_id: u8, #[var]
pub container_id: i32,
pub recipe: ResourceLocation, pub recipe: ResourceLocation,
pub shift_down: bool, pub shift_down: bool,
} }

View file

@ -7,6 +7,6 @@ declare_state_packets!(HandshakePacket,
Clientbound => [ Clientbound => [
], ],
Serverbound => [ Serverbound => [
intention, intention, // 0x00
] ]
); );

View file

@ -5,18 +5,18 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(LoginPacket, declare_state_packets!(LoginPacket,
Clientbound => [ Clientbound => [
login_disconnect, login_disconnect, // 0x00
hello, hello, // 0x01
login_finished, login_finished, // 0x02
login_compression, login_compression, // 0x03
custom_query, custom_query, // 0x04
cookie_request, cookie_request, // 0x05
], ],
Serverbound => [ Serverbound => [
hello, hello, // 0x00
key, key, // 0x01
custom_query_answer, custom_query_answer, // 0x02
login_acknowledged, login_acknowledged, // 0x03
cookie_response, cookie_response, // 0x04
] ]
); );

View file

@ -5,11 +5,11 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(StatusPacket, declare_state_packets!(StatusPacket,
Clientbound => [ Clientbound => [
status_response, status_response, // 0x00
pong_response, pong_response, // 0x01
], ],
Serverbound => [ Serverbound => [
status_request, status_request, // 0x00
ping_request, ping_request, // 0x01
] ]
); );

View file

@ -117,7 +117,7 @@ impl ContainerClientExt for Client {
/// A handle to a container that may be open. This does not close the container /// A handle to a container that may be open. This does not close the container
/// when it's dropped. See [`ContainerHandle`] if that behavior is desired. /// when it's dropped. See [`ContainerHandle`] if that behavior is desired.
pub struct ContainerHandleRef { pub struct ContainerHandleRef {
id: u8, id: i32,
client: Client, client: Client,
} }
impl Debug for ContainerHandleRef { impl Debug for ContainerHandleRef {
@ -138,7 +138,7 @@ impl ContainerHandleRef {
/// Get the id of the container. If this is 0, that means it's the player's /// Get the id of the container. If this is 0, that means it's the player's
/// inventory. Otherwise, the number isn't really meaningful since only one /// inventory. Otherwise, the number isn't really meaningful since only one
/// container can be open at a time. /// container can be open at a time.
pub fn id(&self) -> u8 { pub fn id(&self) -> i32 {
self.id self.id
} }
@ -199,14 +199,14 @@ impl Debug for ContainerHandle {
} }
} }
impl ContainerHandle { impl ContainerHandle {
fn new(id: u8, client: Client) -> Self { fn new(id: i32, client: Client) -> Self {
Self(ContainerHandleRef { id, client }) Self(ContainerHandleRef { id, client })
} }
/// Get the id of the container. If this is 0, that means it's the player's /// Get the id of the container. If this is 0, that means it's the player's
/// inventory. Otherwise, the number isn't really meaningful since only one /// inventory. Otherwise, the number isn't really meaningful since only one
/// container can be open at a time. /// container can be open at a time.
pub fn id(&self) -> u8 { pub fn id(&self) -> i32 {
self.0.id() self.0.id()
} }

View file

@ -6,9 +6,6 @@ import os
import re import re
def make_packet_mod_rs_line(packet_id: int, packet_class_name: str):
return f' {padded_hex(packet_id)}: {to_snake_case(packet_class_name)}::{to_camel_case(packet_class_name)},'
MOJMAP_TO_AZALEA_STATE_NAME_MAPPING = { MOJMAP_TO_AZALEA_STATE_NAME_MAPPING = {
# shorter name, i like it more # shorter name, i like it more
'configuration': 'config', 'configuration': 'config',
@ -62,12 +59,12 @@ def set_packets(packets_report):
code.append('') code.append('')
code.append(f'declare_state_packets!({to_camel_case(state)}Packet,') code.append(f'declare_state_packets!({to_camel_case(state)}Packet,')
code.append(' Clientbound => [') code.append(' Clientbound => [')
for packet_name in clientbound_packets: for packet_id, packet_name in enumerate(clientbound_packets):
code.append(f' {packet_name},') code.append(f' {packet_name}, // {padded_hex(packet_id)}')
code.append(' ],') code.append(' ],')
code.append(' Serverbound => [') code.append(' Serverbound => [')
for packet_name in serverbound_packets: for packet_id, packet_name in enumerate(serverbound_packets):
code.append(f' {packet_name},') code.append(f' {packet_name}, // {padded_hex(packet_id)}')
code.append(' ]') code.append(' ]')
code.append(');') code.append(');')
code.append('') code.append('')

View file

@ -25,7 +25,7 @@ def upper_first_letter(name: str):
def padded_hex(n: int): def padded_hex(n: int):
return f'0x{n:02x}' return f'0x{n:02X}'
class PacketIdentifier: class PacketIdentifier: