diff options
| author | mat <github@matdoes.dev> | 2022-05-01 23:06:56 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-01 23:06:56 -0500 |
| commit | bec2da64d81883e3ea909452e71e17b9d22b2adc (patch) | |
| tree | d4f94abc09534768f2531a4c23f54dcc2dab2814 /azalea-protocol/src/packets/game | |
| parent | 4d75415130a008f83c3bd594ca4cefd01f3d53dd (diff) | |
| parent | db2fcecdc38ea7a43b098c6282dd906b73981f97 (diff) | |
| download | azalea-drasl-bec2da64d81883e3ea909452e71e17b9d22b2adc.tar.xz | |
Merge branch 'main' into chunk-decoding
Diffstat (limited to 'azalea-protocol/src/packets/game')
11 files changed, 120 insertions, 224 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs index afaa7fdd..703811c0 100755 --- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs @@ -1,9 +1,7 @@ use super::GamePacket; use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; -use async_trait::async_trait; use azalea_core::resource_location::ResourceLocation; -use std::hash::Hash; -use tokio::io::{AsyncRead, AsyncReadExt, AsyncWriteExt}; +use std::{hash::Hash, io::Read}; #[derive(Hash, Clone, Debug)] pub struct ClientboundDeclareCommandsPacket { @@ -20,16 +18,14 @@ impl ClientboundDeclareCommandsPacket { panic!("ClientboundDeclareCommandsPacket::write not implemented") } - pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( - buf: &mut T, - ) -> Result<GamePacket, String> { - let node_count = buf.read_varint().await?; + pub fn read<T: Read>(buf: &mut T) -> Result<GamePacket, String> { + let node_count = buf.read_varint()?; let mut nodes = Vec::with_capacity(node_count as usize); for _ in 0..node_count { - let node = BrigadierNodeStub::read_into(buf).await?; + let node = BrigadierNodeStub::read_into(buf)?; nodes.push(node); } - let root_index = buf.read_varint().await?; + let root_index = buf.read_varint()?; Ok(GamePacket::ClientboundDeclareCommandsPacket( ClientboundDeclareCommandsPacket { entries: nodes, @@ -47,20 +43,16 @@ pub struct BrigadierNumber<T> { min: Option<T>, max: Option<T>, } -#[async_trait] -impl<T: McBufReadable + Send> McBufReadable for BrigadierNumber<T> { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let flags = buf.read_byte().await?; +impl<T: McBufReadable> McBufReadable for BrigadierNumber<T> { + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let flags = buf.read_byte()?; let min = if flags & 0x01 != 0 { - Some(T::read_into(buf).await?) + Some(T::read_into(buf)?) } else { None }; let max = if flags & 0x02 != 0 { - Some(T::read_into(buf).await?) + Some(T::read_into(buf)?) } else { None }; @@ -97,13 +89,9 @@ pub enum BrigadierString { GreedyPhrase = 2, } -#[async_trait] impl McBufReadable for BrigadierString { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let id = buf.read_byte().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let id = buf.read_byte()?; Ok(match id { 0 => BrigadierString::SingleWord, 1 => BrigadierString::QuotablePhrase, @@ -171,38 +159,24 @@ pub enum BrigadierParser { Resource { registry_key: ResourceLocation }, } -#[async_trait] impl McBufReadable for BrigadierParser { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let parser = buf.read_resource_location().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let parser = buf.read_resource_location()?; if parser == ResourceLocation::new("brigadier:bool")? { Ok(BrigadierParser::Bool) } else if parser == ResourceLocation::new("brigadier:double")? { - Ok(BrigadierParser::Double( - BrigadierNumber::read_into(buf).await?, - )) + Ok(BrigadierParser::Double(BrigadierNumber::read_into(buf)?)) } else if parser == ResourceLocation::new("brigadier:float")? { - Ok(BrigadierParser::Float( - BrigadierNumber::read_into(buf).await?, - )) + Ok(BrigadierParser::Float(BrigadierNumber::read_into(buf)?)) } else if parser == ResourceLocation::new("brigadier:integer")? { - Ok(BrigadierParser::Integer( - BrigadierNumber::read_into(buf).await?, - )) + Ok(BrigadierParser::Integer(BrigadierNumber::read_into(buf)?)) } else if parser == ResourceLocation::new("brigadier:long")? { - Ok(BrigadierParser::Long( - BrigadierNumber::read_into(buf).await?, - )) + Ok(BrigadierParser::Long(BrigadierNumber::read_into(buf)?)) } else if parser == ResourceLocation::new("brigadier:string")? { - Ok(BrigadierParser::String( - BrigadierString::read_into(buf).await?, - )) + Ok(BrigadierParser::String(BrigadierString::read_into(buf)?)) } else if parser == ResourceLocation::new("minecraft:entity")? { - let flags = buf.read_byte().await?; + let flags = buf.read_byte()?; Ok(BrigadierParser::Entity { single: flags & 0x01 != 0, players_only: flags & 0x02 != 0, @@ -250,7 +224,7 @@ impl McBufReadable for BrigadierParser { } else if parser == ResourceLocation::new("minecraft:scoreboard_slot")? { Ok(BrigadierParser::ScoreboardSlot) } else if parser == ResourceLocation::new("minecraft:score_holder")? { - let flags = buf.read_byte().await?; + let flags = buf.read_byte()?; Ok(BrigadierParser::ScoreHolder { allows_multiple: flags & 0x01 != 0, }) @@ -270,7 +244,7 @@ impl McBufReadable for BrigadierParser { Ok(BrigadierParser::EntityAnchor) } else if parser == ResourceLocation::new("minecraft:range")? { Ok(BrigadierParser::Range { - decimals_allowed: buf.read_boolean().await?, + decimals_allowed: buf.read_boolean()?, }) } else if parser == ResourceLocation::new("minecraft:int_range")? { Ok(BrigadierParser::IntRange) @@ -292,11 +266,11 @@ impl McBufReadable for BrigadierParser { Ok(BrigadierParser::Time) } else if parser == ResourceLocation::new("minecraft:resource_or_tag")? { Ok(BrigadierParser::ResourceOrTag { - registry_key: buf.read_resource_location().await?, + registry_key: buf.read_resource_location()?, }) } else if parser == ResourceLocation::new("minecraft:resource")? { Ok(BrigadierParser::Resource { - registry_key: buf.read_resource_location().await?, + registry_key: buf.read_resource_location()?, }) } else { panic!("Unknown Brigadier parser: {}", parser) @@ -305,13 +279,9 @@ impl McBufReadable for BrigadierParser { } // azalea_brigadier::tree::CommandNode -#[async_trait] impl McBufReadable for BrigadierNodeStub { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let flags = u8::read_into(buf).await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let flags = u8::read_into(buf)?; if flags > 31 { println!( "Warning: The flags from a Brigadier node are over 31. This is probably a bug." @@ -323,21 +293,17 @@ impl McBufReadable for BrigadierNodeStub { let has_redirect = flags & 0x08 != 0; let has_suggestions_type = flags & 0x10 != 0; - let children = buf.read_int_id_list().await?; - let redirect_node = if has_redirect { - buf.read_varint().await? - } else { - 0 - }; + let children = buf.read_int_id_list()?; + let redirect_node = if has_redirect { buf.read_varint()? } else { 0 }; // argument node if node_type == 2 { - let name = buf.read_utf().await?; + let name = buf.read_utf()?; - let parser = BrigadierParser::read_into(buf).await?; + let parser = BrigadierParser::read_into(buf)?; let suggestions_type = if has_suggestions_type { - Some(buf.read_resource_location().await?) + Some(buf.read_resource_location()?) } else { None }; @@ -345,7 +311,7 @@ impl McBufReadable for BrigadierNodeStub { } // literal node if node_type == 1 { - let name = buf.read_utf().await?; + let name = buf.read_utf()?; return Ok(BrigadierNodeStub {}); } Ok(BrigadierNodeStub {}) diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs index f4f528cf..3ca1ac85 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs @@ -1,9 +1,7 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code +use std::io::Read; use crate::mc_buf::{McBufReadable, McBufWritable, Readable}; -use async_trait::async_trait; use packet_macros::GamePacket; -use tokio::io::AsyncRead; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundPlayerAbilitiesPacket { @@ -21,13 +19,9 @@ pub struct PlayerAbilitiesFlags { pub instant_break: bool, } -#[async_trait] impl McBufReadable for PlayerAbilitiesFlags { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let byte = buf.read_byte().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let byte = buf.read_byte()?; Ok(PlayerAbilitiesFlags { invulnerable: byte & 1 != 0, flying: byte & 2 != 0, diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs index 3d4c3ac7..97b68259 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs @@ -1,10 +1,7 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code - use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; -use async_trait::async_trait; use azalea_chat::component::Component; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; +use std::io::Read; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -64,19 +61,15 @@ pub struct RemovePlayer { uuid: Uuid, } -#[async_trait] impl McBufReadable for Action { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let id = buf.read_byte().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let id = buf.read_byte()?; Ok(match id { - 0 => Action::AddPlayer(Vec::<AddPlayer>::read_into(buf).await?), - 1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_into(buf).await?), - 2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_into(buf).await?), - 3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_into(buf).await?), - 4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_into(buf).await?), + 0 => Action::AddPlayer(Vec::<AddPlayer>::read_into(buf)?), + 1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_into(buf)?), + 2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_into(buf)?), + 3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_into(buf)?), + 4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_into(buf)?), _ => panic!("Unknown player info action id: {}", id), }) } diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs index 5bb40d84..e47ca9e1 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs @@ -1,9 +1,7 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code +use std::io::Read; use crate::mc_buf::{McBufReadable, McBufWritable, Readable}; -use async_trait::async_trait; use packet_macros::GamePacket; -use tokio::io::AsyncRead; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundPlayerPositionPacket { @@ -29,13 +27,9 @@ pub struct RelativeArguments { pub x_rot: bool, } -#[async_trait] impl McBufReadable for RelativeArguments { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let byte = buf.read_byte().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let byte = buf.read_byte()?; Ok(RelativeArguments { x: byte & 0b1 != 0, y: byte & 0b10 != 0, diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs index 69f26ddc..4847bbf8 100644 --- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -1,8 +1,6 @@ -use async_trait::async_trait; -use azalea_chat::component::Component; use azalea_core::{resource_location::ResourceLocation, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; +use std::io::Read; use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; @@ -42,13 +40,9 @@ impl McBufWritable for State { Ok(()) } } -#[async_trait] impl McBufReadable for State { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let state = buf.read_varint().await?.try_into().unwrap(); + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let state = buf.read_varint()?.try_into().unwrap(); Ok(match state { 0 => State::Init, 1 => State::Add, diff --git a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs index 4cc456f3..302d832a 100644 --- a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs @@ -1,12 +1,12 @@ +use std::io::Read; + use crate::{ mc_buf::{Readable, Writable}, packets::{McBufReadable, McBufWritable}, }; -use async_trait::async_trait; use azalea_chat::component::Component; use azalea_core::{BlockPos, Direction, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -24,19 +24,15 @@ pub struct EntityDataItem { pub value: EntityDataValue, } -#[async_trait] impl McBufReadable for Vec<EntityDataItem> { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { + fn read_into(buf: &mut impl Read) -> Result<Self, String> { let mut metadata = Vec::new(); loop { - let index = buf.read_byte().await?; + let index = buf.read_byte()?; if index == 0xff { break; } - let value = EntityDataValue::read_into(buf).await?; + let value = EntityDataValue::read_into(buf)?; metadata.push(EntityDataItem { index, value }); } Ok(metadata) @@ -81,51 +77,47 @@ pub enum EntityDataValue { Pose(Pose), } -#[async_trait] impl McBufReadable for EntityDataValue { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let type_ = buf.read_varint().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let type_ = buf.read_varint()?; Ok(match type_ { - 0 => EntityDataValue::Byte(buf.read_byte().await?), - 1 => EntityDataValue::Int(buf.read_varint().await?), - 2 => EntityDataValue::Float(buf.read_float().await?), - 3 => EntityDataValue::String(buf.read_utf().await?), - 4 => EntityDataValue::Component(Component::read_into(buf).await?), - 5 => EntityDataValue::OptionalComponent(Option::<Component>::read_into(buf).await?), - 6 => EntityDataValue::ItemStack(Slot::read_into(buf).await?), - 7 => EntityDataValue::Boolean(buf.read_boolean().await?), + 0 => EntityDataValue::Byte(buf.read_byte()?), + 1 => EntityDataValue::Int(buf.read_varint()?), + 2 => EntityDataValue::Float(buf.read_float()?), + 3 => EntityDataValue::String(buf.read_utf()?), + 4 => EntityDataValue::Component(Component::read_into(buf)?), + 5 => EntityDataValue::OptionalComponent(Option::<Component>::read_into(buf)?), + 6 => EntityDataValue::ItemStack(Slot::read_into(buf)?), + 7 => EntityDataValue::Boolean(buf.read_boolean()?), 8 => EntityDataValue::Rotations { - x: buf.read_float().await?, - y: buf.read_float().await?, - z: buf.read_float().await?, + x: buf.read_float()?, + y: buf.read_float()?, + z: buf.read_float()?, }, - 9 => EntityDataValue::BlockPos(BlockPos::read_into(buf).await?), - 10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_into(buf).await?), - 11 => EntityDataValue::Direction(Direction::read_into(buf).await?), - 12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_into(buf).await?), + 9 => EntityDataValue::BlockPos(BlockPos::read_into(buf)?), + 10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_into(buf)?), + 11 => EntityDataValue::Direction(Direction::read_into(buf)?), + 12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_into(buf)?), 13 => EntityDataValue::OptionalBlockState({ - let val = i32::read_into(buf).await?; + let val = i32::read_into(buf)?; if val == 0 { None } else { Some(val) } }), - 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_into(buf).await?), - 15 => EntityDataValue::Particle(Particle::read_into(buf).await?), - 16 => EntityDataValue::VillagerData(VillagerData::read_into(buf).await?), + 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_into(buf)?), + 15 => EntityDataValue::Particle(Particle::read_into(buf)?), + 16 => EntityDataValue::VillagerData(VillagerData::read_into(buf)?), 17 => EntityDataValue::OptionalUnsignedInt({ - let val = buf.read_varint().await?; + let val = buf.read_varint()?; if val == 0 { None } else { Some((val - 1) as u32) } }), - 18 => EntityDataValue::Pose(Pose::read_into(buf).await?), + 18 => EntityDataValue::Pose(Pose::read_into(buf)?), _ => return Err(format!("Unknown entity data type: {}", type_)), }) } @@ -309,18 +301,14 @@ pub struct VibrationParticle { pub ticks: u32, } -#[async_trait] impl McBufReadable for ParticleData { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let id = buf.read_varint().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let id = buf.read_varint()?; Ok(match id { 0 => ParticleData::AmbientEntityEffect, 1 => ParticleData::AngryVillager, - 2 => ParticleData::Block(BlockParticle::read_into(buf).await?), - 3 => ParticleData::BlockMarker(BlockParticle::read_into(buf).await?), + 2 => ParticleData::Block(BlockParticle::read_into(buf)?), + 3 => ParticleData::BlockMarker(BlockParticle::read_into(buf)?), 4 => ParticleData::Bubble, 5 => ParticleData::Cloud, 6 => ParticleData::Crit, @@ -331,10 +319,8 @@ impl McBufReadable for ParticleData { 11 => ParticleData::LandingLava, 12 => ParticleData::DrippingWater, 13 => ParticleData::FallingWater, - 14 => ParticleData::Dust(DustParticle::read_into(buf).await?), - 15 => ParticleData::DustColorTransition( - DustColorTransitionParticle::read_into(buf).await?, - ), + 14 => ParticleData::Dust(DustParticle::read_into(buf)?), + 15 => ParticleData::DustColorTransition(DustColorTransitionParticle::read_into(buf)?), 16 => ParticleData::Effect, 17 => ParticleData::ElderGuardian, 18 => ParticleData::EnchantedHit, @@ -343,7 +329,7 @@ impl McBufReadable for ParticleData { 21 => ParticleData::EntityEffect, 22 => ParticleData::ExplosionEmitter, 23 => ParticleData::Explosion, - 24 => ParticleData::FallingDust(BlockParticle::read_into(buf).await?), + 24 => ParticleData::FallingDust(BlockParticle::read_into(buf)?), 25 => ParticleData::Firework, 26 => ParticleData::Fishing, 27 => ParticleData::Flame, @@ -354,8 +340,8 @@ impl McBufReadable for ParticleData { 32 => ParticleData::Composter, 33 => ParticleData::Heart, 34 => ParticleData::InstantEffect, - 35 => ParticleData::Item(ItemParticle::read_into(buf).await?), - 36 => ParticleData::Vibration(VibrationParticle::read_into(buf).await?), + 35 => ParticleData::Item(ItemParticle::read_into(buf)?), + 36 => ParticleData::Vibration(VibrationParticle::read_into(buf)?), 37 => ParticleData::ItemSlime, 38 => ParticleData::ItemSnowball, 39 => ParticleData::LargeSmoke, diff --git a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs index d7f86931..6e0aae29 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs @@ -1,11 +1,9 @@ -use async_trait::async_trait; -use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; +use azalea_core::resource_location::ResourceLocation; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; +use std::io::Read; use uuid::Uuid; -use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; - #[derive(Clone, Debug, GamePacket)] pub struct ClientboundUpdateAttributesPacket { #[varint] @@ -34,13 +32,9 @@ enum Operation { MultiplyTotal = 2, } -#[async_trait] impl McBufReadable for Operation { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - match buf.read_byte().await? { + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + match buf.read_byte()? { 0 => Ok(Operation::Addition), 1 => Ok(Operation::MultiplyBase), 2 => Ok(Operation::MultiplyTotal), diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs index 5ae06a6f..4b1a322a 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -1,8 +1,7 @@ -use async_trait::async_trait; -use azalea_chat::component::Component; +use std::io::Read; + use azalea_core::{resource_location::ResourceLocation, Slot}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; @@ -48,20 +47,16 @@ impl McBufWritable for ShapedRecipe { Ok(()) } } -#[async_trait] impl McBufReadable for ShapedRecipe { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let width = buf.read_varint().await?.try_into().unwrap(); - let height = buf.read_varint().await?.try_into().unwrap(); - let group = buf.read_utf().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let width = buf.read_varint()?.try_into().unwrap(); + let height = buf.read_varint()?.try_into().unwrap(); + let group = buf.read_utf()?; let mut ingredients = Vec::with_capacity(width * height); for _ in 0..width * height { - ingredients.push(Ingredient::read_into(buf).await?); + ingredients.push(Ingredient::read_into(buf)?); } - let result = Slot::read_into(buf).await?; + let result = Slot::read_into(buf)?; Ok(ShapedRecipe { width, @@ -132,22 +127,18 @@ impl McBufWritable for Recipe { } } -#[async_trait] impl McBufReadable for Recipe { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let recipe_type = buf.read_resource_location().await?; - let identifier = buf.read_resource_location().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let recipe_type = buf.read_resource_location()?; + let identifier = buf.read_resource_location()?; // rust doesn't let us match ResourceLocation so we have to do a big // if-else chain :( let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap() { - RecipeData::CraftingShapeless(ShapelessRecipe::read_into(buf).await?) + RecipeData::CraftingShapeless(ShapelessRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() { - RecipeData::CraftingShaped(ShapedRecipe::read_into(buf).await?) + RecipeData::CraftingShaped(ShapedRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:crafting_special_armordye").unwrap() { @@ -205,17 +196,17 @@ impl McBufReadable for Recipe { { RecipeData::CraftingSpecialSuspiciousStew } else if recipe_type == ResourceLocation::new("minecraft:smelting").unwrap() { - RecipeData::Smelting(CookingRecipe::read_into(buf).await?) + RecipeData::Smelting(CookingRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:blasting").unwrap() { - RecipeData::Blasting(CookingRecipe::read_into(buf).await?) + RecipeData::Blasting(CookingRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:smoking").unwrap() { - RecipeData::Smoking(CookingRecipe::read_into(buf).await?) + RecipeData::Smoking(CookingRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:campfire_cooking").unwrap() { - RecipeData::CampfireCooking(CookingRecipe::read_into(buf).await?) + RecipeData::CampfireCooking(CookingRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:stonecutting").unwrap() { - RecipeData::Stonecutting(StoneCuttingRecipe::read_into(buf).await?) + RecipeData::Stonecutting(StoneCuttingRecipe::read_into(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:smithing").unwrap() { - RecipeData::Smithing(SmithingRecipe::read_into(buf).await?) + RecipeData::Smithing(SmithingRecipe::read_into(buf)?) } else { panic!("Unknown recipe type sent by server: {}", recipe_type); }; diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs index b6046948..4646c2d3 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs @@ -1,11 +1,7 @@ -use std::collections::HashMap; - -use async_trait::async_trait; +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use azalea_core::resource_location::ResourceLocation; use packet_macros::GamePacket; -use tokio::io::AsyncRead; - -use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; +use std::{collections::HashMap, io::Read}; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundUpdateTagsPacket { @@ -18,20 +14,16 @@ pub struct Tags { pub elements: Vec<i32>, } -#[async_trait] impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let length = buf.read_varint().await? as usize; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let length = buf.read_varint()? as usize; let mut data = HashMap::with_capacity(length); for _ in 0..length { - let tag_type = buf.read_resource_location().await?; - let tags_count = buf.read_varint().await? as usize; + let tag_type = buf.read_resource_location()?; + let tags_count = buf.read_varint()? as usize; let mut tags_vec = Vec::with_capacity(tags_count); for _ in 0..tags_count { - let tags = Tags::read_into(buf).await?; + let tags = Tags::read_into(buf)?; tags_vec.push(tags); } data.insert(tag_type, tags_vec); @@ -50,14 +42,10 @@ impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> { Ok(()) } } -#[async_trait] impl McBufReadable for Tags { - async fn read_into<R>(buf: &mut R) -> Result<Self, String> - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let name = buf.read_resource_location().await?; - let elements = buf.read_int_id_list().await?; + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let name = buf.read_resource_location()?; + let elements = buf.read_int_id_list()?; Ok(Tags { name, elements }) } } diff --git a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs index 8301c089..1f988fe5 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs @@ -1,5 +1,3 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code - use packet_macros::GamePacket; #[derive(Clone, Debug, GamePacket)] diff --git a/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs index 43ddb700..eefafdd1 100644 --- a/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs +++ b/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs @@ -1,5 +1,3 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code - use crate::mc_buf::UnsizedByteArray; use azalea_core::resource_location::ResourceLocation; use packet_macros::GamePacket; |
