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

Set carried item and update tags packets

This commit is contained in:
mat 2022-04-21 15:25:46 +00:00
parent 298d30ad08
commit 2c848ebaa5
7 changed files with 22 additions and 31 deletions

View file

@ -76,10 +76,15 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
GamePacket::ClientboundDeclareCommandsPacket(p) => {
println!("Got declare commands packet {:?}", p);
}
GamePacket::ClientboundPlayerAbilitiesPacket(p) => {
println!("Got player abilities packet {:?}", p);
}
GamePacket::ClientboundSetCarriedItemPacket(p) => {
println!("Got set carried item packet {:?}", p);
}
GamePacket::ClientboundUpdateTagsPacket(p) => {
println!("Got update tags packet {:?}", p);
}
},
Err(e) => {
println!("Error: {:?}", e);

View file

@ -75,7 +75,7 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
.collect::<Vec<_>>();
let read_field_names = named.iter().map(|f| &f.ident).collect::<Vec<_>>();
let gen = quote! {
quote! {
impl #ident {
pub fn get(self) -> #state {
#state::#ident(self)
@ -95,9 +95,8 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
}.get())
}
}
};
gen.into()
}
.into()
}
#[proc_macro_derive(GamePacket, attributes(varint))]

View file

@ -14,7 +14,7 @@ pub trait Writable {
F: FnOnce(&mut Self, &T) -> Result<(), std::io::Error> + Copy,
T: Sized,
Self: Sized;
fn write_int_id_list(&mut self, list: Vec<i32>) -> Result<(), std::io::Error>;
fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error>;
fn write_map<KF, VF, KT, VT>(
&mut self,
map: Vec<(KT, VT)>,
@ -58,7 +58,7 @@ impl Writable for Vec<u8> {
Ok(())
}
fn write_int_id_list(&mut self, list: Vec<i32>) -> Result<(), std::io::Error> {
fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error> {
self.write_list(&list, |buf, n| buf.write_varint(*n))
}

View file

@ -21,7 +21,6 @@ pub struct PlayerAbilitiesFlags {
pub instant_break: bool,
}
// Difficulty
#[async_trait]
impl McBufReadable for PlayerAbilitiesFlags {
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
@ -38,7 +37,6 @@ impl McBufReadable for PlayerAbilitiesFlags {
}
}
// Difficulty
impl McBufWritable for PlayerAbilitiesFlags {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
let mut byte = 0;

View file

@ -3,6 +3,8 @@ pub mod clientbound_custom_payload_packet;
pub mod clientbound_declare_commands_packet;
pub mod clientbound_login_packet;
pub mod clientbound_player_abilities_packet;
pub mod clientbound_set_carried_item_packet;
pub mod clientbound_update_tags_packet;
pub mod clientbound_update_view_distance_packet;
use packet_macros::declare_state_packets;
@ -16,6 +18,8 @@ declare_state_packets!(
0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
0x26: clientbound_login_packet::ClientboundLoginPacket,
0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket,
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket
0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket
}
);

View file

@ -1,22 +1,5 @@
use packet_macros::StatusPacket;
use std::hash::Hash;
use super::StatusPacket;
#[derive(Hash, Clone, Debug)]
#[derive(Clone, Debug, StatusPacket)]
pub struct ServerboundStatusRequestPacket {}
impl ServerboundStatusRequestPacket {
pub fn get(self) -> StatusPacket {
StatusPacket::ServerboundStatusRequestPacket(self)
}
pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
panic!("ServerboundStatusRequestPacket::write not implemented")
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
_buf: &mut T,
) -> Result<StatusPacket, String> {
Err("ServerboundStatusRequestPacket::read not implemented".to_string())
}
}

View file

@ -1,4 +1,5 @@
use azalea_client::connect::join_server;
use azalea_client::ping::ping_server;
#[tokio::main]
async fn main() {
@ -6,7 +7,8 @@ async fn main() {
let address = "95.111.249.143:10000";
// let address = "localhost:63482";
let _response = join_server(&address.try_into().unwrap()).await.unwrap();
// println!("{}", response.description.to_ansi(None));
let response = ping_server(&address.try_into().unwrap()).await.unwrap();
// let _response = join_server(&address.try_into().unwrap()).await.unwrap();
println!("{}", response.description.to_ansi(None));
println!("connected");
}