mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
refactor(bedrock): Add PacketWrite impl for NbtCompound (#2992)
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use std::io::{Error, Write};
|
||||
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_nbt::{Nbt, compound::NbtCompound};
|
||||
use pumpkin_nbt::compound::NbtCompound;
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
|
||||
use crate::serial::PacketWrite;
|
||||
|
||||
/// Synchronizes the complete block-actor data for a block position.
|
||||
#[derive(PacketWrite)]
|
||||
#[packet(56)]
|
||||
pub struct CBlockActorData {
|
||||
pub position: BlockPos,
|
||||
@@ -20,18 +19,11 @@ impl CBlockActorData {
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketWrite for CBlockActorData {
|
||||
fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
|
||||
self.position.write(writer)?;
|
||||
writer.write_all(&Nbt::from(self.data.clone()).write_bedrock())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
|
||||
use pumpkin_nbt::deserializer::NbtReadHelperBedrock;
|
||||
use pumpkin_nbt::{Nbt, deserializer::NbtReadHelperBedrock};
|
||||
|
||||
use super::*;
|
||||
use crate::{Packet, serial::PacketWrite};
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::{
|
||||
net::SocketAddr,
|
||||
};
|
||||
|
||||
use pumpkin_nbt::{Nbt, NbtCompound};
|
||||
use pumpkin_util::{
|
||||
GameMode,
|
||||
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
|
||||
@@ -207,3 +208,9 @@ impl PacketWrite for Cow<'_, str> {
|
||||
self.as_ref().write(writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketWrite for NbtCompound {
|
||||
fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
|
||||
writer.write_all(&Nbt::from(self.clone()).write_bedrock())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user