use graphite_binary::slice_serialization::*;
use crate::identify_packets;
use crate::types::ArmPosition;
use crate::types::BlockHitResult;
use crate::types::BlockPosition;
use crate::types::ChatVisibility;
use crate::types::Direction;
use crate::types::Hand;
use crate::types::HandAction;
use crate::types::MoveAction;
use crate::types::ProtocolItemStack;
use crate::IdentifiedPacket;
use num_enum::TryFromPrimitive;
identify_packets! {
PacketId,
AcceptTeleportation = 0x00,
ChatCommand<'_> = 0x04,
ClientInformation<'_> = 0x08,
CustomPayload<'_> = 0x0d,
InteractEntity = 0x10,
KeepAlive = 0x12,
MovePlayerPos = 0x14,
MovePlayerPosRot = 0x15,
MovePlayerRot = 0x16,
MovePlayerOnGround = 0x17,
PlayerAbilities = 0x1c,
PlayerHandAction = 0x1d,
PlayerMoveAction = 0x1e,
SetCarriedItem = 0x28,
SetCreativeModeSlot<'_> = 0x2b,
Swing = 0x2f,
UseItemOn = 0x31,
UseItem = 0x32
}
slice_serializable! {
#[derive(Debug)]
pub struct AcceptTeleportation {
pub id: i32 as VarInt
}
}
slice_serializable! {
#[derive(Debug)]
pub struct Signature<'a> {
pub string: &'a str as SizedString<256>,
pub bytes: &'a [u8] as SizedBlob<16> }
}
slice_serializable! {
#[derive(Debug)]
pub struct ReceivedMessage<'a> {
pub from_uuid: u128 as BigEndian,
pub bytes: &'a [u8] as SizedBlob<300>
}
}
slice_serializable! {
#[derive(Debug)]
pub struct ChatCommand<'a> {
pub command: &'a str as SizedString<256>,
pub timestamp: u64 as BigEndian,
pub salt: u64 as BigEndian,
pub signatures: Vec<Signature<'a>> as SizedArray<Signature<'_>>,
pub signed: bool as Single,
pub last_seen_messages: Vec<ReceivedMessage<'a>> as SizedArray<ReceivedMessage>,
pub last_received_message: Option<ReceivedMessage<'a>>
}
}
slice_serializable! {
#[derive(Debug)]
pub struct ClientInformation<'a> {
pub language: &'a str as SizedString<16>,
pub view_distance: u8 as Single,
pub chat_visibility: ChatVisibility as AttemptFrom<Single, u8>,
pub chat_colors: bool as Single,
pub model_customization: i8 as Single,
pub arm_position: ArmPosition as AttemptFrom<Single, u8>,
pub text_filtering_enabled: bool as Single,
pub show_on_server_list: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct CustomPayload<'a> {
pub channel: &'a str as SizedString,
pub data: &'a [u8] as GreedyBlob
}
}
slice_serializable! {
#[derive(Debug)]
pub enum InteractMode {
Interact {
hand: Hand as AttemptFrom<Single, u8>
},
Attack {
},
InteractAt {
offset_x: f32 as BigEndian,
offset_y: f32 as BigEndian,
offset_z: f32 as BigEndian,
hand: Hand as AttemptFrom<Single, u8>
}
}
}
slice_serializable! {
#[derive(Debug)]
pub struct InteractEntity {
pub entity_id: i32 as VarInt,
pub mode: InteractMode,
pub shift_key_down: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct KeepAlive {
pub id: u64 as BigEndian
}
}
slice_serializable! {
#[derive(Debug)]
pub struct MovePlayerPos {
pub x: f64 as BigEndian,
pub y: f64 as BigEndian,
pub z: f64 as BigEndian,
pub on_ground: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct MovePlayerRot {
pub yaw: f32 as BigEndian,
pub pitch: f32 as BigEndian,
pub on_ground: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct MovePlayerPosRot {
pub x: f64 as BigEndian,
pub y: f64 as BigEndian,
pub z: f64 as BigEndian,
pub yaw: f32 as BigEndian,
pub pitch: f32 as BigEndian,
pub on_ground: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct MovePlayerOnGround {
pub on_ground: bool as Single
}
}
slice_serializable! {
#[derive(Debug)]
pub struct PlayerAbilities {
pub flags: u8 as Single,
}
}
slice_serializable! {
#[derive(Debug)]
pub struct PlayerHandAction {
pub action: HandAction as AttemptFrom<Single, u8>,
pub block_pos: BlockPosition,
pub direction: Direction as AttemptFrom<Single, u8>,
pub sequence: i32 as VarInt
}
}
slice_serializable! {
#[derive(Debug)]
pub struct PlayerMoveAction {
pub id: i32 as VarInt,
pub action: MoveAction as AttemptFrom<Single, u8>,
pub data: i32 as VarInt,
}
}
slice_serializable! {
#[derive(Debug)]
pub struct SetCarriedItem {
pub slot: u16 as BigEndian
}
}
slice_serializable! {
#[derive(Debug)]
pub struct SetCreativeModeSlot<'a> {
pub slot: i16 as BigEndian,
pub item: Option<ProtocolItemStack<'a>>
}
}
slice_serializable! {
#[derive(Debug)]
pub struct Swing {
pub hand: Hand as AttemptFrom<Single, u8>
}
}
slice_serializable! {
#[derive(Debug)]
pub struct UseItemOn {
pub hand: Hand as AttemptFrom<Single, u8>,
pub block_hit: BlockHitResult,
pub sequence: i32 as VarInt
}
}
slice_serializable! {
#[derive(Debug)]
pub struct UseItem {
pub hand: Hand as AttemptFrom<Single, u8>,
pub sequence: i32 as VarInt
}
}