aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf/write.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/mc_buf/write.rs')
-rwxr-xr-xazalea-protocol/src/mc_buf/write.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
index 9330dccb..05f613d8 100755
--- a/azalea-protocol/src/mc_buf/write.rs
+++ b/azalea-protocol/src/mc_buf/write.rs
@@ -1,4 +1,5 @@
use async_trait::async_trait;
+use azalea_chat::component::Component;
use azalea_core::{
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
};
@@ -209,7 +210,7 @@ impl McBufWritable for ResourceLocation {
// u32
impl McBufWritable for u32 {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
- i32::varint_write_into(&(*self as i32), buf)
+ i16::write_into(&(*self as i16), buf)
}
}
@@ -223,7 +224,7 @@ impl McBufVarintWritable for u32 {
// u16
impl McBufWritable for u16 {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
- i32::varint_write_into(&(*self as i32), buf)
+ i16::write_into(&(*self as i16), buf)
}
}
@@ -241,6 +242,13 @@ impl McBufWritable for u8 {
}
}
+// i16
+impl McBufWritable for i16 {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ Writable::write_short(buf, *self)
+ }
+}
+
// i64
impl McBufWritable for i64 {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
@@ -269,7 +277,7 @@ impl McBufWritable for i8 {
}
}
-// i8
+// f32
impl McBufWritable for f32 {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
buf.write_float(*self)
@@ -312,3 +320,22 @@ impl McBufWritable for Difficulty {
u8::write_into(&self.id(), buf)
}
}
+
+// Component
+#[async_trait]
+impl McBufWritable for Component {
+ // async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ // where
+ // R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ // {
+ // let string = buf.read_utf().await?;
+ // let json: serde_json::Value = serde_json::from_str(string.as_str())
+ // .map_err(|e| "Component isn't valid JSON".to_string())?;
+ // let component = Component::deserialize(json).map_err(|e| e.to_string())?;
+ // Ok(component)
+ // }
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ // component doesn't have serialize implemented yet
+ todo!()
+ }
+}