aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-01 23:35:30 -0500
committermat <github@matdoes.dev>2022-05-01 23:38:55 -0500
commitdedcd0de8f017a00645b31cfdc1819a4e8da0850 (patch)
tree7005291337dcc5a9cd1c5bb71668b511a6834d23 /azalea-protocol/src/packets/game
parentdb2fcecdc38ea7a43b098c6282dd906b73981f97 (diff)
downloadazalea-drasl-dedcd0de8f017a00645b31cfdc1819a4e8da0850.tar.xz
impl Write instead of Vec<u8> for consistency
Diffstat (limited to 'azalea-protocol/src/packets/game')
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs11
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_info_packet.rs4
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_position_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_recipe_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs9
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs4
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs6
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_tags_packet.rs9
9 files changed, 31 insertions, 29 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 703811c0..27f4fb16 100755
--- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
@@ -1,7 +1,10 @@
use super::GamePacket;
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
-use std::{hash::Hash, io::Read};
+use std::{
+ hash::Hash,
+ io::{Read, Write},
+};
#[derive(Hash, Clone, Debug)]
pub struct ClientboundDeclareCommandsPacket {
@@ -14,7 +17,7 @@ impl ClientboundDeclareCommandsPacket {
GamePacket::ClientboundDeclareCommandsPacket(self)
}
- pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
panic!("ClientboundDeclareCommandsPacket::write not implemented")
}
@@ -60,7 +63,7 @@ impl<T: McBufReadable> McBufReadable for BrigadierNumber<T> {
}
}
impl<T: McBufWritable> McBufWritable for BrigadierNumber<T> {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut flags = 0;
if self.min.is_some() {
flags |= 0x01;
@@ -101,7 +104,7 @@ impl McBufReadable for BrigadierString {
}
}
impl McBufWritable for BrigadierString {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_byte(*self as u8)?;
Ok(())
}
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 3ca1ac85..cd645fe6 100755
--- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs
@@ -1,7 +1,6 @@
-use std::io::Read;
-
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::GamePacket;
+use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
pub struct ClientboundPlayerAbilitiesPacket {
@@ -32,7 +31,7 @@ impl McBufReadable for PlayerAbilitiesFlags {
}
impl McBufWritable for PlayerAbilitiesFlags {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut byte = 0;
if self.invulnerable {
byte = byte | 1;
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 97b68259..9c34d06e 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
@@ -1,7 +1,7 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_chat::component::Component;
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
-use std::io::Read;
+use std::io::{Read, Write};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
@@ -75,7 +75,7 @@ impl McBufReadable for Action {
}
}
impl McBufWritable for Action {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_byte(match self {
Action::AddPlayer(_) => 0,
Action::UpdateGameMode(_) => 1,
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 e47ca9e1..cac4665d 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
@@ -1,7 +1,6 @@
-use std::io::Read;
-
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::GamePacket;
+use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
pub struct ClientboundPlayerPositionPacket {
@@ -41,7 +40,7 @@ impl McBufReadable for RelativeArguments {
}
impl McBufWritable for RelativeArguments {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut byte = 0;
if self.x {
byte = byte | 0b1;
diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
index 4847bbf8..543fb64c 100644
--- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
@@ -1,8 +1,7 @@
+use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::{resource_location::ResourceLocation, Slot};
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
-use std::io::Read;
-
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use std::io::{Read, Write};
#[derive(Clone, Debug, GamePacket)]
pub struct ClientboundRecipePacket {
@@ -35,7 +34,7 @@ pub enum State {
}
impl McBufWritable for State {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_varint(*self as i32)?;
Ok(())
}
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 302d832a..5d288518 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,5 +1,3 @@
-use std::io::Read;
-
use crate::{
mc_buf::{Readable, Writable},
packets::{McBufReadable, McBufWritable},
@@ -7,6 +5,7 @@ use crate::{
use azalea_chat::component::Component;
use azalea_core::{BlockPos, Direction, Slot};
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
+use std::io::{Read, Write};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
@@ -40,7 +39,7 @@ impl McBufReadable for Vec<EntityDataItem> {
}
impl McBufWritable for Vec<EntityDataItem> {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
for item in self {
buf.write_byte(item.index)?;
item.value.write_into(buf)?;
@@ -124,7 +123,7 @@ impl McBufReadable for EntityDataValue {
}
impl McBufWritable for EntityDataValue {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!();
}
}
@@ -399,7 +398,7 @@ impl McBufReadable for ParticleData {
}
impl McBufWritable for ParticleData {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!()
}
}
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 6e0aae29..82f34f96 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs
@@ -1,7 +1,7 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
-use std::io::Read;
+use std::io::{Read, Write};
use uuid::Uuid;
#[derive(Clone, Debug, GamePacket)]
@@ -44,7 +44,7 @@ impl McBufReadable for Operation {
}
impl McBufWritable for Operation {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_byte(*self as u8)?;
Ok(())
}
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 4b1a322a..d15e10c3 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -1,4 +1,4 @@
-use std::io::Read;
+use std::io::{Read, Write};
use azalea_core::{resource_location::ResourceLocation, Slot};
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
@@ -35,7 +35,7 @@ pub struct ShapedRecipe {
}
impl McBufWritable for ShapedRecipe {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_varint(self.width.try_into().unwrap())?;
buf.write_varint(self.height.try_into().unwrap())?;
buf.write_utf(&self.group)?;
@@ -122,7 +122,7 @@ pub struct Ingredient {
}
impl McBufWritable for Recipe {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!()
}
}
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 4646c2d3..f82a4177 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
@@ -1,7 +1,10 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
use packet_macros::GamePacket;
-use std::{collections::HashMap, io::Read};
+use std::{
+ collections::HashMap,
+ io::{Read, Write},
+};
#[derive(Clone, Debug, GamePacket)]
pub struct ClientboundUpdateTagsPacket {
@@ -33,7 +36,7 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
}
impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_varint(self.len() as i32)?;
for (k, v) in self {
k.write_into(buf)?;
@@ -51,7 +54,7 @@ impl McBufReadable for Tags {
}
impl McBufWritable for Tags {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
self.name.write_into(buf)?;
buf.write_int_id_list(&self.elements)?;
Ok(())