aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf/write.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-05-15 01:46:11 +0000
committerGitHub <noreply@github.com>2022-05-15 01:46:11 +0000
commitd0ac62d85276bc48e4f8e0e60afdc35840681622 (patch)
treeff4996b89d6f34c7c452d1b2950e53d512bce3c1 /azalea-protocol/src/mc_buf/write.rs
parentef3cbe27f2a7eed5c635924d6fa0401dd04eae77 (diff)
parentc16e958d0be671a17edf060aee9850faccbcfe14 (diff)
downloadazalea-drasl-d0ac62d85276bc48e4f8e0e60afdc35840681622.tar.xz
Merge pull request #6 from mat-1/chunk-decoding
Chunk decoding
Diffstat (limited to 'azalea-protocol/src/mc_buf/write.rs')
-rw-r--r--[-rwxr-xr-x]azalea-protocol/src/mc_buf/write.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
index e3e7a2be..c46297a6 100755..100644
--- a/azalea-protocol/src/mc_buf/write.rs
+++ b/azalea-protocol/src/mc_buf/write.rs
@@ -2,7 +2,7 @@ use super::{UnsizedByteArray, MAX_STRING_LENGTH};
use azalea_chat::component::Component;
use azalea_core::{
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
- serializable_uuid::SerializableUuid, BlockPos, Direction, Slot,
+ serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, Slot,
};
use byteorder::{BigEndian, WriteBytesExt};
use std::{collections::HashMap, io::Write};
@@ -20,8 +20,8 @@ pub trait Writable: Write {
Ok(())
}
- fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error> {
- self.write_list(&list, |buf, n| buf.write_varint(*n))
+ fn write_int_id_list(&mut self, list: &[i32]) -> Result<(), std::io::Error> {
+ self.write_list(list, |buf, n| buf.write_varint(*n))
}
fn write_map<KF, VF, KT, VT>(
@@ -47,7 +47,7 @@ pub trait Writable: Write {
}
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
- self.write_all(bytes);
+ self.write_all(bytes)?;
Ok(())
}
@@ -377,7 +377,7 @@ impl McBufWritable for Component {
// let component = Component::deserialize(json).map_err(|e| e.to_string())?;
// Ok(component)
// }
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
// component doesn't have serialize implemented yet
todo!()
}
@@ -425,3 +425,14 @@ impl McBufWritable for Direction {
buf.write_varint(*self as i32)
}
}
+
+// ChunkSectionPos
+impl McBufWritable for ChunkSectionPos {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ let long = (((self.x & 0x3FFFFF) as i64) << 42)
+ | (self.y & 0xFFFFF) as i64
+ | (((self.z & 0x3FFFFF) as i64) << 20);
+ long.write_into(buf)?;
+ Ok(())
+ }
+}