mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Add valence_nbt to valence
This commit is contained in:
parent
8f3a46bccf
commit
c8cc7a021c
|
@ -17,14 +17,12 @@ async-trait = "0.1"
|
|||
base64 = "0.13"
|
||||
bitfield-struct = "0.1"
|
||||
bitvec = "1"
|
||||
bumpalo = "3.11.0"
|
||||
byteorder = "1"
|
||||
cesu8 = "1.1.0"
|
||||
cfb8 = "0.7"
|
||||
flate2 = "1"
|
||||
flume = "0.10"
|
||||
futures = "0.3"
|
||||
hematite-nbt = "0.5"
|
||||
log = "0.4"
|
||||
num = "0.4"
|
||||
paste = "1"
|
||||
|
@ -39,6 +37,7 @@ sha2 = "0.10"
|
|||
thiserror = "1"
|
||||
url = { version = "2.2.2", features = ["serde"] }
|
||||
uuid = "1"
|
||||
valence_nbt = { path = "valence_nbt" }
|
||||
vek = "0.15"
|
||||
|
||||
[dependencies.tokio]
|
||||
|
|
|
@ -125,7 +125,7 @@ impl Value {
|
|||
Value::Facing(_) => quote!(Facing),
|
||||
Value::OptionalUuid(_) => quote!(Option<Uuid>),
|
||||
Value::OptionalBlockState(_) => quote!(BlockState),
|
||||
Value::NbtCompound(_) => quote!(nbt::Blob),
|
||||
Value::NbtCompound(_) => quote!(crate::nbt::Compound),
|
||||
Value::Particle(_) => quote!(Particle),
|
||||
Value::VillagerData { .. } => quote!(VillagerData),
|
||||
Value::OptionalInt(_) => quote!(OptionalInt),
|
||||
|
@ -142,7 +142,7 @@ impl Value {
|
|||
Value::String(_) => quote!(&str),
|
||||
Value::TextComponent(_) => quote!(&Text),
|
||||
Value::OptionalTextComponent(_) => quote!(Option<&Text>),
|
||||
Value::NbtCompound(_) => quote!(&nbt::Blob),
|
||||
Value::NbtCompound(_) => quote!(&crate::nbt::Compound),
|
||||
_ => self.field_type(),
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl Value {
|
|||
}
|
||||
Value::OptionalUuid(_) => quote!(None), // TODO
|
||||
Value::OptionalBlockState(_) => quote!(BlockState::default()), // TODO
|
||||
Value::NbtCompound(_) => quote!(nbt::Blob::default()), // TODO
|
||||
Value::NbtCompound(_) => quote!(crate::nbt::Compound::default()), // TODO
|
||||
Value::Particle(p) => {
|
||||
let variant = ident(p.to_pascal_case());
|
||||
quote!(Particle::#variant)
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::dimension::DimensionId;
|
|||
use crate::protocol_inner::packets::s2c::play::{
|
||||
BlockUpdate, ChunkData, ChunkDataHeightmaps, ChunkSectionUpdate, S2cPlayPacket,
|
||||
};
|
||||
use crate::protocol_inner::{Encode, Nbt, VarInt, VarLong};
|
||||
use crate::protocol_inner::{Encode, NbtBridge, VarInt, VarLong};
|
||||
use crate::server::SharedServer;
|
||||
|
||||
/// A container for all [`Chunks`]s in a [`World`](crate::world::World).
|
||||
|
@ -311,7 +311,7 @@ impl<C: Config> Chunk<C> {
|
|||
ChunkData {
|
||||
chunk_x: pos.x,
|
||||
chunk_z: pos.z,
|
||||
heightmaps: Nbt(ChunkDataHeightmaps {
|
||||
heightmaps: NbtBridge(ChunkDataHeightmaps {
|
||||
motion_blocking: self.heightmap.clone(),
|
||||
}),
|
||||
blocks_and_biomes,
|
||||
|
|
|
@ -37,7 +37,7 @@ use crate::protocol_inner::packets::s2c::play::{
|
|||
PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn, PlayerSpawnPosition, RegistryCodec,
|
||||
Rotate, RotateAndMoveRelative, S2cPlayPacket, UnloadChunk, UpdateSubtitle, UpdateTitle,
|
||||
};
|
||||
use crate::protocol_inner::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
|
||||
use crate::protocol_inner::{BoundedInt, ByteAngle, NbtBridge, RawBytes, VarInt};
|
||||
use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer};
|
||||
use crate::slab_versioned::{Key, VersionedSlab};
|
||||
use crate::text::Text;
|
||||
|
@ -900,7 +900,7 @@ impl<C: Config> Client<C> {
|
|||
gamemode: self.new_game_mode,
|
||||
previous_gamemode: self.old_game_mode,
|
||||
dimension_names,
|
||||
registry_codec: Nbt(make_registry_codec(shared)),
|
||||
registry_codec: NbtBridge(make_registry_codec(shared)),
|
||||
dimension_type_name: ident!(
|
||||
"{LIBRARY_NAMESPACE}:dimension_type_{}",
|
||||
world.meta.dimension().0
|
||||
|
|
|
@ -128,7 +128,7 @@ pub use async_trait::async_trait;
|
|||
#[doc(inline)]
|
||||
pub use server::start_server;
|
||||
#[doc(inline)]
|
||||
pub use {uuid, vek};
|
||||
pub use {uuid, valence_nbt as nbt, vek};
|
||||
|
||||
pub mod biome;
|
||||
pub mod block;
|
||||
|
|
|
@ -14,6 +14,7 @@ pub use var_long::VarLong;
|
|||
use vek::{Vec2, Vec3, Vec4};
|
||||
|
||||
use crate::entity::EntityId;
|
||||
use crate::nbt;
|
||||
|
||||
mod byte_angle;
|
||||
pub mod codec;
|
||||
|
@ -503,32 +504,32 @@ impl Decode for Uuid {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for nbt::Blob {
|
||||
impl Encode for nbt::Compound {
|
||||
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
|
||||
Ok(nbt::to_writer(w, self, None)?)
|
||||
Ok(nbt::binary::to_writer(w, self)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for nbt::Blob {
|
||||
impl Decode for nbt::Compound {
|
||||
fn decode(r: &mut impl Read) -> anyhow::Result<Self> {
|
||||
Ok(nbt::from_reader(r)?)
|
||||
Ok(nbt::binary::from_reader(r)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type acting as a bridge between Serde and [Encode]/[Decode] through
|
||||
/// the NBT format.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash, Debug)]
|
||||
pub struct Nbt<T>(pub T);
|
||||
pub struct NbtBridge<T>(pub T);
|
||||
|
||||
impl<T: Serialize> Encode for Nbt<T> {
|
||||
impl<T: Serialize> Encode for NbtBridge<T> {
|
||||
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
|
||||
Ok(nbt::to_writer(w, &self.0, None)?)
|
||||
Ok(nbt::binary::to_writer(w, &self.0)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> Decode for Nbt<T> {
|
||||
impl<T: DeserializeOwned> Decode for NbtBridge<T> {
|
||||
fn decode(r: &mut impl Read) -> anyhow::Result<Self> {
|
||||
Ok(Self(nbt::from_reader(r)?))
|
||||
Ok(Self(nbt::binary::from_reader(r)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,10 @@ use vek::Vec3;
|
|||
// use {def_bitfield, def_enum, def_struct};
|
||||
use crate::block_pos::BlockPos;
|
||||
use crate::ident::Ident;
|
||||
use crate::nbt::Compound;
|
||||
use crate::protocol_inner::{
|
||||
BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, Nbt, RawBytes, VarInt,
|
||||
VarLong,
|
||||
BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, NbtBridge, RawBytes,
|
||||
VarInt, VarLong,
|
||||
};
|
||||
use crate::text::Text;
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ pub mod play {
|
|||
BlockEntityUpdate {
|
||||
location: BlockPos,
|
||||
kind: VarInt, // TODO: use enum here
|
||||
data: nbt::Blob,
|
||||
data: Compound,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ pub mod play {
|
|||
ChunkData {
|
||||
chunk_x: i32,
|
||||
chunk_z: i32,
|
||||
heightmaps: Nbt<ChunkDataHeightmaps>,
|
||||
heightmaps: NbtBridge<ChunkDataHeightmaps>,
|
||||
blocks_and_biomes: Vec<u8>,
|
||||
block_entities: Vec<ChunkDataBlockEntity>,
|
||||
trust_edges: bool,
|
||||
|
@ -309,7 +309,7 @@ pub mod play {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ChunkDataHeightmaps {
|
||||
#[serde(rename = "MOTION_BLOCKING", serialize_with = "nbt::i64_array")]
|
||||
#[serde(rename = "MOTION_BLOCKING", with = "crate::nbt::long_array")]
|
||||
pub motion_blocking: Vec<i64>,
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ pub mod play {
|
|||
packed_xz: i8,
|
||||
y: i16,
|
||||
kind: VarInt,
|
||||
data: nbt::Blob,
|
||||
data: Compound,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ pub mod play {
|
|||
gamemode: GameMode,
|
||||
previous_gamemode: GameMode,
|
||||
dimension_names: Vec<Ident>,
|
||||
registry_codec: Nbt<RegistryCodec>,
|
||||
registry_codec: NbtBridge<RegistryCodec>,
|
||||
/// The name of the dimension type being spawned into.
|
||||
dimension_type_name: Ident,
|
||||
/// The name of the dimension being spawned into.
|
||||
|
|
Loading…
Reference in a new issue