aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf/read.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/read.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/read.rs')
-rw-r--r--[-rwxr-xr-x]azalea-protocol/src/mc_buf/read.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs
index 98a3ee53..1c4fbd6f 100755..100644
--- a/azalea-protocol/src/mc_buf/read.rs
+++ b/azalea-protocol/src/mc_buf/read.rs
@@ -1,10 +1,10 @@
-use super::{BitSet, UnsizedByteArray, MAX_STRING_LENGTH};
+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, SlotData,
+ serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, Slot, SlotData,
};
-use byteorder::{ReadBytesExt, WriteBytesExt, BE};
+use byteorder::{ReadBytesExt, BE};
use serde::Deserialize;
use std::{collections::HashMap, hash::Hash, io::Read};
use tokio::io::{AsyncRead, AsyncReadExt};
@@ -466,7 +466,7 @@ impl McBufReadable for Component {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let string = buf.read_utf()?;
let json: serde_json::Value = serde_json::from_str(string.as_str())
- .map_err(|e| "Component isn't valid JSON".to_string())?;
+ .map_err(|_| "Component isn't valid JSON".to_string())?;
let component = Component::deserialize(json).map_err(|e| e.to_string())?;
Ok(component)
}
@@ -518,3 +518,15 @@ impl McBufReadable for Direction {
}
}
}
+
+// ChunkSectionPos
+impl McBufReadable for ChunkSectionPos {
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ let long = i64::read_into(buf)?;
+ Ok(ChunkSectionPos {
+ x: (long >> 42) as i32,
+ y: (long << 44 >> 44) as i32,
+ z: (long << 22 >> 42) as i32,
+ })
+ }
+}