aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf/definitions.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/definitions.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/definitions.rs')
-rw-r--r--azalea-protocol/src/mc_buf/definitions.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/azalea-protocol/src/mc_buf/definitions.rs b/azalea-protocol/src/mc_buf/definitions.rs
index a59fc574..3867b3fc 100644
--- a/azalea-protocol/src/mc_buf/definitions.rs
+++ b/azalea-protocol/src/mc_buf/definitions.rs
@@ -1,8 +1,9 @@
use crate::mc_buf::read::{McBufReadable, Readable};
use crate::mc_buf::write::{McBufWritable, Writable};
+use crate::mc_buf::McBufVarReadable;
use azalea_chat::component::Component;
use azalea_core::{BlockPos, Direction, Slot};
-use packet_macros::{McBufReadable, McBufWritable};
+use packet_macros::McBuf;
use std::io::{Read, Write};
use std::ops::Deref;
use uuid::Uuid;
@@ -32,7 +33,7 @@ impl From<&str> for UnsizedByteArray {
}
/// Represents Java's BitSet, a list of bits.
-#[derive(Debug, Clone, PartialEq, Eq, Hash, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash, McBuf)]
pub struct BitSet {
data: Vec<u64>,
}
@@ -159,7 +160,7 @@ impl McBufWritable for EntityDataValue {
}
}
-#[derive(Clone, Debug, Copy, McBufReadable, McBufWritable)]
+#[derive(Clone, Debug, Copy, McBuf)]
pub enum Pose {
Standing = 0,
FallFlying = 1,
@@ -171,7 +172,7 @@ pub enum Pose {
Dying = 7,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct VillagerData {
#[var]
type_: u32,
@@ -181,7 +182,7 @@ pub struct VillagerData {
level: u32,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct Particle {
#[var]
pub id: i32,
@@ -280,12 +281,12 @@ pub enum ParticleData {
Scrape,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct BlockParticle {
#[var]
pub block_state: i32,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct DustParticle {
/// Red value, 0-1
pub red: f32,
@@ -297,7 +298,7 @@ pub struct DustParticle {
pub scale: f32,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct DustColorTransitionParticle {
/// Red value, 0-1
pub from_red: f32,
@@ -315,12 +316,12 @@ pub struct DustColorTransitionParticle {
pub to_blue: f32,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct ItemParticle {
pub item: Slot,
}
-#[derive(Debug, Clone, McBufReadable, McBufWritable)]
+#[derive(Debug, Clone, McBuf)]
pub struct VibrationParticle {
pub origin: BlockPos,
pub position_type: String,
@@ -331,9 +332,8 @@ pub struct VibrationParticle {
pub ticks: u32,
}
-impl McBufReadable for ParticleData {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let id = buf.read_varint()?;
+impl ParticleData {
+ pub fn read_from_particle_id(buf: &mut impl Read, id: u32) -> Result<Self, String> {
Ok(match id {
0 => ParticleData::AmbientEntityEffect,
1 => ParticleData::AngryVillager,
@@ -428,6 +428,13 @@ impl McBufReadable for ParticleData {
}
}
+impl McBufReadable for ParticleData {
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ let id = u32::var_read_into(buf)?;
+ ParticleData::read_from_particle_id(buf, id)
+ }
+}
+
impl McBufWritable for ParticleData {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!()