WritePacket for bevy_ecs::world::Mut<'_, T> {
fn write_packet_fallible(&mut self, packet: &P) -> anyhow::Result<()>
where
P: Packet + Encode,
@@ -236,11 +239,11 @@ impl WritePacket for Mut<'_, T> {
#[derive(Debug)]
pub struct PacketWriter<'a> {
pub buf: &'a mut Vec,
- pub threshold: Option,
+ pub threshold: CompressionThreshold,
}
impl<'a> PacketWriter<'a> {
- pub fn new(buf: &'a mut Vec, threshold: Option) -> Self {
+ pub fn new(buf: &'a mut Vec, threshold: CompressionThreshold) -> Self {
Self { buf, threshold }
}
}
diff --git a/crates/valence_core/src/game_mode.rs b/crates/valence_protocol/src/game_mode.rs
similarity index 83%
rename from crates/valence_core/src/game_mode.rs
rename to crates/valence_protocol/src/game_mode.rs
index c23c2a6a8..b6f061364 100644
--- a/crates/valence_core/src/game_mode.rs
+++ b/crates/valence_protocol/src/game_mode.rs
@@ -1,6 +1,6 @@
use bevy_ecs::prelude::*;
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Encode, Decode, Component)]
pub enum GameMode {
diff --git a/crates/valence_core/src/protocol/global_pos.rs b/crates/valence_protocol/src/global_pos.rs
similarity index 76%
rename from crates/valence_core/src/protocol/global_pos.rs
rename to crates/valence_protocol/src/global_pos.rs
index 2136b941b..37ae89956 100644
--- a/crates/valence_core/src/protocol/global_pos.rs
+++ b/crates/valence_protocol/src/global_pos.rs
@@ -1,8 +1,9 @@
use std::borrow::Cow;
+use valence_ident::Ident;
+
use crate::block_pos::BlockPos;
-use crate::ident::Ident;
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct GlobalPos<'a> {
diff --git a/crates/valence_core/src/hand.rs b/crates/valence_protocol/src/hand.rs
similarity index 75%
rename from crates/valence_core/src/hand.rs
rename to crates/valence_protocol/src/hand.rs
index 957a01cf5..b2536ddf2 100644
--- a/crates/valence_core/src/hand.rs
+++ b/crates/valence_protocol/src/hand.rs
@@ -1,4 +1,4 @@
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug, Encode, Decode)]
pub enum Hand {
diff --git a/crates/valence_core/src/protocol/impls.rs b/crates/valence_protocol/src/impls.rs
similarity index 87%
rename from crates/valence_core/src/protocol/impls.rs
rename to crates/valence_protocol/src/impls.rs
index e14bb2132..857634693 100644
--- a/crates/valence_core/src/protocol/impls.rs
+++ b/crates/valence_protocol/src/impls.rs
@@ -1,4 +1,4 @@
-//! [`Encode`] and [`Decode`] impls on foreign types.
+//! Implementations of [`Encode`] and [`Decode`] on foreign types.
use core::slice;
use std::borrow::Cow;
@@ -8,13 +8,18 @@ use std::io::Write;
use std::mem;
use std::mem::MaybeUninit;
use std::rc::Rc;
+use std::str::FromStr;
use std::sync::Arc;
-use anyhow::{ensure, Result};
+use anyhow::{ensure, Context, Result};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
-use glam::*;
use uuid::Uuid;
+use valence_generated::block::{BlockEntityKind, BlockKind, BlockState};
+use valence_generated::item::ItemKind;
+use valence_ident::{Ident, IdentError};
+use valence_math::*;
use valence_nbt::Compound;
+use valence_text::Text;
use super::var_int::VarInt;
use super::{Decode, Encode, MAX_PACKET_SIZE};
@@ -777,3 +782,93 @@ impl Decode<'_> for Compound {
Ok(Self::from_binary(r)?.0)
}
}
+
+impl Encode for Ident {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ self.as_ref().encode(w)
+ }
+}
+
+impl<'a, S> Decode<'a> for Ident
+where
+ S: Decode<'a>,
+ Ident: TryFrom,
+{
+ fn decode(r: &mut &'a [u8]) -> anyhow::Result {
+ Ok(Ident::try_from(S::decode(r)?)?)
+ }
+}
+
+impl Encode for Text {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ serde_json::to_string(self)
+ .context("encoding text JSON")?
+ .encode(w)
+ }
+}
+
+impl Decode<'_> for Text {
+ fn decode(r: &mut &[u8]) -> anyhow::Result {
+ let str = <&str>::decode(r)?;
+
+ Self::from_str(str).context("decoding text JSON")
+ }
+}
+
+impl Encode for BlockState {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ VarInt(self.to_raw() as i32).encode(w)
+ }
+}
+
+impl Decode<'_> for BlockState {
+ fn decode(r: &mut &[u8]) -> anyhow::Result {
+ let id = VarInt::decode(r)?.0;
+ let errmsg = "invalid block state ID";
+
+ BlockState::from_raw(id.try_into().context(errmsg)?).context(errmsg)
+ }
+}
+
+impl Encode for BlockKind {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ VarInt(self.to_raw() as i32).encode(w)
+ }
+}
+
+impl Decode<'_> for BlockKind {
+ fn decode(r: &mut &[u8]) -> anyhow::Result {
+ let id = VarInt::decode(r)?.0;
+ let errmsg = "invalid block kind ID";
+
+ BlockKind::from_raw(id.try_into().context(errmsg)?).context(errmsg)
+ }
+}
+
+impl Encode for BlockEntityKind {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ VarInt(self.id() as i32).encode(w)
+ }
+}
+
+impl<'a> Decode<'a> for BlockEntityKind {
+ fn decode(r: &mut &'a [u8]) -> anyhow::Result {
+ let id = VarInt::decode(r)?;
+ Self::from_id(id.0 as u32).with_context(|| format!("id {}", id.0))
+ }
+}
+
+impl Encode for ItemKind {
+ fn encode(&self, w: impl Write) -> anyhow::Result<()> {
+ VarInt(self.to_raw() as i32).encode(w)
+ }
+}
+
+impl Decode<'_> for ItemKind {
+ fn decode(r: &mut &[u8]) -> anyhow::Result {
+ let id = VarInt::decode(r)?.0;
+ let errmsg = "invalid item ID";
+
+ ItemKind::from_raw(id.try_into().context(errmsg)?).context(errmsg)
+ }
+}
diff --git a/crates/valence_core/src/item.rs b/crates/valence_protocol/src/item.rs
similarity index 69%
rename from crates/valence_core/src/item.rs
rename to crates/valence_protocol/src/item.rs
index 9d3814a28..ab28bfeb7 100644
--- a/crates/valence_core/src/item.rs
+++ b/crates/valence_protocol/src/item.rs
@@ -1,13 +1,12 @@
use std::io::Write;
-use anyhow::{ensure, Context};
+use anyhow::ensure;
+pub use valence_generated::item::ItemKind;
use valence_nbt::Compound;
-use crate::protocol::var_int::VarInt;
-use crate::protocol::{Decode, Encode};
-
-include!(concat!(env!("OUT_DIR"), "/item.rs"));
+use crate::{Decode, Encode};
+/// A stack of items in an inventory.
#[derive(Clone, PartialEq, Debug)]
pub struct ItemStack {
pub item: ItemKind,
@@ -115,52 +114,15 @@ impl Decode<'_> for Option {
}
}
-impl Encode for ItemKind {
- fn encode(&self, w: impl Write) -> anyhow::Result<()> {
- VarInt(self.to_raw() as i32).encode(w)
- }
-}
-
-impl Decode<'_> for ItemKind {
- fn decode(r: &mut &[u8]) -> anyhow::Result {
- let id = VarInt::decode(r)?.0;
- let errmsg = "invalid item ID";
-
- ItemKind::from_raw(id.try_into().context(errmsg)?).context(errmsg)
- }
-}
-
-/*
#[cfg(test)]
mod tests {
use super::*;
- use crate::block::BlockKind;
-
- #[test]
- fn item_kind_to_block_kind() {
- assert_eq!(
- ItemKind::Cauldron.to_block_kind(),
- Some(BlockKind::Cauldron)
- );
- }
-
- #[test]
- fn block_state_to_item() {
- assert_eq!(BlockKind::Torch.to_item_kind(), ItemKind::Torch);
- assert_eq!(BlockKind::WallTorch.to_item_kind(), ItemKind::Torch);
-
- assert_eq!(BlockKind::Cauldron.to_item_kind(), ItemKind::Cauldron);
- assert_eq!(BlockKind::LavaCauldron.to_item_kind(), ItemKind::Cauldron);
-
- assert_eq!(BlockKind::NetherPortal.to_item_kind(), ItemKind::Air);
- }
#[test]
fn item_stack_clamps_count() {
let mut stack = ItemStack::new(ItemKind::Stone, 200, None);
- assert_eq!(stack.count, STACK_MAX);
+ assert_eq!(stack.count, ItemStack::STACK_MAX);
stack.set_count(201);
- assert_eq!(stack.count, STACK_MAX);
+ assert_eq!(stack.count, ItemStack::STACK_MAX);
}
}
-*/
diff --git a/crates/valence_protocol/src/lib.rs b/crates/valence_protocol/src/lib.rs
new file mode 100644
index 000000000..a551e35be
--- /dev/null
+++ b/crates/valence_protocol/src/lib.rs
@@ -0,0 +1,451 @@
+#![doc = include_str!("../README.md")]
+#![deny(
+ rustdoc::broken_intra_doc_links,
+ rustdoc::private_intra_doc_links,
+ rustdoc::missing_crate_level_docs,
+ rustdoc::invalid_codeblock_attributes,
+ rustdoc::invalid_rust_codeblocks,
+ rustdoc::bare_urls,
+ rustdoc::invalid_html_tags
+)]
+#![warn(
+ trivial_casts,
+ trivial_numeric_casts,
+ unused_lifetimes,
+ unused_import_braces,
+ unreachable_pub,
+ clippy::dbg_macro
+)]
+
+/// Used only by macros. Not public API.
+#[doc(hidden)]
+pub mod __private {
+ pub use anyhow::{anyhow, bail, ensure, Context, Result};
+
+ pub use crate::var_int::VarInt;
+ pub use crate::{Decode, Encode, Packet};
+}
+
+// This allows us to use our own proc macros internally.
+extern crate self as valence_protocol;
+
+mod array;
+mod block_pos;
+mod byte_angle;
+mod chunk_pos;
+pub mod decode;
+mod difficulty;
+mod direction;
+pub mod encode;
+mod game_mode;
+mod global_pos;
+mod hand;
+mod impls;
+pub mod item;
+pub mod packets;
+mod player_textures;
+mod property;
+mod raw;
+pub mod sound;
+pub mod var_int;
+mod var_long;
+
+use std::io::Write;
+
+use anyhow::Context;
+pub use array::LengthPrefixedArray;
+pub use block::{BlockKind, BlockState};
+pub use block_pos::BlockPos;
+pub use byte_angle::ByteAngle;
+pub use chunk_pos::ChunkPos;
+pub use decode::PacketDecoder;
+pub use difficulty::Difficulty;
+pub use direction::Direction;
+pub use encode::{PacketEncoder, WritePacket};
+pub use game_mode::GameMode;
+pub use global_pos::GlobalPos;
+pub use hand::Hand;
+pub use ident::ident;
+pub use item::{ItemKind, ItemStack};
+pub use packets::play::particle_s2c::Particle;
+pub use player_textures::PlayerTextures;
+pub use property::Property;
+pub use raw::RawBytes;
+pub use sound::Sound;
+pub use text::Text;
+pub use valence_generated::{block, packet_id};
+pub use valence_ident::Ident;
+pub use valence_protocol_macros::{Decode, Encode, Packet};
+pub use var_int::VarInt;
+pub use var_long::VarLong;
+pub use {
+ anyhow, bytes, uuid, valence_ident as ident, valence_math as math, valence_nbt as nbt,
+ valence_text as text,
+};
+
+/// The maximum number of bytes in a single Minecraft packet.
+pub const MAX_PACKET_SIZE: i32 = 2097152;
+
+/// The Minecraft protocol version this library currently targets.
+pub const PROTOCOL_VERSION: i32 = 763;
+
+/// The stringified name of the Minecraft version this library currently
+/// targets.
+pub const MINECRAFT_VERSION: &str = "1.20.1";
+
+/// Type alias for the compression threshold.
+///
+/// For a compression threshold of `Some(N)`, packets with encoded lengths >=
+/// `N` are compressed while all others are not. `None` disables compression
+/// completely.
+pub type CompressionThreshold = Option;
+
+/// The `Encode` trait allows objects to be written to the Minecraft protocol.
+/// It is the inverse of [`Decode`].
+///
+/// # Deriving
+///
+/// This trait can be implemented automatically for structs and enums by using
+/// the [`Encode`][macro] derive macro. All components of the type must
+/// implement `Encode`. Components are encoded in the order they appear in the
+/// type definition.
+///
+/// For enums, the variant to encode is marked by a leading [`VarInt`]
+/// discriminant (tag). The discriminant value can be changed using the
+/// `#[packet(tag = ...)]` attribute on the variant in question. Discriminant
+/// values are assigned to variants using rules similar to regular enum
+/// discriminants.
+///
+/// ```
+/// use valence_protocol::Encode;
+///
+/// #[derive(Encode)]
+/// struct MyStruct<'a> {
+/// first: i32,
+/// second: &'a str,
+/// third: [f64; 3],
+/// }
+///
+/// #[derive(Encode)]
+/// enum MyEnum {
+/// First, // tag = 0
+/// Second, // tag = 1
+/// #[packet(tag = 25)]
+/// Third, // tag = 25
+/// Fourth, // tag = 26
+/// }
+///
+/// let value = MyStruct {
+/// first: 10,
+/// second: "hello",
+/// third: [1.5, 3.14, 2.718],
+/// };
+///
+/// let mut buf = vec![];
+/// value.encode(&mut buf).unwrap();
+///
+/// println!("{buf:?}");
+/// ```
+///
+/// [macro]: valence_protocol_macros::Encode
+/// [`VarInt`]: var_int::VarInt
+pub trait Encode {
+ /// Writes this object to the provided writer.
+ ///
+ /// If this type also implements [`Decode`] then successful calls to this
+ /// function returning `Ok(())` must always successfully [`decode`] using
+ /// the data that was written to the writer. The exact number of bytes
+ /// that were originally written must be consumed during the decoding.
+ ///
+ /// [`decode`]: Decode::decode
+ fn encode(&self, w: impl Write) -> anyhow::Result<()>;
+
+ /// Like [`Encode::encode`], except that a whole slice of values is encoded.
+ ///
+ /// This method must be semantically equivalent to encoding every element of
+ /// the slice in sequence with no leading length prefix (which is exactly
+ /// what the default implementation does), but a more efficient
+ /// implementation may be used.
+ ///
+ /// This method is important for some types like `u8` where the entire slice
+ /// can be encoded in a single call to [`write_all`]. Because impl
+ /// specialization is unavailable in stable Rust at the time of writing,
+ /// we must make the slice specialization part of this trait.
+ ///
+ /// [`write_all`]: Write::write_all
+ fn encode_slice(slice: &[Self], mut w: impl Write) -> anyhow::Result<()>
+ where
+ Self: Sized,
+ {
+ for value in slice {
+ value.encode(&mut w)?;
+ }
+
+ Ok(())
+ }
+}
+
+/// The `Decode` trait allows objects to be read from the Minecraft protocol. It
+/// is the inverse of [`Encode`].
+///
+/// `Decode` is parameterized by a lifetime. This allows the decoded value to
+/// borrow data from the byte slice it was read from.
+///
+/// # Deriving
+///
+/// This trait can be implemented automatically for structs and enums by using
+/// the [`Decode`][macro] derive macro. All components of the type must
+/// implement `Decode`. Components are decoded in the order they appear in the
+/// type definition.
+///
+/// For enums, the variant to decode is determined by a leading [`VarInt`]
+/// discriminant (tag). The discriminant value can be changed using the
+/// `#[packet(tag = ...)]` attribute on the variant in question. Discriminant
+/// values are assigned to variants using rules similar to regular enum
+/// discriminants.
+///
+/// ```
+/// use valence_protocol::Decode;
+///
+/// #[derive(PartialEq, Debug, Decode)]
+/// struct MyStruct {
+/// first: i32,
+/// second: MyEnum,
+/// }
+///
+/// #[derive(PartialEq, Debug, Decode)]
+/// enum MyEnum {
+/// First, // tag = 0
+/// Second, // tag = 1
+/// #[packet(tag = 25)]
+/// Third, // tag = 25
+/// Fourth, // tag = 26
+/// }
+///
+/// let mut r: &[u8] = &[0, 0, 0, 0, 26];
+///
+/// let value = MyStruct::decode(&mut r).unwrap();
+/// let expected = MyStruct {
+/// first: 0,
+/// second: MyEnum::Fourth,
+/// };
+///
+/// assert_eq!(value, expected);
+/// assert!(r.is_empty());
+/// ```
+///
+/// [macro]: valence_protocol_macros::Decode
+/// [`VarInt`]: var_int::VarInt
+pub trait Decode<'a>: Sized {
+ /// Reads this object from the provided byte slice.
+ ///
+ /// Implementations of `Decode` are expected to shrink the slice from the
+ /// front as bytes are read.
+ fn decode(r: &mut &'a [u8]) -> anyhow::Result;
+}
+
+/// Types considered to be Minecraft packets.
+///
+/// In serialized form, a packet begins with a [`VarInt`] packet ID followed by
+/// the body of the packet. If present, the implementations of [`Encode`] and
+/// [`Decode`] on `Self` are expected to only encode/decode the _body_ of this
+/// packet without the leading ID.
+pub trait Packet: std::fmt::Debug {
+ /// The leading VarInt ID of this packet.
+ const ID: i32;
+ /// The name of this packet for debugging purposes.
+ const NAME: &'static str;
+ /// The side this packet is intended for.
+ const SIDE: PacketSide;
+ /// The state in which this packet is used.
+ const STATE: PacketState;
+
+ /// Encodes this packet's VarInt ID first, followed by the packet's body.
+ fn encode_with_id(&self, mut w: impl Write) -> anyhow::Result<()>
+ where
+ Self: Encode,
+ {
+ VarInt(Self::ID)
+ .encode(&mut w)
+ .context("failed to encode packet ID")?;
+
+ self.encode(w)
+ }
+}
+
+/// The side a packet is intended for.
+#[derive(Copy, Clone, PartialEq, Eq)]
+pub enum PacketSide {
+ /// Server -> Client
+ Clientbound,
+ /// Client -> Server
+ Serverbound,
+}
+
+/// The statein which a packet is used.
+#[derive(Copy, Clone, PartialEq, Eq)]
+pub enum PacketState {
+ Handshaking,
+ Status,
+ Login,
+ Play,
+}
+
+#[allow(dead_code)]
+#[cfg(test)]
+mod tests {
+ use std::borrow::Cow;
+
+ use bytes::BytesMut;
+
+ use super::*;
+ use crate::block_pos::BlockPos;
+ use crate::decode::PacketDecoder;
+ use crate::encode::PacketEncoder;
+ use crate::hand::Hand;
+ use crate::item::{ItemKind, ItemStack};
+ use crate::text::{IntoText, Text};
+ use crate::var_int::VarInt;
+ use crate::var_long::VarLong;
+ use crate::Ident;
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 1, side = PacketSide::Clientbound)]
+ struct RegularStruct {
+ foo: i32,
+ bar: bool,
+ baz: f64,
+ }
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 2, side = PacketSide::Clientbound)]
+ struct UnitStruct;
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 3, side = PacketSide::Clientbound)]
+ struct EmptyStruct {}
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 4, side = PacketSide::Clientbound)]
+ struct TupleStruct(i32, bool, f64);
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 5, side = PacketSide::Clientbound)]
+ struct StructWithGenerics<'z, T = ()> {
+ foo: &'z str,
+ bar: T,
+ }
+
+ #[derive(Encode, Decode, Packet, Debug)]
+ #[packet(id = 6, side = PacketSide::Clientbound)]
+ struct TupleStructWithGenerics<'z, T = ()>(&'z str, i32, T);
+
+ #[allow(unconditional_recursion, clippy::extra_unused_type_parameters)]
+ fn assert_has_impls<'a, T>()
+ where
+ T: Encode + Decode<'a> + Packet,
+ {
+ assert_has_impls::();
+ assert_has_impls::();
+ assert_has_impls::();
+ assert_has_impls::();
+ assert_has_impls::();
+ assert_has_impls::();
+ }
+
+ #[test]
+ fn packet_name() {
+ assert_eq!(RegularStruct::NAME, "RegularStruct");
+ assert_eq!(UnitStruct::NAME, "UnitStruct");
+ assert_eq!(StructWithGenerics::<()>::NAME, "StructWithGenerics");
+ }
+
+ #[cfg(feature = "encryption")]
+ const CRYPT_KEY: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
+
+ #[derive(PartialEq, Debug, Encode, Decode, Packet)]
+ #[packet(id = 42, side = PacketSide::Clientbound)]
+ struct TestPacket<'a> {
+ a: bool,
+ b: u8,
+ c: i32,
+ d: f32,
+ e: f64,
+ f: BlockPos,
+ g: Hand,
+ h: Ident>,
+ i: Option,
+ j: Text,
+ k: VarInt,
+ l: VarLong,
+ m: &'a str,
+ n: &'a [u8; 10],
+ o: [u128; 3],
+ }
+
+ impl<'a> TestPacket<'a> {
+ fn new(string: &'a str) -> Self {
+ Self {
+ a: true,
+ b: 12,
+ c: -999,
+ d: 5.001,
+ e: 1e10,
+ f: BlockPos::new(1, 2, 3),
+ g: Hand::Off,
+ h: Ident::new("minecraft:whatever").unwrap(),
+ i: Some(ItemStack::new(ItemKind::WoodenSword, 12, None)),
+ j: "my ".into_text() + "fancy".italic() + " text",
+ k: VarInt(123),
+ l: VarLong(456),
+ m: string,
+ n: &[7; 10],
+ o: [123456789; 3],
+ }
+ }
+ }
+
+ fn check_test_packet(dec: &mut PacketDecoder, string: &str) {
+ let frame = dec.try_next_packet().unwrap().unwrap();
+
+ let pkt = frame.decode::().unwrap();
+
+ assert_eq!(&pkt, &TestPacket::new(string));
+ }
+
+ #[test]
+ fn packets_round_trip() {
+ let mut buf = BytesMut::new();
+
+ let mut enc = PacketEncoder::new();
+
+ enc.append_packet(&TestPacket::new("first")).unwrap();
+ #[cfg(feature = "compression")]
+ enc.set_compression(Some(0));
+ enc.append_packet(&TestPacket::new("second")).unwrap();
+ buf.unsplit(enc.take());
+ #[cfg(feature = "encryption")]
+ enc.enable_encryption(&CRYPT_KEY);
+ enc.append_packet(&TestPacket::new("third")).unwrap();
+ enc.prepend_packet(&TestPacket::new("fourth")).unwrap();
+
+ buf.unsplit(enc.take());
+
+ let mut dec = PacketDecoder::new();
+
+ dec.queue_bytes(buf);
+
+ check_test_packet(&mut dec, "first");
+
+ #[cfg(feature = "compression")]
+ dec.set_compression(Some(0));
+
+ check_test_packet(&mut dec, "second");
+
+ #[cfg(feature = "encryption")]
+ dec.enable_encryption(&CRYPT_KEY);
+
+ check_test_packet(&mut dec, "fourth");
+ check_test_packet(&mut dec, "third");
+ }
+}
diff --git a/crates/valence_protocol/src/packets.rs b/crates/valence_protocol/src/packets.rs
new file mode 100644
index 000000000..c0708ff4f
--- /dev/null
+++ b/crates/valence_protocol/src/packets.rs
@@ -0,0 +1,22 @@
+//! All of Minecraft's network packets.
+//!
+//! Packets are grouped in submodules according to the protocol stage they're
+//! used in. Names are derived from the FabricMC Yarn mappings for consistency.
+
+use std::borrow::Cow;
+use std::io::Write;
+
+use anyhow::bail;
+use uuid::Uuid;
+use valence_generated::packet_id;
+
+use crate::property::Property;
+use crate::raw::RawBytes;
+use crate::text::Text;
+use crate::var_int::VarInt;
+use crate::{Decode, Encode, Ident, Packet, PacketState};
+
+pub mod handshaking;
+pub mod login;
+pub mod play;
+pub mod status;
diff --git a/crates/valence_packet/src/packets/handshaking.rs b/crates/valence_protocol/src/packets/handshaking.rs
similarity index 100%
rename from crates/valence_packet/src/packets/handshaking.rs
rename to crates/valence_protocol/src/packets/handshaking.rs
diff --git a/crates/valence_packet/src/packets/handshaking/handshake_c2s.rs b/crates/valence_protocol/src/packets/handshaking/handshake_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/handshaking/handshake_c2s.rs
rename to crates/valence_protocol/src/packets/handshaking/handshake_c2s.rs
diff --git a/crates/valence_packet/src/packets/login.rs b/crates/valence_protocol/src/packets/login.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login.rs
rename to crates/valence_protocol/src/packets/login.rs
diff --git a/crates/valence_packet/src/packets/login/login_compression_s2c.rs b/crates/valence_protocol/src/packets/login/login_compression_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_compression_s2c.rs
rename to crates/valence_protocol/src/packets/login/login_compression_s2c.rs
diff --git a/crates/valence_packet/src/packets/login/login_disconnect_s2c.rs b/crates/valence_protocol/src/packets/login/login_disconnect_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_disconnect_s2c.rs
rename to crates/valence_protocol/src/packets/login/login_disconnect_s2c.rs
diff --git a/crates/valence_packet/src/packets/login/login_hello_c2s.rs b/crates/valence_protocol/src/packets/login/login_hello_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_hello_c2s.rs
rename to crates/valence_protocol/src/packets/login/login_hello_c2s.rs
diff --git a/crates/valence_packet/src/packets/login/login_hello_s2c.rs b/crates/valence_protocol/src/packets/login/login_hello_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_hello_s2c.rs
rename to crates/valence_protocol/src/packets/login/login_hello_s2c.rs
diff --git a/crates/valence_packet/src/packets/login/login_key_c2s.rs b/crates/valence_protocol/src/packets/login/login_key_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_key_c2s.rs
rename to crates/valence_protocol/src/packets/login/login_key_c2s.rs
diff --git a/crates/valence_packet/src/packets/login/login_query_request_s2c.rs b/crates/valence_protocol/src/packets/login/login_query_request_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_query_request_s2c.rs
rename to crates/valence_protocol/src/packets/login/login_query_request_s2c.rs
diff --git a/crates/valence_packet/src/packets/login/login_query_response_c2s.rs b/crates/valence_protocol/src/packets/login/login_query_response_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_query_response_c2s.rs
rename to crates/valence_protocol/src/packets/login/login_query_response_c2s.rs
diff --git a/crates/valence_packet/src/packets/login/login_success_s2c.rs b/crates/valence_protocol/src/packets/login/login_success_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/login/login_success_s2c.rs
rename to crates/valence_protocol/src/packets/login/login_success_s2c.rs
diff --git a/crates/valence_packet/src/packets/play.rs b/crates/valence_protocol/src/packets/play.rs
similarity index 96%
rename from crates/valence_packet/src/packets/play.rs
rename to crates/valence_protocol/src/packets/play.rs
index 50bd28844..ed5f7dbd4 100644
--- a/crates/valence_packet/src/packets/play.rs
+++ b/crates/valence_protocol/src/packets/play.rs
@@ -1,19 +1,19 @@
use bitfield_struct::bitfield;
use byteorder::WriteBytesExt;
-use glam::{DVec3, IVec3, Vec3};
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::ChunkPos;
-use valence_core::difficulty::Difficulty;
-use valence_core::direction::Direction;
-use valence_core::game_mode::GameMode;
-use valence_core::hand::Hand;
-use valence_core::item::ItemStack;
-use valence_core::protocol::byte_angle::ByteAngle;
-use valence_core::protocol::global_pos::GlobalPos;
-use valence_core::protocol::var_long::VarLong;
+use valence_math::{DVec3, IVec3, Vec3};
use valence_nbt::Compound;
use super::*;
+use crate::block_pos::BlockPos;
+use crate::byte_angle::ByteAngle;
+use crate::chunk_pos::ChunkPos;
+use crate::difficulty::Difficulty;
+use crate::direction::Direction;
+use crate::game_mode::GameMode;
+use crate::global_pos::GlobalPos;
+use crate::hand::Hand;
+use crate::item::ItemStack;
+use crate::var_long::VarLong;
pub mod advancement_tab_c2s;
pub use advancement_tab_c2s::AdvancementTabC2s;
diff --git a/crates/valence_packet/src/packets/play/advancement_tab_c2s.rs b/crates/valence_protocol/src/packets/play/advancement_tab_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/advancement_tab_c2s.rs
rename to crates/valence_protocol/src/packets/play/advancement_tab_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/advancement_update_s2c.rs b/crates/valence_protocol/src/packets/play/advancement_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/advancement_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/advancement_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/block_breaking_progress_s2c.rs b/crates/valence_protocol/src/packets/play/block_breaking_progress_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/block_breaking_progress_s2c.rs
rename to crates/valence_protocol/src/packets/play/block_breaking_progress_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/block_entity_update_s2c.rs b/crates/valence_protocol/src/packets/play/block_entity_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/block_entity_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/block_entity_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/block_event_s2c.rs b/crates/valence_protocol/src/packets/play/block_event_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/block_event_s2c.rs
rename to crates/valence_protocol/src/packets/play/block_event_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/block_update_s2c.rs b/crates/valence_protocol/src/packets/play/block_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/block_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/block_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/boat_paddle_state_c2s.rs b/crates/valence_protocol/src/packets/play/boat_paddle_state_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/boat_paddle_state_c2s.rs
rename to crates/valence_protocol/src/packets/play/boat_paddle_state_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/book_update_c2s.rs b/crates/valence_protocol/src/packets/play/book_update_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/book_update_c2s.rs
rename to crates/valence_protocol/src/packets/play/book_update_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/boss_bar_s2c.rs b/crates/valence_protocol/src/packets/play/boss_bar_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/boss_bar_s2c.rs
rename to crates/valence_protocol/src/packets/play/boss_bar_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/bundle_splitter_s2c.rs b/crates/valence_protocol/src/packets/play/bundle_splitter_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/bundle_splitter_s2c.rs
rename to crates/valence_protocol/src/packets/play/bundle_splitter_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/button_click_c2s.rs b/crates/valence_protocol/src/packets/play/button_click_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/button_click_c2s.rs
rename to crates/valence_protocol/src/packets/play/button_click_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/chat_message_c2s.rs b/crates/valence_protocol/src/packets/play/chat_message_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chat_message_c2s.rs
rename to crates/valence_protocol/src/packets/play/chat_message_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/chat_message_s2c.rs b/crates/valence_protocol/src/packets/play/chat_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chat_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/chat_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/chat_suggestions_s2c.rs b/crates/valence_protocol/src/packets/play/chat_suggestions_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chat_suggestions_s2c.rs
rename to crates/valence_protocol/src/packets/play/chat_suggestions_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/chunk_biome_data_s2c.rs b/crates/valence_protocol/src/packets/play/chunk_biome_data_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chunk_biome_data_s2c.rs
rename to crates/valence_protocol/src/packets/play/chunk_biome_data_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/chunk_data_s2c.rs b/crates/valence_protocol/src/packets/play/chunk_data_s2c.rs
similarity index 93%
rename from crates/valence_packet/src/packets/play/chunk_data_s2c.rs
rename to crates/valence_protocol/src/packets/play/chunk_data_s2c.rs
index 6d7226fc2..91617359b 100644
--- a/crates/valence_packet/src/packets/play/chunk_data_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/chunk_data_s2c.rs
@@ -1,6 +1,5 @@
-use valence_core::protocol::array::LengthPrefixedArray;
-
use super::*;
+use crate::array::LengthPrefixedArray;
#[derive(Clone, Debug, Encode, Decode, Packet)]
#[packet(id = packet_id::CHUNK_DATA_S2C)]
diff --git a/crates/valence_packet/src/packets/play/chunk_delta_update_s2c.rs b/crates/valence_protocol/src/packets/play/chunk_delta_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chunk_delta_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/chunk_delta_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/chunk_load_distance_s2c.rs b/crates/valence_protocol/src/packets/play/chunk_load_distance_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chunk_load_distance_s2c.rs
rename to crates/valence_protocol/src/packets/play/chunk_load_distance_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/chunk_render_distance_center_s2c.rs b/crates/valence_protocol/src/packets/play/chunk_render_distance_center_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/chunk_render_distance_center_s2c.rs
rename to crates/valence_protocol/src/packets/play/chunk_render_distance_center_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/clear_title_s2c.rs b/crates/valence_protocol/src/packets/play/clear_title_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/clear_title_s2c.rs
rename to crates/valence_protocol/src/packets/play/clear_title_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/click_slot_c2s.rs b/crates/valence_protocol/src/packets/play/click_slot_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/click_slot_c2s.rs
rename to crates/valence_protocol/src/packets/play/click_slot_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/client_command_c2s.rs b/crates/valence_protocol/src/packets/play/client_command_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/client_command_c2s.rs
rename to crates/valence_protocol/src/packets/play/client_command_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/client_settings_c2s.rs b/crates/valence_protocol/src/packets/play/client_settings_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/client_settings_c2s.rs
rename to crates/valence_protocol/src/packets/play/client_settings_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/client_status_c2s.rs b/crates/valence_protocol/src/packets/play/client_status_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/client_status_c2s.rs
rename to crates/valence_protocol/src/packets/play/client_status_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/close_handled_screen_c2s.rs b/crates/valence_protocol/src/packets/play/close_handled_screen_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/close_handled_screen_c2s.rs
rename to crates/valence_protocol/src/packets/play/close_handled_screen_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/close_screen_s2c.rs b/crates/valence_protocol/src/packets/play/close_screen_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/close_screen_s2c.rs
rename to crates/valence_protocol/src/packets/play/close_screen_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/command_execution_c2s.rs b/crates/valence_protocol/src/packets/play/command_execution_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/command_execution_c2s.rs
rename to crates/valence_protocol/src/packets/play/command_execution_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/command_suggestions_s2c.rs b/crates/valence_protocol/src/packets/play/command_suggestions_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/command_suggestions_s2c.rs
rename to crates/valence_protocol/src/packets/play/command_suggestions_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/command_tree_s2c.rs b/crates/valence_protocol/src/packets/play/command_tree_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/command_tree_s2c.rs
rename to crates/valence_protocol/src/packets/play/command_tree_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/cooldown_update_s2c.rs b/crates/valence_protocol/src/packets/play/cooldown_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/cooldown_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/cooldown_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/craft_failed_response_s2c.rs b/crates/valence_protocol/src/packets/play/craft_failed_response_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/craft_failed_response_s2c.rs
rename to crates/valence_protocol/src/packets/play/craft_failed_response_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/craft_request_c2s.rs b/crates/valence_protocol/src/packets/play/craft_request_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/craft_request_c2s.rs
rename to crates/valence_protocol/src/packets/play/craft_request_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/creative_inventory_action_c2s.rs b/crates/valence_protocol/src/packets/play/creative_inventory_action_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/creative_inventory_action_c2s.rs
rename to crates/valence_protocol/src/packets/play/creative_inventory_action_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/custom_payload_c2s.rs b/crates/valence_protocol/src/packets/play/custom_payload_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/custom_payload_c2s.rs
rename to crates/valence_protocol/src/packets/play/custom_payload_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/custom_payload_s2c.rs b/crates/valence_protocol/src/packets/play/custom_payload_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/custom_payload_s2c.rs
rename to crates/valence_protocol/src/packets/play/custom_payload_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/damage_tilt_s2c.rs b/crates/valence_protocol/src/packets/play/damage_tilt_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/damage_tilt_s2c.rs
rename to crates/valence_protocol/src/packets/play/damage_tilt_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/death_message_s2c.rs b/crates/valence_protocol/src/packets/play/death_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/death_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/death_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/difficulty_s2c.rs b/crates/valence_protocol/src/packets/play/difficulty_s2c.rs
similarity index 66%
rename from crates/valence_packet/src/packets/play/difficulty_s2c.rs
rename to crates/valence_protocol/src/packets/play/difficulty_s2c.rs
index b3d298587..ba9a521a9 100644
--- a/crates/valence_packet/src/packets/play/difficulty_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/difficulty_s2c.rs
@@ -1,6 +1,6 @@
use super::*;
-#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Encode, Decode, Packet)]
#[packet(id = packet_id::DIFFICULTY_S2C)]
pub struct DifficultyS2c {
pub difficulty: Difficulty,
diff --git a/crates/valence_packet/src/packets/play/disconnect_s2c.rs b/crates/valence_protocol/src/packets/play/disconnect_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/disconnect_s2c.rs
rename to crates/valence_protocol/src/packets/play/disconnect_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/end_combat_s2c.rs b/crates/valence_protocol/src/packets/play/end_combat_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/end_combat_s2c.rs
rename to crates/valence_protocol/src/packets/play/end_combat_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/enter_combat_s2c.rs b/crates/valence_protocol/src/packets/play/enter_combat_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/enter_combat_s2c.rs
rename to crates/valence_protocol/src/packets/play/enter_combat_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entities_destroy_s2c.rs b/crates/valence_protocol/src/packets/play/entities_destroy_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entities_destroy_s2c.rs
rename to crates/valence_protocol/src/packets/play/entities_destroy_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_animation_s2c.rs b/crates/valence_protocol/src/packets/play/entity_animation_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_animation_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_animation_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_attach_s2c.rs b/crates/valence_protocol/src/packets/play/entity_attach_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_attach_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_attach_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_attributes_s2c.rs b/crates/valence_protocol/src/packets/play/entity_attributes_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_attributes_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_attributes_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_damage_s2c.rs b/crates/valence_protocol/src/packets/play/entity_damage_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_damage_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_damage_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_equipment_update_s2c.rs b/crates/valence_protocol/src/packets/play/entity_equipment_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_equipment_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_equipment_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_passengers_set_s2c.rs b/crates/valence_protocol/src/packets/play/entity_passengers_set_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_passengers_set_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_passengers_set_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_position_s2c.rs b/crates/valence_protocol/src/packets/play/entity_position_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_position_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_position_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_set_head_yaw_s2c.rs b/crates/valence_protocol/src/packets/play/entity_set_head_yaw_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_set_head_yaw_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_set_head_yaw_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_spawn_s2c.rs b/crates/valence_protocol/src/packets/play/entity_spawn_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_spawn_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_spawn_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_status_effect_s2c.rs b/crates/valence_protocol/src/packets/play/entity_status_effect_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_status_effect_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_status_effect_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_status_s2c.rs b/crates/valence_protocol/src/packets/play/entity_status_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_status_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_status_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_tracker_update_s2c.rs b/crates/valence_protocol/src/packets/play/entity_tracker_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_tracker_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_tracker_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/entity_velocity_update_s2c.rs b/crates/valence_protocol/src/packets/play/entity_velocity_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/entity_velocity_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/entity_velocity_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/experience_bar_update_s2c.rs b/crates/valence_protocol/src/packets/play/experience_bar_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/experience_bar_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/experience_bar_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/experience_orb_spawn_s2c.rs b/crates/valence_protocol/src/packets/play/experience_orb_spawn_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/experience_orb_spawn_s2c.rs
rename to crates/valence_protocol/src/packets/play/experience_orb_spawn_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/explosion_s2c.rs b/crates/valence_protocol/src/packets/play/explosion_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/explosion_s2c.rs
rename to crates/valence_protocol/src/packets/play/explosion_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/features_s2c.rs b/crates/valence_protocol/src/packets/play/features_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/features_s2c.rs
rename to crates/valence_protocol/src/packets/play/features_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/full_c2s.rs b/crates/valence_protocol/src/packets/play/full_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/full_c2s.rs
rename to crates/valence_protocol/src/packets/play/full_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/game_join_s2c.rs b/crates/valence_protocol/src/packets/play/game_join_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/game_join_s2c.rs
rename to crates/valence_protocol/src/packets/play/game_join_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/game_message_s2c.rs b/crates/valence_protocol/src/packets/play/game_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/game_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/game_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/game_state_change_s2c.rs b/crates/valence_protocol/src/packets/play/game_state_change_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/game_state_change_s2c.rs
rename to crates/valence_protocol/src/packets/play/game_state_change_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/hand_swing_c2s.rs b/crates/valence_protocol/src/packets/play/hand_swing_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/hand_swing_c2s.rs
rename to crates/valence_protocol/src/packets/play/hand_swing_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/health_update_s2c.rs b/crates/valence_protocol/src/packets/play/health_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/health_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/health_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/inventory_s2c.rs b/crates/valence_protocol/src/packets/play/inventory_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/inventory_s2c.rs
rename to crates/valence_protocol/src/packets/play/inventory_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/item_pickup_animation_s2c.rs b/crates/valence_protocol/src/packets/play/item_pickup_animation_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/item_pickup_animation_s2c.rs
rename to crates/valence_protocol/src/packets/play/item_pickup_animation_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/jigsaw_generating_c2s.rs b/crates/valence_protocol/src/packets/play/jigsaw_generating_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/jigsaw_generating_c2s.rs
rename to crates/valence_protocol/src/packets/play/jigsaw_generating_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/keep_alive_c2s.rs b/crates/valence_protocol/src/packets/play/keep_alive_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/keep_alive_c2s.rs
rename to crates/valence_protocol/src/packets/play/keep_alive_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/keep_alive_s2c.rs b/crates/valence_protocol/src/packets/play/keep_alive_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/keep_alive_s2c.rs
rename to crates/valence_protocol/src/packets/play/keep_alive_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/light_update_s2c.rs b/crates/valence_protocol/src/packets/play/light_update_s2c.rs
similarity index 89%
rename from crates/valence_packet/src/packets/play/light_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/light_update_s2c.rs
index b265f76f1..6b5a6e936 100644
--- a/crates/valence_packet/src/packets/play/light_update_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/light_update_s2c.rs
@@ -1,6 +1,5 @@
-use valence_core::protocol::array::LengthPrefixedArray;
-
use super::*;
+use crate::array::LengthPrefixedArray;
#[derive(Clone, Debug, Encode, Decode, Packet)]
#[packet(id = packet_id::LIGHT_UPDATE_S2C)]
diff --git a/crates/valence_packet/src/packets/play/look_and_on_ground_c2s.rs b/crates/valence_protocol/src/packets/play/look_and_on_ground_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/look_and_on_ground_c2s.rs
rename to crates/valence_protocol/src/packets/play/look_and_on_ground_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/look_at_s2c.rs b/crates/valence_protocol/src/packets/play/look_at_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/look_at_s2c.rs
rename to crates/valence_protocol/src/packets/play/look_at_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/map_update_s2c.rs b/crates/valence_protocol/src/packets/play/map_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/map_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/map_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/message_acknowledgment_c2s.rs b/crates/valence_protocol/src/packets/play/message_acknowledgment_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/message_acknowledgment_c2s.rs
rename to crates/valence_protocol/src/packets/play/message_acknowledgment_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/move_relative_s2c.rs b/crates/valence_protocol/src/packets/play/move_relative_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/move_relative_s2c.rs
rename to crates/valence_protocol/src/packets/play/move_relative_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/nbt_query_response_s2c.rs b/crates/valence_protocol/src/packets/play/nbt_query_response_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/nbt_query_response_s2c.rs
rename to crates/valence_protocol/src/packets/play/nbt_query_response_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/on_ground_only_c2s.rs b/crates/valence_protocol/src/packets/play/on_ground_only_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/on_ground_only_c2s.rs
rename to crates/valence_protocol/src/packets/play/on_ground_only_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/open_horse_screen_s2c.rs b/crates/valence_protocol/src/packets/play/open_horse_screen_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/open_horse_screen_s2c.rs
rename to crates/valence_protocol/src/packets/play/open_horse_screen_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/open_screen_s2c.rs b/crates/valence_protocol/src/packets/play/open_screen_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/open_screen_s2c.rs
rename to crates/valence_protocol/src/packets/play/open_screen_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/open_written_book_s2c.rs b/crates/valence_protocol/src/packets/play/open_written_book_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/open_written_book_s2c.rs
rename to crates/valence_protocol/src/packets/play/open_written_book_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/overlay_message_s2c.rs b/crates/valence_protocol/src/packets/play/overlay_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/overlay_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/overlay_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/particle_s2c.rs b/crates/valence_protocol/src/packets/play/particle_s2c.rs
similarity index 95%
rename from crates/valence_packet/src/packets/play/particle_s2c.rs
rename to crates/valence_protocol/src/packets/play/particle_s2c.rs
index 79db86674..c74b020ef 100644
--- a/crates/valence_packet/src/packets/play/particle_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/particle_s2c.rs
@@ -1,4 +1,5 @@
-use glam::Vec3;
+use valence_generated::block::BlockState;
+use valence_math::Vec3;
use super::*;
@@ -50,8 +51,8 @@ impl<'a> Decode<'a> for ParticleS2c<'a> {
pub enum Particle {
AmbientEntityEffect,
AngryVillager,
- Block(i32), // TODO: use BlockState type.
- BlockMarker(i32), // TODO: use BlockState type.
+ Block(BlockState),
+ BlockMarker(BlockState),
Bubble,
Cloud,
Crit,
@@ -80,7 +81,7 @@ pub enum Particle {
ExplosionEmitter,
Explosion,
SonicBoom,
- FallingDust(i32), // TODO: use BlockState type.
+ FallingDust(BlockState),
Firework,
Fishing,
Flame,
@@ -273,8 +274,8 @@ impl Particle {
Ok(match particle_id {
0 => Particle::AmbientEntityEffect,
1 => Particle::AngryVillager,
- 2 => Particle::Block(VarInt::decode(r)?.0),
- 3 => Particle::BlockMarker(VarInt::decode(r)?.0),
+ 2 => Particle::Block(BlockState::decode(r)?),
+ 3 => Particle::BlockMarker(BlockState::decode(r)?),
4 => Particle::Bubble,
5 => Particle::Cloud,
6 => Particle::Crit,
@@ -303,7 +304,7 @@ impl Particle {
22 => Particle::ExplosionEmitter,
23 => Particle::Explosion,
24 => Particle::SonicBoom,
- 25 => Particle::FallingDust(VarInt::decode(r)?.0),
+ 25 => Particle::FallingDust(BlockState::decode(r)?),
26 => Particle::Firework,
27 => Particle::Fishing,
28 => Particle::Flame,
@@ -397,8 +398,8 @@ impl Particle {
impl Encode for Particle {
fn encode(&self, mut w: impl Write) -> anyhow::Result<()> {
match self {
- Particle::Block(block_state) => VarInt(*block_state).encode(w),
- Particle::BlockMarker(block_state) => VarInt(*block_state).encode(w),
+ Particle::Block(block_state) => block_state.encode(w),
+ Particle::BlockMarker(block_state) => block_state.encode(w),
Particle::Dust { rgb, scale } => {
rgb.encode(&mut w)?;
scale.encode(w)
@@ -412,7 +413,7 @@ impl Encode for Particle {
scale.encode(&mut w)?;
to_rgb.encode(w)
}
- Particle::FallingDust(block_state) => VarInt(*block_state).encode(w),
+ Particle::FallingDust(block_state) => block_state.encode(w),
Particle::SculkCharge { roll } => roll.encode(w),
Particle::Item(stack) => stack.encode(w),
Particle::VibrationBlock { block_pos, ticks } => {
diff --git a/crates/valence_packet/src/packets/play/pick_from_inventory_c2s.rs b/crates/valence_protocol/src/packets/play/pick_from_inventory_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/pick_from_inventory_c2s.rs
rename to crates/valence_protocol/src/packets/play/pick_from_inventory_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/play_ping_s2c.rs b/crates/valence_protocol/src/packets/play/play_ping_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/play_ping_s2c.rs
rename to crates/valence_protocol/src/packets/play/play_ping_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/play_pong_c2s.rs b/crates/valence_protocol/src/packets/play/play_pong_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/play_pong_c2s.rs
rename to crates/valence_protocol/src/packets/play/play_pong_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/play_sound_from_entity_s2c.rs b/crates/valence_protocol/src/packets/play/play_sound_from_entity_s2c.rs
similarity index 88%
rename from crates/valence_packet/src/packets/play/play_sound_from_entity_s2c.rs
rename to crates/valence_protocol/src/packets/play/play_sound_from_entity_s2c.rs
index ea36d1987..c06f02017 100644
--- a/crates/valence_packet/src/packets/play/play_sound_from_entity_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/play_sound_from_entity_s2c.rs
@@ -1,6 +1,5 @@
-use valence_core::sound::SoundCategory;
-
use super::*;
+use crate::sound::SoundCategory;
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
#[packet(id = packet_id::PLAY_SOUND_FROM_ENTITY_S2C)]
diff --git a/crates/valence_packet/src/packets/play/play_sound_s2c.rs b/crates/valence_protocol/src/packets/play/play_sound_s2c.rs
similarity index 84%
rename from crates/valence_packet/src/packets/play/play_sound_s2c.rs
rename to crates/valence_protocol/src/packets/play/play_sound_s2c.rs
index 2651c29a9..6e04ce84d 100644
--- a/crates/valence_packet/src/packets/play/play_sound_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/play_sound_s2c.rs
@@ -1,6 +1,5 @@
-use valence_core::sound::{SoundCategory, SoundId};
-
use super::*;
+use crate::sound::{SoundCategory, SoundId};
#[derive(Clone, Debug, Encode, Decode, Packet)]
#[packet(id = packet_id::PLAY_SOUND_S2C)]
diff --git a/crates/valence_packet/src/packets/play/player_abilities_s2c.rs b/crates/valence_protocol/src/packets/play/player_abilities_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_abilities_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_abilities_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_action_c2s.rs b/crates/valence_protocol/src/packets/play/player_action_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_action_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_action_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_action_response_s2c.rs b/crates/valence_protocol/src/packets/play/player_action_response_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_action_response_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_action_response_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_input_c2s.rs b/crates/valence_protocol/src/packets/play/player_input_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_input_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_input_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_interact_block_c2s.rs b/crates/valence_protocol/src/packets/play/player_interact_block_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_interact_block_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_interact_block_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_interact_entity_c2s.rs b/crates/valence_protocol/src/packets/play/player_interact_entity_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_interact_entity_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_interact_entity_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_interact_item_c2s.rs b/crates/valence_protocol/src/packets/play/player_interact_item_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_interact_item_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_interact_item_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_list_header_s2c.rs b/crates/valence_protocol/src/packets/play/player_list_header_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_list_header_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_list_header_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_list_s2c.rs b/crates/valence_protocol/src/packets/play/player_list_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_list_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_list_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_position_look_s2c.rs b/crates/valence_protocol/src/packets/play/player_position_look_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_position_look_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_position_look_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_remove_s2c.rs b/crates/valence_protocol/src/packets/play/player_remove_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_remove_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_remove_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_respawn_s2c.rs b/crates/valence_protocol/src/packets/play/player_respawn_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_respawn_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_respawn_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_session_c2s.rs b/crates/valence_protocol/src/packets/play/player_session_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_session_c2s.rs
rename to crates/valence_protocol/src/packets/play/player_session_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/player_spawn_position_s2c.rs b/crates/valence_protocol/src/packets/play/player_spawn_position_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_spawn_position_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_spawn_position_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/player_spawn_s2c.rs b/crates/valence_protocol/src/packets/play/player_spawn_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/player_spawn_s2c.rs
rename to crates/valence_protocol/src/packets/play/player_spawn_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/position_and_on_ground_c2s.rs b/crates/valence_protocol/src/packets/play/position_and_on_ground_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/position_and_on_ground_c2s.rs
rename to crates/valence_protocol/src/packets/play/position_and_on_ground_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/profileless_chat_message_s2c.rs b/crates/valence_protocol/src/packets/play/profileless_chat_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/profileless_chat_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/profileless_chat_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/query_block_nbt_c2s.rs b/crates/valence_protocol/src/packets/play/query_block_nbt_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/query_block_nbt_c2s.rs
rename to crates/valence_protocol/src/packets/play/query_block_nbt_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/query_entity_nbt_c2s.rs b/crates/valence_protocol/src/packets/play/query_entity_nbt_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/query_entity_nbt_c2s.rs
rename to crates/valence_protocol/src/packets/play/query_entity_nbt_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/recipe_book_data_c2s.rs b/crates/valence_protocol/src/packets/play/recipe_book_data_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/recipe_book_data_c2s.rs
rename to crates/valence_protocol/src/packets/play/recipe_book_data_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/recipe_category_options_c2s.rs b/crates/valence_protocol/src/packets/play/recipe_category_options_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/recipe_category_options_c2s.rs
rename to crates/valence_protocol/src/packets/play/recipe_category_options_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/remove_entity_status_effect_s2c.rs b/crates/valence_protocol/src/packets/play/remove_entity_status_effect_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/remove_entity_status_effect_s2c.rs
rename to crates/valence_protocol/src/packets/play/remove_entity_status_effect_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/remove_message_s2c.rs b/crates/valence_protocol/src/packets/play/remove_message_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/remove_message_s2c.rs
rename to crates/valence_protocol/src/packets/play/remove_message_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/rename_item_c2s.rs b/crates/valence_protocol/src/packets/play/rename_item_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/rename_item_c2s.rs
rename to crates/valence_protocol/src/packets/play/rename_item_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/request_command_completions_c2s.rs b/crates/valence_protocol/src/packets/play/request_command_completions_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/request_command_completions_c2s.rs
rename to crates/valence_protocol/src/packets/play/request_command_completions_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/resource_pack_send_s2c.rs b/crates/valence_protocol/src/packets/play/resource_pack_send_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/resource_pack_send_s2c.rs
rename to crates/valence_protocol/src/packets/play/resource_pack_send_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/resource_pack_status_c2s.rs b/crates/valence_protocol/src/packets/play/resource_pack_status_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/resource_pack_status_c2s.rs
rename to crates/valence_protocol/src/packets/play/resource_pack_status_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/rotate_and_move_relative_s2c.rs b/crates/valence_protocol/src/packets/play/rotate_and_move_relative_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/rotate_and_move_relative_s2c.rs
rename to crates/valence_protocol/src/packets/play/rotate_and_move_relative_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/rotate_s2c.rs b/crates/valence_protocol/src/packets/play/rotate_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/rotate_s2c.rs
rename to crates/valence_protocol/src/packets/play/rotate_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/scoreboard_display_s2c.rs b/crates/valence_protocol/src/packets/play/scoreboard_display_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/scoreboard_display_s2c.rs
rename to crates/valence_protocol/src/packets/play/scoreboard_display_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/scoreboard_objective_update_s2c.rs b/crates/valence_protocol/src/packets/play/scoreboard_objective_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/scoreboard_objective_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/scoreboard_objective_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/scoreboard_player_update_s2c.rs b/crates/valence_protocol/src/packets/play/scoreboard_player_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/scoreboard_player_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/scoreboard_player_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/screen_handler_property_update_s2c.rs b/crates/valence_protocol/src/packets/play/screen_handler_property_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/screen_handler_property_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/screen_handler_property_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/screen_handler_slot_update_s2c.rs b/crates/valence_protocol/src/packets/play/screen_handler_slot_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/screen_handler_slot_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/screen_handler_slot_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/select_advancement_tab_s2c.rs b/crates/valence_protocol/src/packets/play/select_advancement_tab_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/select_advancement_tab_s2c.rs
rename to crates/valence_protocol/src/packets/play/select_advancement_tab_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/select_merchant_trade_c2s.rs b/crates/valence_protocol/src/packets/play/select_merchant_trade_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/select_merchant_trade_c2s.rs
rename to crates/valence_protocol/src/packets/play/select_merchant_trade_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/server_metadata_s2c.rs b/crates/valence_protocol/src/packets/play/server_metadata_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/server_metadata_s2c.rs
rename to crates/valence_protocol/src/packets/play/server_metadata_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/set_camera_entity_s2c.rs b/crates/valence_protocol/src/packets/play/set_camera_entity_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/set_camera_entity_s2c.rs
rename to crates/valence_protocol/src/packets/play/set_camera_entity_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/set_trade_offers_s2c.rs b/crates/valence_protocol/src/packets/play/set_trade_offers_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/set_trade_offers_s2c.rs
rename to crates/valence_protocol/src/packets/play/set_trade_offers_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/sign_editor_open_s2c.rs b/crates/valence_protocol/src/packets/play/sign_editor_open_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/sign_editor_open_s2c.rs
rename to crates/valence_protocol/src/packets/play/sign_editor_open_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/simulation_distance_s2c.rs b/crates/valence_protocol/src/packets/play/simulation_distance_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/simulation_distance_s2c.rs
rename to crates/valence_protocol/src/packets/play/simulation_distance_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/spectator_teleport_c2s.rs b/crates/valence_protocol/src/packets/play/spectator_teleport_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/spectator_teleport_c2s.rs
rename to crates/valence_protocol/src/packets/play/spectator_teleport_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/statistics_s2c.rs b/crates/valence_protocol/src/packets/play/statistics_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/statistics_s2c.rs
rename to crates/valence_protocol/src/packets/play/statistics_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/stop_sound_s2c.rs b/crates/valence_protocol/src/packets/play/stop_sound_s2c.rs
similarity index 97%
rename from crates/valence_packet/src/packets/play/stop_sound_s2c.rs
rename to crates/valence_protocol/src/packets/play/stop_sound_s2c.rs
index 85ed75ca3..b29c1a0b8 100644
--- a/crates/valence_packet/src/packets/play/stop_sound_s2c.rs
+++ b/crates/valence_protocol/src/packets/play/stop_sound_s2c.rs
@@ -1,6 +1,5 @@
-use valence_core::sound::SoundCategory;
-
use super::*;
+use crate::sound::SoundCategory;
#[derive(Clone, PartialEq, Debug, Packet)]
#[packet(id = packet_id::STOP_SOUND_S2C)]
diff --git a/crates/valence_packet/src/packets/play/subtitle_s2c.rs b/crates/valence_protocol/src/packets/play/subtitle_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/subtitle_s2c.rs
rename to crates/valence_protocol/src/packets/play/subtitle_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/synchronize_recipes_s2c.rs b/crates/valence_protocol/src/packets/play/synchronize_recipes_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/synchronize_recipes_s2c.rs
rename to crates/valence_protocol/src/packets/play/synchronize_recipes_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/synchronize_tags_s2c.rs b/crates/valence_protocol/src/packets/play/synchronize_tags_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/synchronize_tags_s2c.rs
rename to crates/valence_protocol/src/packets/play/synchronize_tags_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/team_s2c.rs b/crates/valence_protocol/src/packets/play/team_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/team_s2c.rs
rename to crates/valence_protocol/src/packets/play/team_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/teleport_confirm_c2s.rs b/crates/valence_protocol/src/packets/play/teleport_confirm_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/teleport_confirm_c2s.rs
rename to crates/valence_protocol/src/packets/play/teleport_confirm_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/title_fade_s2c.rs b/crates/valence_protocol/src/packets/play/title_fade_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/title_fade_s2c.rs
rename to crates/valence_protocol/src/packets/play/title_fade_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/title_s2c.rs b/crates/valence_protocol/src/packets/play/title_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/title_s2c.rs
rename to crates/valence_protocol/src/packets/play/title_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/unload_chunk_s2c.rs b/crates/valence_protocol/src/packets/play/unload_chunk_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/unload_chunk_s2c.rs
rename to crates/valence_protocol/src/packets/play/unload_chunk_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/unlock_recipes_s2c.rs b/crates/valence_protocol/src/packets/play/unlock_recipes_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/unlock_recipes_s2c.rs
rename to crates/valence_protocol/src/packets/play/unlock_recipes_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/update_beacon_c2s.rs b/crates/valence_protocol/src/packets/play/update_beacon_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_beacon_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_beacon_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_command_block_c2s.rs b/crates/valence_protocol/src/packets/play/update_command_block_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_command_block_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_command_block_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_command_block_minecart_c2s.rs b/crates/valence_protocol/src/packets/play/update_command_block_minecart_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_command_block_minecart_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_command_block_minecart_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_difficulty_c2s.rs b/crates/valence_protocol/src/packets/play/update_difficulty_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_difficulty_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_difficulty_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_difficulty_lock_c2s.rs b/crates/valence_protocol/src/packets/play/update_difficulty_lock_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_difficulty_lock_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_difficulty_lock_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_jigsaw_c2s.rs b/crates/valence_protocol/src/packets/play/update_jigsaw_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_jigsaw_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_jigsaw_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_player_abilities_c2s.rs b/crates/valence_protocol/src/packets/play/update_player_abilities_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_player_abilities_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_player_abilities_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_selected_slot_c2s.rs b/crates/valence_protocol/src/packets/play/update_selected_slot_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_selected_slot_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_selected_slot_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_selected_slot_s2c.rs b/crates/valence_protocol/src/packets/play/update_selected_slot_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_selected_slot_s2c.rs
rename to crates/valence_protocol/src/packets/play/update_selected_slot_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/update_sign_c2s.rs b/crates/valence_protocol/src/packets/play/update_sign_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_sign_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_sign_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/update_structure_block_c2s.rs b/crates/valence_protocol/src/packets/play/update_structure_block_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/update_structure_block_c2s.rs
rename to crates/valence_protocol/src/packets/play/update_structure_block_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/vehicle_move_c2s.rs b/crates/valence_protocol/src/packets/play/vehicle_move_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/vehicle_move_c2s.rs
rename to crates/valence_protocol/src/packets/play/vehicle_move_c2s.rs
diff --git a/crates/valence_packet/src/packets/play/vehicle_move_s2c.rs b/crates/valence_protocol/src/packets/play/vehicle_move_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/vehicle_move_s2c.rs
rename to crates/valence_protocol/src/packets/play/vehicle_move_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_center_changed_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_center_changed_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_center_changed_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_center_changed_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_initialize_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_initialize_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_initialize_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_initialize_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_interpolate_size_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_interpolate_size_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_interpolate_size_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_interpolate_size_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_size_changed_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_size_changed_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_size_changed_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_size_changed_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_warning_blocks_changed_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_warning_blocks_changed_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_warning_blocks_changed_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_warning_blocks_changed_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_border_warning_time_changed_s2c.rs b/crates/valence_protocol/src/packets/play/world_border_warning_time_changed_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_border_warning_time_changed_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_border_warning_time_changed_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_event_s2c.rs b/crates/valence_protocol/src/packets/play/world_event_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_event_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_event_s2c.rs
diff --git a/crates/valence_packet/src/packets/play/world_time_update_s2c.rs b/crates/valence_protocol/src/packets/play/world_time_update_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/play/world_time_update_s2c.rs
rename to crates/valence_protocol/src/packets/play/world_time_update_s2c.rs
diff --git a/crates/valence_packet/src/packets/status.rs b/crates/valence_protocol/src/packets/status.rs
similarity index 100%
rename from crates/valence_packet/src/packets/status.rs
rename to crates/valence_protocol/src/packets/status.rs
diff --git a/crates/valence_packet/src/packets/status/query_ping_c2s.rs b/crates/valence_protocol/src/packets/status/query_ping_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/status/query_ping_c2s.rs
rename to crates/valence_protocol/src/packets/status/query_ping_c2s.rs
diff --git a/crates/valence_packet/src/packets/status/query_pong_s2c.rs b/crates/valence_protocol/src/packets/status/query_pong_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/status/query_pong_s2c.rs
rename to crates/valence_protocol/src/packets/status/query_pong_s2c.rs
diff --git a/crates/valence_packet/src/packets/status/query_request_c2s.rs b/crates/valence_protocol/src/packets/status/query_request_c2s.rs
similarity index 100%
rename from crates/valence_packet/src/packets/status/query_request_c2s.rs
rename to crates/valence_protocol/src/packets/status/query_request_c2s.rs
diff --git a/crates/valence_packet/src/packets/status/query_response_s2c.rs b/crates/valence_protocol/src/packets/status/query_response_s2c.rs
similarity index 100%
rename from crates/valence_packet/src/packets/status/query_response_s2c.rs
rename to crates/valence_protocol/src/packets/status/query_response_s2c.rs
diff --git a/crates/valence_core/src/player_textures.rs b/crates/valence_protocol/src/player_textures.rs
similarity index 100%
rename from crates/valence_core/src/player_textures.rs
rename to crates/valence_protocol/src/player_textures.rs
diff --git a/crates/valence_core/src/property.rs b/crates/valence_protocol/src/property.rs
similarity index 85%
rename from crates/valence_core/src/property.rs
rename to crates/valence_protocol/src/property.rs
index 634d44162..b00d131c0 100644
--- a/crates/valence_core/src/property.rs
+++ b/crates/valence_protocol/src/property.rs
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encode, Decode, Serialize, Deserialize)]
pub struct Property {
diff --git a/crates/valence_core/src/protocol/raw.rs b/crates/valence_protocol/src/raw.rs
similarity index 96%
rename from crates/valence_core/src/protocol/raw.rs
rename to crates/valence_protocol/src/raw.rs
index e49e8c680..a106d3310 100644
--- a/crates/valence_core/src/protocol/raw.rs
+++ b/crates/valence_protocol/src/raw.rs
@@ -1,7 +1,7 @@
use std::io::Write;
use std::mem;
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
/// While [encoding], the contained slice is written directly to the output
/// without any length prefix or metadata.
diff --git a/crates/valence_core/src/sound.rs b/crates/valence_protocol/src/sound.rs
similarity index 78%
rename from crates/valence_core/src/sound.rs
rename to crates/valence_protocol/src/sound.rs
index 91733d742..4fa3d9e4f 100644
--- a/crates/valence_core/src/sound.rs
+++ b/crates/valence_protocol/src/sound.rs
@@ -1,21 +1,11 @@
use std::borrow::Cow;
use std::io::Write;
-use crate::ident;
-use crate::ident::Ident;
-use crate::protocol::var_int::VarInt;
-use crate::protocol::{Decode, Encode};
+pub use valence_generated::sound::Sound;
+use valence_ident::Ident;
-include!(concat!(env!("OUT_DIR"), "/sound.rs"));
-
-impl Sound {
- pub fn to_id(self) -> SoundId<'static> {
- SoundId::Direct {
- id: self.to_ident().into(),
- range: None,
- }
- }
-}
+use crate::var_int::VarInt;
+use crate::{Decode, Encode};
#[derive(Clone, PartialEq, Debug)]
pub enum SoundId<'a> {
@@ -28,6 +18,20 @@ pub enum SoundId<'a> {
},
}
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Encode, Decode)]
+pub enum SoundCategory {
+ Master,
+ Music,
+ Record,
+ Weather,
+ Block,
+ Hostile,
+ Neutral,
+ Player,
+ Ambient,
+ Voice,
+}
+
impl Encode for SoundId<'_> {
fn encode(&self, mut w: impl Write) -> anyhow::Result<()> {
match self {
@@ -57,17 +61,3 @@ impl<'a> Decode<'a> for SoundId<'a> {
}
}
}
-
-#[derive(Copy, Clone, PartialEq, Eq, Debug, Encode, Decode)]
-pub enum SoundCategory {
- Master,
- Music,
- Record,
- Weather,
- Block,
- Hostile,
- Neutral,
- Player,
- Ambient,
- Voice,
-}
diff --git a/crates/valence_core/src/protocol/var_int.rs b/crates/valence_protocol/src/var_int.rs
similarity index 99%
rename from crates/valence_core/src/protocol/var_int.rs
rename to crates/valence_protocol/src/var_int.rs
index 68a7442d2..0e3e84924 100644
--- a/crates/valence_core/src/protocol/var_int.rs
+++ b/crates/valence_protocol/src/var_int.rs
@@ -5,7 +5,7 @@ use byteorder::ReadBytesExt;
use serde::Deserialize;
use thiserror::Error;
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
/// An `i32` encoded with variable length.
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)]
diff --git a/crates/valence_core/src/protocol/var_long.rs b/crates/valence_protocol/src/var_long.rs
similarity index 99%
rename from crates/valence_core/src/protocol/var_long.rs
rename to crates/valence_protocol/src/var_long.rs
index 12d26c424..626f3e8db 100644
--- a/crates/valence_core/src/protocol/var_long.rs
+++ b/crates/valence_protocol/src/var_long.rs
@@ -3,7 +3,7 @@ use std::io::Write;
use anyhow::bail;
use byteorder::ReadBytesExt;
-use crate::protocol::{Decode, Encode};
+use crate::{Decode, Encode};
/// An `i64` encoded with variable length.
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
diff --git a/crates/valence_core_macros/Cargo.toml b/crates/valence_protocol_macros/Cargo.toml
similarity index 77%
rename from crates/valence_core_macros/Cargo.toml
rename to crates/valence_protocol_macros/Cargo.toml
index 4e7ef88aa..299257dec 100644
--- a/crates/valence_core_macros/Cargo.toml
+++ b/crates/valence_protocol_macros/Cargo.toml
@@ -1,7 +1,8 @@
[package]
-name = "valence_core_macros"
+name = "valence_protocol_macros"
version.workspace = true
edition.workspace = true
+license.workspace = true
[lib]
proc-macro = true
diff --git a/crates/valence_protocol_macros/README.md b/crates/valence_protocol_macros/README.md
new file mode 100644
index 000000000..fc74027cc
--- /dev/null
+++ b/crates/valence_protocol_macros/README.md
@@ -0,0 +1,3 @@
+# valence_protocol_macros
+
+Procedural macros for `valence_protocol`
diff --git a/crates/valence_core_macros/src/decode.rs b/crates/valence_protocol_macros/src/decode.rs
similarity index 90%
rename from crates/valence_core_macros/src/decode.rs
rename to crates/valence_protocol_macros/src/decode.rs
index a996eef97..15f45e838 100644
--- a/crates/valence_core_macros/src/decode.rs
+++ b/crates/valence_protocol_macros/src/decode.rs
@@ -63,7 +63,7 @@ pub(super) fn derive_decode(item: TokenStream) -> Result {
add_trait_bounds(
&mut input.generics,
- quote!(::valence_core::__private::Decode<#lifetime>),
+ quote!(::valence_protocol::__private::Decode<#lifetime>),
);
let (impl_generics, ty_generics, where_clause) =
@@ -71,11 +71,11 @@ pub(super) fn derive_decode(item: TokenStream) -> Result {
Ok(quote! {
#[allow(unused_imports)]
- impl #impl_generics ::valence_core::__private::Decode<#lifetime> for #input_name #ty_generics
+ impl #impl_generics ::valence_protocol::__private::Decode<#lifetime> for #input_name #ty_generics
#where_clause
{
- fn decode(_r: &mut lifetime [u8]) -> ::valence_core::__private::Result {
- use ::valence_core::__private::{Decode, Context, ensure};
+ fn decode(_r: &mut lifetime [u8]) -> ::valence_protocol::__private::Result {
+ use ::valence_protocol::__private::{Decode, Context, ensure};
Ok(#decode_fields)
}
@@ -135,7 +135,7 @@ pub(super) fn derive_decode(item: TokenStream) -> Result {
add_trait_bounds(
&mut input.generics,
- quote!(::valence_core::__private::Decode<#lifetime>),
+ quote!(::valence_protocol::__private::Decode<#lifetime>),
);
let (impl_generics, ty_generics, where_clause) =
@@ -143,11 +143,11 @@ pub(super) fn derive_decode(item: TokenStream) -> Result {
Ok(quote! {
#[allow(unused_imports)]
- impl #impl_generics ::valence_core::__private::Decode<#lifetime> for #input_name #ty_generics
+ impl #impl_generics ::valence_protocol::__private::Decode<#lifetime> for #input_name #ty_generics
#where_clause
{
- fn decode(_r: &mut lifetime [u8]) -> ::valence_core::__private::Result {
- use ::valence_core::__private::{Decode, Context, VarInt, bail};
+ fn decode(_r: &mut lifetime [u8]) -> ::valence_protocol::__private::Result {
+ use ::valence_protocol::__private::{Decode, Context, VarInt, bail};
let ctx = concat!("failed to decode enum discriminant in `", stringify!(#input_name), "`");
let disc = VarInt::decode(_r).context(ctx)?.0;
diff --git a/crates/valence_core_macros/src/encode.rs b/crates/valence_protocol_macros/src/encode.rs
similarity index 92%
rename from crates/valence_core_macros/src/encode.rs
rename to crates/valence_protocol_macros/src/encode.rs
index 06e1aef6f..101048e0c 100644
--- a/crates/valence_core_macros/src/encode.rs
+++ b/crates/valence_protocol_macros/src/encode.rs
@@ -12,7 +12,7 @@ pub(super) fn derive_encode(item: TokenStream) -> Result {
add_trait_bounds(
&mut input.generics,
- quote!(::valence_core::__private::Encode),
+ quote!(::valence_protocol::__private::Encode),
);
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
@@ -45,11 +45,11 @@ pub(super) fn derive_encode(item: TokenStream) -> Result {
Ok(quote! {
#[allow(unused_imports)]
- impl #impl_generics ::valence_core::__private::Encode for #input_name #ty_generics
+ impl #impl_generics ::valence_protocol::__private::Encode for #input_name #ty_generics
#where_clause
{
- fn encode(&self, mut _w: impl ::std::io::Write) -> ::valence_core::__private::Result<()> {
- use ::valence_core::__private::{Encode, Context};
+ fn encode(&self, mut _w: impl ::std::io::Write) -> ::valence_protocol::__private::Result<()> {
+ use ::valence_protocol::__private::{Encode, Context};
#encode_fields
@@ -143,11 +143,11 @@ pub(super) fn derive_encode(item: TokenStream) -> Result {
Ok(quote! {
#[allow(unused_imports, unreachable_code)]
- impl #impl_generics ::valence_core::__private::Encode for #input_name #ty_generics
+ impl #impl_generics ::valence_protocol::__private::Encode for #input_name #ty_generics
#where_clause
{
- fn encode(&self, mut _w: impl ::std::io::Write) -> ::valence_core::__private::Result<()> {
- use ::valence_core::__private::{Encode, VarInt, Context};
+ fn encode(&self, mut _w: impl ::std::io::Write) -> ::valence_protocol::__private::Result<()> {
+ use ::valence_protocol::__private::{Encode, VarInt, Context};
match self {
#encode_arms
diff --git a/crates/valence_core_macros/src/lib.rs b/crates/valence_protocol_macros/src/lib.rs
similarity index 95%
rename from crates/valence_core_macros/src/lib.rs
rename to crates/valence_protocol_macros/src/lib.rs
index 82de02d63..46c552024 100644
--- a/crates/valence_core_macros/src/lib.rs
+++ b/crates/valence_protocol_macros/src/lib.rs
@@ -27,7 +27,7 @@ use syn::{
mod decode;
mod encode;
-mod ident;
+mod packet;
#[proc_macro_derive(Encode, attributes(packet))]
pub fn derive_encode(item: StdTokenStream) -> StdTokenStream {
@@ -45,9 +45,9 @@ pub fn derive_decode(item: StdTokenStream) -> StdTokenStream {
}
}
-#[proc_macro]
-pub fn parse_ident_str(item: StdTokenStream) -> StdTokenStream {
- match ident::parse_ident_str(item.into()) {
+#[proc_macro_derive(Packet, attributes(packet))]
+pub fn derive_packet(item: StdTokenStream) -> StdTokenStream {
+ match packet::derive_packet(item.into()) {
Ok(tokens) => tokens.into(),
Err(e) => e.into_compile_error().into(),
}
diff --git a/crates/valence_packet_macros/src/packet.rs b/crates/valence_protocol_macros/src/packet.rs
similarity index 86%
rename from crates/valence_packet_macros/src/packet.rs
rename to crates/valence_protocol_macros/src/packet.rs
index cb97c77ba..5aa0738a3 100644
--- a/crates/valence_packet_macros/src/packet.rs
+++ b/crates/valence_protocol_macros/src/packet.rs
@@ -34,9 +34,9 @@ pub(super) fn derive_packet(item: TokenStream) -> Result {
let side = if let Some(side_attr) = packet_attr.side {
side_attr
} else if name_str.to_lowercase().contains("s2c") {
- parse_quote!(::valence_packet::protocol::PacketSide::Clientbound)
+ parse_quote!(::valence_protocol::PacketSide::Clientbound)
} else if name_str.to_lowercase().contains("c2s") {
- parse_quote!(::valence_packet::protocol::PacketSide::Serverbound)
+ parse_quote!(::valence_protocol::PacketSide::Serverbound)
} else {
return Err(Error::new(
input.span(),
@@ -46,16 +46,16 @@ pub(super) fn derive_packet(item: TokenStream) -> Result {
let state = packet_attr
.state
- .unwrap_or_else(|| parse_quote!(::valence_packet::protocol::PacketState::Play));
+ .unwrap_or_else(|| parse_quote!(::valence_protocol::PacketState::Play));
Ok(quote! {
- impl #impl_generics ::valence_packet::__private::Packet for #name #ty_generics
+ impl #impl_generics ::valence_protocol::__private::Packet for #name #ty_generics
#where_clause
{
const ID: i32 = #packet_id;
const NAME: &'static str = #name_str;
- const SIDE: ::valence_packet::protocol::PacketSide = #side;
- const STATE: ::valence_packet::protocol::PacketState = #state;
+ const SIDE: ::valence_protocol::PacketSide = #side;
+ const STATE: ::valence_protocol::PacketState = #state;
}
})
}
diff --git a/crates/valence_registry/Cargo.toml b/crates/valence_registry/Cargo.toml
index 0de4f26c8..73072a4fe 100644
--- a/crates/valence_registry/Cargo.toml
+++ b/crates/valence_registry/Cargo.toml
@@ -10,6 +10,8 @@ indexmap.workspace = true
serde_json.workspace = true
serde.workspace = true
tracing.workspace = true
-valence_core.workspace = true
-valence_packet.workspace = true
-valence_nbt.workspace = true
\ No newline at end of file
+valence_protocol.workspace = true
+anyhow.workspace = true
+valence_ident.workspace = true
+valence_nbt = { workspace = true, features = ["serde"] }
+valence_server_core.workspace = true
diff --git a/crates/valence_registry/README.md b/crates/valence_registry/README.md
index 9a598ac9e..088afc7c2 100644
--- a/crates/valence_registry/README.md
+++ b/crates/valence_registry/README.md
@@ -1,7 +1,3 @@
# valence_registry
-Manages Minecraft's networked registries in a generic way. This includes the registry codec sent to clients during the initial join.
-
-Consumers of `registry` such as `biome` and `dimension` are expected to update themselves in the registries defined here. Minecraft's default registry codec is loaded by default.
-
-End users are not expected to use this module directly.
+Contains Minecraft's networked registries. This includes the registry codec sent to clients during the initial join.
diff --git a/crates/valence_biome/src/lib.rs b/crates/valence_registry/src/biome.rs
similarity index 84%
rename from crates/valence_biome/src/lib.rs
rename to crates/valence_registry/src/biome.rs
index b61c52b65..b6048e76f 100644
--- a/crates/valence_biome/src/lib.rs
+++ b/crates/valence_registry/src/biome.rs
@@ -1,21 +1,12 @@
-#![doc = include_str!("../README.md")]
-#![deny(
- rustdoc::broken_intra_doc_links,
- rustdoc::private_intra_doc_links,
- rustdoc::missing_crate_level_docs,
- rustdoc::invalid_codeblock_attributes,
- rustdoc::invalid_rust_codeblocks,
- rustdoc::bare_urls,
- rustdoc::invalid_html_tags
-)]
-#![warn(
- trivial_casts,
- trivial_numeric_casts,
- unused_lifetimes,
- unused_import_braces,
- unreachable_pub,
- clippy::dbg_macro
-)]
+//! Contains biomes and the biome registry. Minecraft's default biomes are added
+//! to the registry by default.
+//!
+//! ### **NOTE:**
+//! - Modifying the biome registry after the server has started can
+//! break invariants within instances and clients! Make sure there are no
+//! instances or clients spawned before mutating.
+//! - A biome named "minecraft:plains" must exist. Otherwise, vanilla clients
+//! will be disconnected.
use std::ops::{Deref, DerefMut};
@@ -23,11 +14,11 @@ use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use serde::{Deserialize, Serialize};
use tracing::error;
-use valence_core::ident;
-use valence_core::ident::Ident;
+use valence_ident::{ident, Ident};
use valence_nbt::serde::CompoundSerializer;
-use valence_registry::codec::{RegistryCodec, RegistryValue};
-use valence_registry::{Registry, RegistryIdx, RegistrySet};
+
+use crate::codec::{RegistryCodec, RegistryValue};
+use crate::{Registry, RegistryIdx, RegistrySet};
pub struct BiomePlugin;
diff --git a/crates/valence_registry/src/codec.rs b/crates/valence_registry/src/codec.rs
index 2c570bd94..aa71fa689 100644
--- a/crates/valence_registry/src/codec.rs
+++ b/crates/valence_registry/src/codec.rs
@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use tracing::error;
-use valence_core::ident::Ident;
+use valence_ident::Ident;
use valence_nbt::{compound, Compound, List, Value};
use crate::RegistrySet;
diff --git a/crates/valence_dimension/src/lib.rs b/crates/valence_registry/src/dimension_type.rs
similarity index 87%
rename from crates/valence_dimension/src/lib.rs
rename to crates/valence_registry/src/dimension_type.rs
index 36c34a657..fccdedbb8 100644
--- a/crates/valence_dimension/src/lib.rs
+++ b/crates/valence_registry/src/dimension_type.rs
@@ -1,37 +1,25 @@
-#![doc = include_str!("../README.md")]
-#![deny(
- rustdoc::broken_intra_doc_links,
- rustdoc::private_intra_doc_links,
- rustdoc::missing_crate_level_docs,
- rustdoc::invalid_codeblock_attributes,
- rustdoc::invalid_rust_codeblocks,
- rustdoc::bare_urls,
- rustdoc::invalid_html_tags
-)]
-#![warn(
- trivial_casts,
- trivial_numeric_casts,
- unused_lifetimes,
- unused_import_braces,
- unreachable_pub,
- clippy::dbg_macro
-)]
+//! Contains dimension types and the dimension type registry. Minecraft's
+//! default dimensions are added to the registry by default.
+//!
+//! ### **NOTE:**
+//! - Modifying the dimension type registry after the server has started can
+//! break invariants within instances and clients! Make sure there are no
+//! instances or clients spawned before mutating.
use std::ops::{Deref, DerefMut};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use serde::{Deserialize, Serialize};
-use tracing::{error, warn};
-use valence_core::ident;
-use valence_core::ident::Ident;
+use tracing::error;
+use valence_ident::{ident, Ident};
use valence_nbt::serde::CompoundSerializer;
-use valence_registry::codec::{RegistryCodec, RegistryValue};
-use valence_registry::{Registry, RegistryIdx, RegistrySet};
-pub struct DimensionPlugin;
+use crate::codec::{RegistryCodec, RegistryValue};
+use crate::{Registry, RegistryIdx, RegistrySet};
+pub struct DimensionTypePlugin;
-impl Plugin for DimensionPlugin {
+impl Plugin for DimensionTypePlugin {
fn build(&self, app: &mut App) {
app.init_resource::()
.add_systems(PreStartup, load_default_dimension_types)
@@ -150,7 +138,7 @@ pub struct DimensionType {
impl Default for DimensionType {
fn default() -> Self {
Self {
- ambient_light: 1.0,
+ ambient_light: 0.0,
bed_works: true,
coordinate_scale: 1.0,
effects: DimensionEffects::default(),
diff --git a/crates/valence_registry/src/lib.rs b/crates/valence_registry/src/lib.rs
index 0984f60c4..d9a59b105 100644
--- a/crates/valence_registry/src/lib.rs
+++ b/crates/valence_registry/src/lib.rs
@@ -17,7 +17,9 @@
clippy::dbg_macro
)]
+pub mod biome;
pub mod codec;
+pub mod dimension_type;
pub mod tags;
use std::fmt::Debug;
@@ -26,10 +28,14 @@ use std::marker::PhantomData;
use std::ops::{Index, IndexMut};
use bevy_app::prelude::*;
-pub use bevy_ecs::prelude::*;
+use bevy_ecs::prelude::*;
+pub use biome::BiomeRegistry;
+pub use codec::RegistryCodec;
+pub use dimension_type::DimensionTypeRegistry;
use indexmap::map::Entry;
use indexmap::IndexMap;
-use valence_core::ident::Ident;
+pub use tags::TagsRegistry;
+use valence_ident::Ident;
pub struct RegistryPlugin;
diff --git a/crates/valence_registry/src/tags.rs b/crates/valence_registry/src/tags.rs
index 5e9ae25eb..833227951 100644
--- a/crates/valence_registry/src/tags.rs
+++ b/crates/valence_registry/src/tags.rs
@@ -2,10 +2,10 @@ use std::borrow::Cow;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_core::Server;
-pub use valence_packet::packets::play::synchronize_tags_s2c::Registry;
-use valence_packet::packets::play::SynchronizeTagsS2c;
-use valence_packet::protocol::encode::{PacketWriter, WritePacket};
+use valence_protocol::encode::{PacketWriter, WritePacket};
+pub use valence_protocol::packets::play::synchronize_tags_s2c::Registry;
+use valence_protocol::packets::play::SynchronizeTagsS2c;
+use valence_server_core::Server;
use crate::RegistrySet;
@@ -33,7 +33,7 @@ impl TagsRegistry {
}
}
-pub fn init_tags_registry(mut tags: ResMut) {
+fn init_tags_registry(mut tags: ResMut) {
let registries =
serde_json::from_str::>(include_str!("../../../extracted/tags.json"))
.expect("tags.json is invalid");
@@ -53,14 +53,12 @@ pub(crate) fn cache_tags_packet(server: Res, tags: ResMut)
#[cfg(test)]
mod tests {
- use super::*;
- use crate::RegistryPlugin;
-
+ /* TODO: move this to src/tests/
#[test]
fn smoke_test() {
let mut app = bevy_app::App::new();
app.add_plugins(RegistryPlugin);
- app.insert_resource(Server::default());
+ // app.insert_resource(Server::default());
app.update();
let tags_registry = app.world.get_resource::().unwrap();
@@ -68,4 +66,5 @@ mod tests {
assert!(!packet.registries.is_empty());
assert!(!tags_registry.cached_packet.is_empty());
}
+ */
}
diff --git a/crates/valence_scoreboard/Cargo.toml b/crates/valence_scoreboard/Cargo.toml
index fe28da114..ad99a3d84 100644
--- a/crates/valence_scoreboard/Cargo.toml
+++ b/crates/valence_scoreboard/Cargo.toml
@@ -6,9 +6,5 @@ edition = "2021"
[dependencies]
bevy_app.workspace = true
bevy_ecs.workspace = true
-valence_client.workspace = true
-valence_core.workspace = true
-valence_entity.workspace = true
-valence_layer.workspace = true
-valence_packet.workspace = true
+valence_server.workspace = true
tracing.workspace = true
diff --git a/crates/valence_scoreboard/README.md b/crates/valence_scoreboard/README.md
index 3b7173e93..886df9e36 100644
--- a/crates/valence_scoreboard/README.md
+++ b/crates/valence_scoreboard/README.md
@@ -11,7 +11,7 @@ Example:
```rust
# use bevy_ecs::prelude::*;
use valence_scoreboard::*;
-use valence_core::text::IntoText;
+use valence_server::protocol::text::IntoText;
fn spawn_scoreboard(mut commands: Commands) {
commands.spawn(ObjectiveBundle {
diff --git a/crates/valence_scoreboard/src/components.rs b/crates/valence_scoreboard/src/components.rs
index 7c7b90089..71342fdbe 100644
--- a/crates/valence_scoreboard/src/components.rs
+++ b/crates/valence_scoreboard/src/components.rs
@@ -1,10 +1,11 @@
use std::collections::HashMap;
use bevy_ecs::prelude::*;
-use valence_core::text::{IntoText, Text};
-use valence_entity::EntityLayerId;
-use valence_packet::packets::play::scoreboard_display_s2c::ScoreboardPosition;
-use valence_packet::packets::play::scoreboard_objective_update_s2c::ObjectiveRenderType;
+use valence_server::entity::EntityLayerId;
+use valence_server::protocol::packets::play::scoreboard_display_s2c::ScoreboardPosition;
+use valence_server::protocol::packets::play::scoreboard_objective_update_s2c::ObjectiveRenderType;
+use valence_server::text::IntoText;
+use valence_server::Text;
/// A string that identifies an objective. There is one scoreboard per
/// objective.It's generally not safe to modify this after it's been created.
diff --git a/crates/valence_scoreboard/src/lib.rs b/crates/valence_scoreboard/src/lib.rs
index f5780588c..e7a2b9a68 100644
--- a/crates/valence_scoreboard/src/lib.rs
+++ b/crates/valence_scoreboard/src/lib.rs
@@ -18,27 +18,28 @@
)]
#![allow(clippy::type_complexity)]
+mod components;
use std::collections::BTreeSet;
use bevy_app::prelude::*;
use bevy_ecs::change_detection::DetectChanges;
use bevy_ecs::prelude::*;
-use tracing::{debug, warn};
-
-mod components;
pub use components::*;
-use valence_client::{Client, OldVisibleEntityLayers, VisibleEntityLayers};
-use valence_core::__private::VarInt;
-use valence_core::despawn::Despawned;
-use valence_core::text::IntoText;
-use valence_entity::EntityLayerId;
-use valence_layer::{EntityLayer, UpdateLayersPreClientSet};
-pub use valence_packet::packets::play::scoreboard_display_s2c::ScoreboardPosition;
-use valence_packet::packets::play::scoreboard_display_s2c::*;
-pub use valence_packet::packets::play::scoreboard_objective_update_s2c::ObjectiveRenderType;
-use valence_packet::packets::play::scoreboard_objective_update_s2c::*;
-use valence_packet::packets::play::scoreboard_player_update_s2c::*;
-use valence_packet::protocol::encode::WritePacket;
+use tracing::{debug, warn};
+use valence_server::client::{Client, OldVisibleEntityLayers, VisibleEntityLayers};
+use valence_server::entity::EntityLayerId;
+use valence_server::layer::UpdateLayersPreClientSet;
+use valence_server::protocol::packets::play::scoreboard_display_s2c::ScoreboardPosition;
+use valence_server::protocol::packets::play::scoreboard_objective_update_s2c::{
+ ObjectiveMode, ObjectiveRenderType,
+};
+use valence_server::protocol::packets::play::scoreboard_player_update_s2c::ScoreboardPlayerUpdateAction;
+use valence_server::protocol::packets::play::{
+ ScoreboardDisplayS2c, ScoreboardObjectiveUpdateS2c, ScoreboardPlayerUpdateS2c,
+};
+use valence_server::protocol::{VarInt, WritePacket};
+use valence_server::text::IntoText;
+use valence_server::{Despawned, EntityLayer};
/// Provides all necessary systems to manage scoreboards.
pub struct ScoreboardPlugin;
@@ -102,7 +103,10 @@ fn create_or_update_objectives(
};
let Ok(mut layer) = layers.get_mut(entity_layer.0) else {
- warn!("No layer found for entity layer ID {:?}, can't update scoreboard objective", entity_layer);
+ warn!(
+ "No layer found for entity layer ID {:?}, can't update scoreboard objective",
+ entity_layer
+ );
continue;
};
@@ -128,7 +132,10 @@ fn display_objectives(
};
let Ok(mut layer) = layers.get_mut(entity_layer.0) else {
- warn!("No layer found for entity layer ID {:?}, can't update scoreboard display", entity_layer);
+ warn!(
+ "No layer found for entity layer ID {:?}, can't update scoreboard display",
+ entity_layer
+ );
continue;
};
@@ -144,7 +151,10 @@ fn remove_despawned_objectives(
for (entity, objective, entity_layer) in objectives.iter() {
commands.entity(entity).despawn();
let Ok(mut layer) = layers.get_mut(entity_layer.0) else {
- warn!("No layer found for entity layer ID {:?}, can't remove scoreboard objective", entity_layer);
+ warn!(
+ "No layer found for entity layer ID {:?}, can't remove scoreboard objective",
+ entity_layer
+ );
continue;
};
@@ -252,7 +262,10 @@ fn update_scores(
) {
for (objective, scores, mut old_scores, entity_layer) in objectives.iter_mut() {
let Ok(mut layer) = layers.get_mut(entity_layer.0) else {
- warn!("No layer found for entity layer ID {:?}, can't update scores", entity_layer);
+ warn!(
+ "No layer found for entity layer ID {:?}, can't update scores",
+ entity_layer
+ );
continue;
};
diff --git a/crates/valence_server/Cargo.toml b/crates/valence_server/Cargo.toml
new file mode 100644
index 000000000..bfc0a455d
--- /dev/null
+++ b/crates/valence_server/Cargo.toml
@@ -0,0 +1,30 @@
+[package]
+name = "valence_server"
+version.workspace = true
+edition.workspace = true
+repository.workspace = true
+documentation.workspace = true
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bevy_app.workspace = true
+bevy_ecs.workspace = true
+bevy_utils.workspace = true # Needed for `ScheduleLabel` derive macro.
+bitfield-struct.workspace = true
+bytes.workspace = true
+valence_math.workspace = true
+rand.workspace = true
+tracing.workspace = true
+uuid.workspace = true
+byteorder.workspace = true
+valence_server_core.workspace = true
+valence_entity.workspace = true
+valence_nbt.workspace = true
+valence_registry.workspace = true
+valence_protocol.workspace = true
+valence_generated.workspace = true
+rustc-hash.workspace = true
+parking_lot.workspace = true
+num-integer.workspace = true
+arrayvec.workspace = true
diff --git a/crates/valence_server/README.md b/crates/valence_server/README.md
new file mode 100644
index 000000000..13c1fdc91
--- /dev/null
+++ b/crates/valence_server/README.md
@@ -0,0 +1,5 @@
+# valence_server
+
+Defines the "core" of the Valence server that plugins depend on. If a plugin module here is large enough, it may be split off into its own crate to reduce compile times.
+
+The contents of `valence_server` are re-exported from the main `valence` crate, so end users should not interact with this crate directly.
diff --git a/crates/valence_client/src/abilities.rs b/crates/valence_server/src/abilities.rs
similarity index 78%
rename from crates/valence_client/src/abilities.rs
rename to crates/valence_server/src/abilities.rs
index 827ea94bd..45dcb2ca5 100644
--- a/crates/valence_client/src/abilities.rs
+++ b/crates/valence_server/src/abilities.rs
@@ -1,7 +1,10 @@
-pub use valence_packet::packets::play::player_abilities_s2c::PlayerAbilitiesFlags;
-use valence_packet::packets::play::{PlayerAbilitiesS2c, UpdatePlayerAbilitiesC2s};
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+pub use valence_protocol::packets::play::player_abilities_s2c::PlayerAbilitiesFlags;
+use valence_protocol::packets::play::{PlayerAbilitiesS2c, UpdatePlayerAbilitiesC2s};
+use valence_protocol::{GameMode, WritePacket};
-use super::*;
+use crate::client::{update_game_mode, Client, UpdateClientsSet};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
/// [`Component`] that stores the player's flying speed ability.
@@ -41,29 +44,38 @@ pub struct PlayerStopFlyingEvent {
pub client: Entity,
}
-/// Order of execution :
-/// 1. [`update_game_mode`] : Watch [`GameMode`] changes => Send
-/// [`GameStateChangeS2c`] to update the client's gamemode
-/// 2. [`update_client_player_abilities`] : Watch [`PlayerAbilitiesFlags`],
+/// Order of execution:
+/// 1. `update_game_mode`: Watch [`GameMode`] changes => Send
+/// `GameStateChangeS2c` to update the client's gamemode
+///
+/// 2. `update_client_player_abilities`: Watch [`PlayerAbilitiesFlags`],
/// [`FlyingSpeed`] and [`FovModifier`] changes => Send [`PlayerAbilitiesS2c`]
-/// to update the client's abilities 3. [`update_player_abilities`] : Watch
+/// to update the client's abilities
+///
+/// 3. `update_player_abilities`: Watch
/// [`GameMode`] changes => Update [`PlayerAbilitiesFlags`] according to the
-/// [`GameMode`] 4. [`update_server_player_abilities`] : Watch
+/// [`GameMode`]
+///
+/// 4. `update_server_player_abilities`: Watch
/// [`UpdatePlayerAbilitiesC2s`] packets => Update [`PlayerAbilitiesFlags`]
/// according to the packet
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_event::()
- .add_systems(
- PostUpdate,
- (
- update_client_player_abilities,
- update_player_abilities.before(update_client_player_abilities),
+pub struct AbilitiesPlugin;
+
+impl Plugin for AbilitiesPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_event::()
+ .add_systems(
+ PostUpdate,
+ (
+ update_client_player_abilities,
+ update_player_abilities.before(update_client_player_abilities),
+ )
+ .in_set(UpdateClientsSet)
+ .after(update_game_mode),
)
- .in_set(UpdateClientsSet)
- .after(update_game_mode),
- )
- .add_systems(EventLoopPreUpdate, update_server_player_abilities);
+ .add_systems(EventLoopPreUpdate, update_server_player_abilities);
+ }
}
fn update_client_player_abilities(
diff --git a/crates/valence_client/src/action.rs b/crates/valence_server/src/action.rs
similarity index 80%
rename from crates/valence_client/src/action.rs
rename to crates/valence_server/src/action.rs
index 05f36fe1d..320377608 100644
--- a/crates/valence_client/src/action.rs
+++ b/crates/valence_server/src/action.rs
@@ -1,19 +1,23 @@
-use valence_core::block_pos::BlockPos;
-use valence_core::direction::Direction;
-use valence_core::protocol::var_int::VarInt;
-use valence_packet::packets::play::player_action_c2s::PlayerAction;
-use valence_packet::packets::play::{PlayerActionC2s, PlayerActionResponseS2c};
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+use valence_protocol::packets::play::player_action_c2s::PlayerAction;
+use valence_protocol::packets::play::{PlayerActionC2s, PlayerActionResponseS2c};
+use valence_protocol::{BlockPos, Direction, VarInt, WritePacket};
-use super::*;
+use crate::client::{Client, UpdateClientsSet};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_player_action)
- .add_systems(
- PostUpdate,
- acknowledge_player_actions.in_set(UpdateClientsSet),
- );
+pub struct ActionPlugin;
+
+impl Plugin for ActionPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_player_action)
+ .add_systems(
+ PostUpdate,
+ acknowledge_player_actions.in_set(UpdateClientsSet),
+ );
+ }
}
#[derive(Event, Copy, Clone, Debug)]
diff --git a/crates/valence_core/src/chunk_pos.rs b/crates/valence_server/src/chunk_view.rs
similarity index 62%
rename from crates/valence_core/src/chunk_pos.rs
rename to crates/valence_server/src/chunk_view.rs
index 88db14dbd..134949faf 100644
--- a/crates/valence_core/src/chunk_pos.rs
+++ b/crates/valence_server/src/chunk_view.rs
@@ -1,66 +1,5 @@
-use glam::DVec3;
-
-use crate::block_pos::BlockPos;
-use crate::protocol::{Decode, Encode};
-
-/// The X and Z position of a chunk.
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash, Debug, Encode, Decode)]
-pub struct ChunkPos {
- /// The X position of the chunk.
- pub x: i32,
- /// The Z position of the chunk.
- pub z: i32,
-}
-
-impl ChunkPos {
- /// Constructs a new chunk position.
- pub const fn new(x: i32, z: i32) -> Self {
- Self { x, z }
- }
-
- /// Constructs a chunk position from a position in world space. Only the `x`
- /// and `z` components are used.
- pub fn from_pos(pos: DVec3) -> Self {
- Self::new((pos.x / 16.0).floor() as i32, (pos.z / 16.0).floor() as i32)
- }
-
- pub const fn from_block_pos(pos: BlockPos) -> Self {
- Self::new(pos.x.div_euclid(16), pos.z.div_euclid(16))
- }
-
- pub const fn distance_squared(self, other: Self) -> u64 {
- let diff_x = other.x as i64 - self.x as i64;
- let diff_z = other.z as i64 - self.z as i64;
-
- (diff_x * diff_x + diff_z * diff_z) as u64
- }
-}
-
-impl From<(i32, i32)> for ChunkPos {
- fn from((x, z): (i32, i32)) -> Self {
- Self { x, z }
- }
-}
-
-impl From for (i32, i32) {
- fn from(pos: ChunkPos) -> Self {
- (pos.x, pos.z)
- }
-}
-
-impl From<[i32; 2]> for ChunkPos {
- fn from([x, z]: [i32; 2]) -> Self {
- Self { x, z }
- }
-}
-
-impl From for [i32; 2] {
- fn from(pos: ChunkPos) -> Self {
- [pos.x, pos.z]
- }
-}
-
-include!(concat!(env!("OUT_DIR"), "/chunk_pos.rs"));
+use valence_generated::chunk_view::{CHUNK_VIEW_LUT, EXTRA_VIEW_RADIUS, MAX_VIEW_DIST};
+use valence_protocol::ChunkPos;
/// Represents the set of all chunk positions that a client can see, defined by
/// a center chunk position `pos` and view distance `dist`.
@@ -123,7 +62,7 @@ impl ChunkView {
/// # Examples
///
/// ```
- /// use valence_core::chunk_pos::{ChunkPos, ChunkView};
+ /// use valence_server::{ChunkPos, ChunkView};
///
/// let view = ChunkView::new(ChunkPos::new(5, -4), 16);
/// let (min, max) = view.bounding_box();
@@ -160,12 +99,4 @@ mod tests {
}
}
}
-
- #[test]
- fn chunk_pos_round_trip_conv() {
- let p = ChunkPos::new(rand::random(), rand::random());
-
- assert_eq!(ChunkPos::from(<(i32, i32)>::from(p)), p);
- assert_eq!(ChunkPos::from(<[i32; 2]>::from(p)), p);
- }
}
diff --git a/crates/valence_client/src/lib.rs b/crates/valence_server/src/client.rs
similarity index 83%
rename from crates/valence_client/src/lib.rs
rename to crates/valence_server/src/client.rs
index c468f69b9..5f444ca41 100644
--- a/crates/valence_client/src/lib.rs
+++ b/crates/valence_server/src/client.rs
@@ -1,23 +1,3 @@
-#![doc = include_str!("../README.md")]
-#![deny(
- rustdoc::broken_intra_doc_links,
- rustdoc::private_intra_doc_links,
- rustdoc::missing_crate_level_docs,
- rustdoc::invalid_codeblock_attributes,
- rustdoc::invalid_rust_codeblocks,
- rustdoc::bare_urls,
- rustdoc::invalid_html_tags
-)]
-#![warn(
- trivial_casts,
- trivial_numeric_casts,
- unused_lifetimes,
- unused_import_braces,
- unreachable_pub,
- clippy::dbg_macro
-)]
-#![allow(clippy::type_complexity)]
-
use std::borrow::Cow;
use std::collections::BTreeSet;
use std::fmt;
@@ -31,62 +11,33 @@ use bevy_ecs::query::WorldQuery;
use bevy_ecs::system::Command;
use byteorder::{NativeEndian, ReadBytesExt};
use bytes::{Bytes, BytesMut};
-use glam::{DVec3, Vec3};
use tracing::warn;
use uuid::Uuid;
-use valence_biome::BiomeRegistry;
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::{ChunkPos, ChunkView};
-use valence_core::despawn::Despawned;
-use valence_core::game_mode::GameMode;
-use valence_core::ident::Ident;
-use valence_core::property::Property;
-use valence_core::protocol::global_pos::GlobalPos;
-use valence_core::protocol::var_int::VarInt;
-use valence_core::protocol::Encode;
-use valence_core::sound::{Sound, SoundCategory};
-use valence_core::text::{IntoText, Text};
-use valence_core::uuid::UniqueId;
use valence_entity::player::PlayerEntityBundle;
use valence_entity::query::EntityInitQuery;
use valence_entity::tracked_data::TrackedData;
use valence_entity::{
- ClearEntityChangesSet, EntityId, EntityLayerId, EntityStatus, Look, OldPosition, Position,
- Velocity,
+ ClearEntityChangesSet, EntityId, EntityStatus, OldPosition, Position, Velocity,
};
-use valence_layer::{ChunkLayer, EntityLayer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
-use valence_packet::packets::play::chunk_biome_data_s2c::ChunkBiome;
-use valence_packet::packets::play::game_state_change_s2c::GameEventKind;
-use valence_packet::packets::play::particle_s2c::Particle;
-use valence_packet::packets::play::{
+use valence_math::{DVec3, Vec3};
+use valence_protocol::encode::{PacketEncoder, WritePacket};
+use valence_protocol::packets::play::chunk_biome_data_s2c::ChunkBiome;
+use valence_protocol::packets::play::game_state_change_s2c::GameEventKind;
+use valence_protocol::packets::play::particle_s2c::Particle;
+use valence_protocol::packets::play::{
ChunkBiomeDataS2c, ChunkLoadDistanceS2c, ChunkRenderDistanceCenterS2c, DeathMessageS2c,
DisconnectS2c, EntitiesDestroyS2c, EntityStatusS2c, EntityTrackerUpdateS2c,
- EntityVelocityUpdateS2c, GameJoinS2c, GameStateChangeS2c, ParticleS2c, PlaySoundS2c,
- PlayerRespawnS2c, PlayerSpawnPositionS2c, UnloadChunkS2c,
+ EntityVelocityUpdateS2c, GameStateChangeS2c, ParticleS2c, PlaySoundS2c, UnloadChunkS2c,
};
-use valence_packet::protocol::encode::{PacketEncoder, WritePacket};
-use valence_packet::protocol::Packet;
+use valence_protocol::sound::{Sound, SoundCategory, SoundId};
+use valence_protocol::text::{IntoText, Text};
+use valence_protocol::var_int::VarInt;
+use valence_protocol::{BlockPos, ChunkPos, Encode, GameMode, Packet, Property};
use valence_registry::RegistrySet;
+use valence_server_core::{Despawned, UniqueId};
-pub mod abilities;
-pub mod action;
-pub mod command;
-pub mod custom_payload;
-pub mod event_loop;
-pub mod hand_swing;
-pub mod interact_block;
-pub mod interact_entity;
-pub mod interact_item;
-pub mod keepalive;
-pub mod message;
-pub mod movement;
-pub mod op_level;
-pub mod resource_pack;
-pub mod settings;
-pub mod spawn;
-pub mod status;
-pub mod teleport;
-pub mod title;
+use crate::layer::{ChunkLayer, EntityLayer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
+use crate::ChunkView;
pub struct ClientPlugin;
@@ -113,15 +64,15 @@ impl Plugin for ClientPlugin {
PostUpdate,
(
(
- spawn::initial_join.after(RegistrySet),
+ crate::spawn::initial_join.after(RegistrySet),
update_chunk_load_dist,
handle_layer_messages.after(update_chunk_load_dist),
update_view_and_layers
- .after(spawn::initial_join)
+ .after(crate::spawn::initial_join)
.after(handle_layer_messages),
cleanup_chunks_after_client_despawn.after(update_view_and_layers),
- spawn::update_respawn_position.after(update_view_and_layers),
- spawn::respawn.after(spawn::update_respawn_position),
+ crate::spawn::update_respawn_position.after(update_view_and_layers),
+ crate::spawn::respawn.after(crate::spawn::update_respawn_position),
update_old_view_dist.after(update_view_and_layers),
update_game_mode,
update_tracked_data,
@@ -143,25 +94,6 @@ impl Plugin for ClientPlugin {
FlushPacketsSet,
),
);
-
- event_loop::build(app);
- movement::build(app);
- command::build(app);
- keepalive::build(app);
- interact_entity::build(app);
- settings::build(app);
- action::build(app);
- teleport::build(app);
- // weather::build(app);
- message::build(app);
- custom_payload::build(app);
- hand_swing::build(app);
- interact_block::build(app);
- interact_item::build(app);
- op_level::build(app);
- resource_pack::build(app);
- status::build(app);
- abilities::build(app);
}
}
@@ -171,36 +103,36 @@ impl Plugin for ClientPlugin {
pub struct ClientBundle {
pub marker: ClientMarker,
pub client: Client,
- pub settings: settings::ClientSettings,
+ pub settings: crate::client_settings::ClientSettings,
pub entity_remove_buf: EntityRemoveBuf,
pub username: Username,
pub ip: Ip,
pub properties: Properties,
- pub respawn_pos: RespawnPosition,
- pub op_level: op_level::OpLevel,
- pub action_sequence: action::ActionSequence,
+ pub respawn_pos: crate::spawn::RespawnPosition,
+ pub op_level: crate::op_level::OpLevel,
+ pub action_sequence: crate::action::ActionSequence,
pub view_distance: ViewDistance,
pub old_view_distance: OldViewDistance,
pub visible_chunk_layer: VisibleChunkLayer,
pub old_visible_chunk_layer: OldVisibleChunkLayer,
pub visible_entity_layers: VisibleEntityLayers,
pub old_visible_entity_layers: OldVisibleEntityLayers,
- pub keepalive_state: keepalive::KeepaliveState,
- pub ping: Ping,
- pub teleport_state: teleport::TeleportState,
+ pub keepalive_state: crate::keepalive::KeepaliveState,
+ pub ping: crate::keepalive::Ping,
+ pub teleport_state: crate::teleport::TeleportState,
pub game_mode: GameMode,
- pub prev_game_mode: spawn::PrevGameMode,
- pub death_location: spawn::DeathLocation,
- pub is_hardcore: spawn::IsHardcore,
- pub hashed_seed: spawn::HashedSeed,
- pub reduced_debug_info: spawn::ReducedDebugInfo,
- pub has_respawn_screen: spawn::HasRespawnScreen,
- pub is_debug: spawn::IsDebug,
- pub is_flat: spawn::IsFlat,
- pub portal_cooldown: spawn::PortalCooldown,
- pub player_abilities_flags: abilities::PlayerAbilitiesFlags,
- pub flying_speed: abilities::FlyingSpeed,
- pub fov_modifier: abilities::FovModifier,
+ pub prev_game_mode: crate::spawn::PrevGameMode,
+ pub death_location: crate::spawn::DeathLocation,
+ pub is_hardcore: crate::spawn::IsHardcore,
+ pub hashed_seed: crate::spawn::HashedSeed,
+ pub reduced_debug_info: crate::spawn::ReducedDebugInfo,
+ pub has_respawn_screen: crate::spawn::HasRespawnScreen,
+ pub is_debug: crate::spawn::IsDebug,
+ pub is_flat: crate::spawn::IsFlat,
+ pub portal_cooldown: crate::spawn::PortalCooldown,
+ pub flying_speed: crate::abilities::FlyingSpeed,
+ pub fov_modifier: crate::abilities::FovModifier,
+ pub player_abilities_flags: crate::abilities::PlayerAbilitiesFlags,
pub player: PlayerEntityBundle,
}
@@ -212,36 +144,36 @@ impl ClientBundle {
conn: args.conn,
enc: args.enc,
},
- settings: settings::ClientSettings::default(),
- entity_remove_buf: EntityRemoveBuf(vec![]),
+ settings: Default::default(),
+ entity_remove_buf: Default::default(),
username: Username(args.username),
ip: Ip(args.ip),
properties: Properties(args.properties),
- respawn_pos: RespawnPosition::default(),
- op_level: op_level::OpLevel::default(),
- action_sequence: action::ActionSequence::default(),
- view_distance: ViewDistance::default(),
+ respawn_pos: Default::default(),
+ op_level: Default::default(),
+ action_sequence: Default::default(),
+ view_distance: Default::default(),
old_view_distance: OldViewDistance(2),
- visible_chunk_layer: VisibleChunkLayer::default(),
+ visible_chunk_layer: Default::default(),
old_visible_chunk_layer: OldVisibleChunkLayer(Entity::PLACEHOLDER),
- visible_entity_layers: VisibleEntityLayers::default(),
+ visible_entity_layers: Default::default(),
old_visible_entity_layers: OldVisibleEntityLayers(BTreeSet::new()),
- keepalive_state: keepalive::KeepaliveState::new(),
- ping: Ping::default(),
- teleport_state: teleport::TeleportState::new(),
+ keepalive_state: crate::keepalive::KeepaliveState::new(),
+ ping: Default::default(),
+ teleport_state: crate::teleport::TeleportState::new(),
game_mode: GameMode::default(),
- prev_game_mode: spawn::PrevGameMode::default(),
- death_location: spawn::DeathLocation::default(),
- is_hardcore: spawn::IsHardcore::default(),
- is_flat: spawn::IsFlat::default(),
- has_respawn_screen: spawn::HasRespawnScreen::default(),
- hashed_seed: spawn::HashedSeed::default(),
- reduced_debug_info: spawn::ReducedDebugInfo::default(),
- is_debug: spawn::IsDebug::default(),
- portal_cooldown: spawn::PortalCooldown::default(),
- player_abilities_flags: abilities::PlayerAbilitiesFlags::default(),
- flying_speed: abilities::FlyingSpeed::default(),
- fov_modifier: abilities::FovModifier::default(),
+ prev_game_mode: Default::default(),
+ death_location: Default::default(),
+ is_hardcore: Default::default(),
+ is_flat: Default::default(),
+ has_respawn_screen: Default::default(),
+ hashed_seed: Default::default(),
+ reduced_debug_info: Default::default(),
+ is_debug: Default::default(),
+ portal_cooldown: Default::default(),
+ flying_speed: Default::default(),
+ fov_modifier: Default::default(),
+ player_abilities_flags: Default::default(),
player: PlayerEntityBundle {
uuid: UniqueId(args.uuid),
..Default::default()
@@ -275,7 +207,7 @@ pub struct ClientMarker;
#[derive(Component)]
pub struct Client {
conn: Box,
- enc: PacketEncoder,
+ pub(crate) enc: PacketEncoder,
}
/// Represents the bidirectional packet channel between the server and a client
@@ -402,7 +334,10 @@ impl Client {
let position = position.into();
self.write_packet(&PlaySoundS2c {
- id: sound.to_id(),
+ id: SoundId::Direct {
+ id: sound.to_ident().into(),
+ range: None,
+ },
category,
position: (position * 8.0).as_ivec3(),
volume,
@@ -455,7 +390,7 @@ impl Command for DisconnectClient {
/// in this list will be despawned all at once at the end of the tick.
///
/// You should not need to use this directly under normal circumstances.
-#[derive(Component, Debug)]
+#[derive(Component, Default, Debug)]
pub struct EntityRemoveBuf(Vec);
impl EntityRemoveBuf {
@@ -522,17 +457,6 @@ impl Deref for Properties {
#[derive(Component, Clone, PartialEq, Eq, Debug)]
pub struct Ip(pub IpAddr);
-/// The position and angle that clients will respawn with. Also
-/// controls the position that compasses point towards.
-#[derive(Component, Copy, Clone, PartialEq, Default, Debug)]
-pub struct RespawnPosition {
- /// The position that clients will respawn at. This can be changed at any
- /// time to set the position that compasses point towards.
- pub pos: BlockPos,
- /// The yaw angle that clients will respawn with (in degrees).
- pub yaw: f32,
-}
-
#[derive(Component, Clone, PartialEq, Eq, Debug)]
pub struct ViewDistance(u8);
@@ -595,16 +519,6 @@ impl OldViewItem<'_> {
}
}
-/// Delay measured in milliseconds. Negative values indicate absence.
-#[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
-pub struct Ping(pub i32);
-
-impl Default for Ping {
- fn default() -> Self {
- Self(-1)
- }
-}
-
/// A [`Component`] containing a handle to the [`ChunkLayer`] a client can
/// see.
///
@@ -724,10 +638,10 @@ fn handle_layer_messages(
// Global messages
for (msg, range) in messages.iter_global() {
match msg {
- valence_layer::chunk::GlobalMsg::Packet => {
+ crate::layer::chunk::GlobalMsg::Packet => {
client.write_packet_bytes(&bytes[range]);
}
- valence_layer::chunk::GlobalMsg::PacketExcept { except } => {
+ crate::layer::chunk::GlobalMsg::PacketExcept { except } => {
if self_entity != except {
client.write_packet_bytes(&bytes[range]);
}
@@ -739,15 +653,15 @@ fn handle_layer_messages(
// Local messages
messages.query_local(old_view, |msg, range| match msg {
- valence_layer::chunk::LocalMsg::PacketAt { .. } => {
+ crate::layer::chunk::LocalMsg::PacketAt { .. } => {
client.write_packet_bytes(&bytes[range]);
}
- valence_layer::chunk::LocalMsg::PacketAtExcept { except, .. } => {
+ crate::layer::chunk::LocalMsg::PacketAtExcept { except, .. } => {
if self_entity != except {
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::chunk::LocalMsg::RadiusAt {
+ crate::layer::chunk::LocalMsg::RadiusAt {
center,
radius_squared,
} => {
@@ -755,7 +669,7 @@ fn handle_layer_messages(
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::chunk::LocalMsg::RadiusAtExcept {
+ crate::layer::chunk::LocalMsg::RadiusAtExcept {
center,
radius_squared,
except,
@@ -764,13 +678,13 @@ fn handle_layer_messages(
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::chunk::LocalMsg::ChangeBiome { pos } => {
+ crate::layer::chunk::LocalMsg::ChangeBiome { pos } => {
chunk_biome_buf.push(ChunkBiome {
pos,
data: &bytes[range],
});
}
- valence_layer::chunk::LocalMsg::ChangeChunkState { pos } => {
+ crate::layer::chunk::LocalMsg::ChangeChunkState { pos } => {
match &bytes[range] {
[ChunkLayer::LOAD, .., ChunkLayer::UNLOAD] => {
// Chunk is being loaded and unloaded on the
@@ -809,15 +723,15 @@ fn handle_layer_messages(
// Global messages
for (msg, range) in messages.iter_global() {
match msg {
- valence_layer::entity::GlobalMsg::Packet => {
+ crate::layer::entity::GlobalMsg::Packet => {
client.write_packet_bytes(&bytes[range]);
}
- valence_layer::entity::GlobalMsg::PacketExcept { except } => {
+ crate::layer::entity::GlobalMsg::PacketExcept { except } => {
if self_entity != except {
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::entity::GlobalMsg::DespawnLayer => {
+ crate::layer::entity::GlobalMsg::DespawnLayer => {
// Remove this entity layer. The changes to the visible entity layer
// set will be detected by the `update_view_and_layers` system and
// despawning of entities will happen there.
@@ -828,7 +742,7 @@ fn handle_layer_messages(
// Local messages
messages.query_local(old_view, |msg, range| match msg {
- valence_layer::entity::LocalMsg::DespawnEntity { pos: _, dest_layer } => {
+ crate::layer::entity::LocalMsg::DespawnEntity { pos: _, dest_layer } => {
if !old_visible_entity_layers.0.contains(&dest_layer) {
let mut bytes = &bytes[range];
@@ -839,7 +753,7 @@ fn handle_layer_messages(
}
}
}
- valence_layer::entity::LocalMsg::DespawnEntityTransition {
+ crate::layer::entity::LocalMsg::DespawnEntityTransition {
pos: _,
dest_pos,
} => {
@@ -853,7 +767,7 @@ fn handle_layer_messages(
}
}
}
- valence_layer::entity::LocalMsg::SpawnEntity { pos: _, src_layer } => {
+ crate::layer::entity::LocalMsg::SpawnEntity { pos: _, src_layer } => {
if !old_visible_entity_layers.0.contains(&src_layer) {
let mut bytes = &bytes[range];
@@ -873,7 +787,7 @@ fn handle_layer_messages(
}
}
}
- valence_layer::entity::LocalMsg::SpawnEntityTransition {
+ crate::layer::entity::LocalMsg::SpawnEntityTransition {
pos: _,
src_pos,
} => {
@@ -896,15 +810,15 @@ fn handle_layer_messages(
}
}
}
- valence_layer::entity::LocalMsg::PacketAt { pos: _ } => {
+ crate::layer::entity::LocalMsg::PacketAt { pos: _ } => {
client.write_packet_bytes(&bytes[range]);
}
- valence_layer::entity::LocalMsg::PacketAtExcept { pos: _, except } => {
+ crate::layer::entity::LocalMsg::PacketAtExcept { pos: _, except } => {
if self_entity != except {
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::entity::LocalMsg::RadiusAt {
+ crate::layer::entity::LocalMsg::RadiusAt {
center,
radius_squared,
} => {
@@ -912,7 +826,7 @@ fn handle_layer_messages(
client.write_packet_bytes(&bytes[range]);
}
}
- valence_layer::entity::LocalMsg::RadiusAtExcept {
+ crate::layer::entity::LocalMsg::RadiusAtExcept {
center,
radius_squared,
except,
@@ -931,7 +845,7 @@ fn handle_layer_messages(
);
}
-fn update_view_and_layers(
+pub(crate) fn update_view_and_layers(
mut clients: Query<
(
Entity,
@@ -1152,7 +1066,7 @@ fn update_view_and_layers(
);
}
-fn update_game_mode(mut clients: Query<(&mut Client, &GameMode), Changed>) {
+pub(crate) fn update_game_mode(mut clients: Query<(&mut Client, &GameMode), Changed>) {
for (mut client, game_mode) in &mut clients {
if client.is_added() {
// Game join packet includes the initial game mode.
diff --git a/crates/valence_client/src/command.rs b/crates/valence_server/src/client_command.rs
similarity index 90%
rename from crates/valence_client/src/command.rs
rename to crates/valence_server/src/client_command.rs
index 8f67d905a..b21b8c01b 100644
--- a/crates/valence_client/src/command.rs
+++ b/crates/valence_server/src/client_command.rs
@@ -2,17 +2,21 @@ use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use valence_entity::entity::Flags;
use valence_entity::{entity, Pose};
-pub use valence_packet::packets::play::client_command_c2s::ClientCommand;
-use valence_packet::packets::play::ClientCommandC2s;
+pub use valence_protocol::packets::play::client_command_c2s::ClientCommand;
+use valence_protocol::packets::play::ClientCommandC2s;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_event::()
- .add_event::()
- .add_event::()
- .add_systems(EventLoopPreUpdate, handle_client_command);
+pub struct ClientCommandPlugin;
+
+impl Plugin for ClientCommandPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_event::()
+ .add_event::()
+ .add_event::()
+ .add_systems(EventLoopPreUpdate, handle_client_command);
+ }
}
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
diff --git a/crates/valence_client/src/settings.rs b/crates/valence_server/src/client_settings.rs
similarity index 81%
rename from crates/valence_client/src/settings.rs
rename to crates/valence_server/src/client_settings.rs
index 2c99d32ab..1b058ecd3 100644
--- a/crates/valence_client/src/settings.rs
+++ b/crates/valence_server/src/client_settings.rs
@@ -1,14 +1,18 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use valence_entity::player::{self, PlayerModelParts};
-use valence_packet::packets::play::client_settings_c2s::ChatMode;
-use valence_packet::packets::play::ClientSettingsC2s;
+use valence_protocol::packets::play::client_settings_c2s::ChatMode;
+use valence_protocol::packets::play::ClientSettingsC2s;
+use crate::client::ViewDistance;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-use crate::ViewDistance;
-pub(super) fn build(app: &mut App) {
- app.add_systems(EventLoopPreUpdate, handle_client_settings);
+pub struct ClientSettingsPlugin;
+
+impl Plugin for ClientSettingsPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_systems(EventLoopPreUpdate, handle_client_settings);
+ }
}
/// Component containing client-controlled settings about a client.
diff --git a/crates/valence_client/src/custom_payload.rs b/crates/valence_server/src/custom_payload.rs
similarity index 66%
rename from crates/valence_client/src/custom_payload.rs
rename to crates/valence_server/src/custom_payload.rs
index 5f35ad7d4..6d545ea32 100644
--- a/crates/valence_client/src/custom_payload.rs
+++ b/crates/valence_server/src/custom_payload.rs
@@ -1,11 +1,18 @@
-use valence_packet::packets::play::{CustomPayloadC2s, CustomPayloadS2c};
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+use valence_protocol::packets::play::{CustomPayloadC2s, CustomPayloadS2c};
+use valence_protocol::{Ident, WritePacket};
-use super::*;
+use crate::client::Client;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_custom_payload);
+pub struct CustomPayloadPlugin;
+
+impl Plugin for CustomPayloadPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_custom_payload);
+ }
}
#[derive(Event, Clone, Debug)]
diff --git a/crates/valence_client/src/event_loop.rs b/crates/valence_server/src/event_loop.rs
similarity index 88%
rename from crates/valence_client/src/event_loop.rs
rename to crates/valence_server/src/event_loop.rs
index b2be540ee..1e43703ac 100644
--- a/crates/valence_client/src/event_loop.rs
+++ b/crates/valence_server/src/event_loop.rs
@@ -7,22 +7,25 @@ use bevy_ecs::schedule::ScheduleLabel;
use bevy_ecs::system::SystemState;
use bytes::Bytes;
use tracing::{debug, warn};
-use valence_core::protocol::Decode;
-use valence_packet::protocol::Packet;
-
-use crate::Client;
-
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_schedule(RunEventLoop, Schedule::new())
- .add_schedule(EventLoopPreUpdate, Schedule::new())
- .add_schedule(EventLoopUpdate, Schedule::new())
- .add_schedule(EventLoopPostUpdate, Schedule::new())
- .add_systems(RunEventLoop, run_event_loop);
-
- app.world
- .resource_mut::()
- .insert_after(PreUpdate, RunEventLoop);
+use valence_protocol::{Decode, Packet};
+
+use crate::client::Client;
+
+pub struct EventLoopPlugin;
+
+impl Plugin for EventLoopPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_schedule(RunEventLoop, Schedule::new())
+ .add_schedule(EventLoopPreUpdate, Schedule::new())
+ .add_schedule(EventLoopUpdate, Schedule::new())
+ .add_schedule(EventLoopPostUpdate, Schedule::new())
+ .add_systems(RunEventLoop, run_event_loop);
+
+ app.world
+ .resource_mut::()
+ .insert_after(PreUpdate, RunEventLoop);
+ }
}
/// The schedule responsible for running [`EventLoopPreUpdate`],
diff --git a/crates/valence_client/src/hand_swing.rs b/crates/valence_server/src/hand_swing.rs
similarity index 77%
rename from crates/valence_client/src/hand_swing.rs
rename to crates/valence_server/src/hand_swing.rs
index ebf70bef4..1b5acfc3e 100644
--- a/crates/valence_client/src/hand_swing.rs
+++ b/crates/valence_server/src/hand_swing.rs
@@ -1,14 +1,18 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_core::hand::Hand;
use valence_entity::{EntityAnimation, EntityAnimations};
-use valence_packet::packets::play::HandSwingC2s;
+use valence_protocol::packets::play::HandSwingC2s;
+use valence_protocol::Hand;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_hand_swing);
+pub struct HandSwingPlugin;
+
+impl Plugin for HandSwingPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_hand_swing);
+ }
}
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
diff --git a/crates/valence_client/src/interact_block.rs b/crates/valence_server/src/interact_block.rs
similarity index 80%
rename from crates/valence_client/src/interact_block.rs
rename to crates/valence_server/src/interact_block.rs
index f9bf8fe5e..ff723a904 100644
--- a/crates/valence_client/src/interact_block.rs
+++ b/crates/valence_server/src/interact_block.rs
@@ -1,17 +1,19 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use glam::Vec3;
-use valence_core::block_pos::BlockPos;
-use valence_core::direction::Direction;
-use valence_core::hand::Hand;
-use valence_packet::packets::play::PlayerInteractBlockC2s;
+use valence_math::Vec3;
+use valence_protocol::packets::play::PlayerInteractBlockC2s;
+use valence_protocol::{BlockPos, Direction, Hand};
use crate::action::ActionSequence;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_interact_block);
+pub struct InteractBlockPlugin;
+
+impl Plugin for InteractBlockPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_interact_block);
+ }
}
#[derive(Event, Copy, Clone, Debug)]
diff --git a/crates/valence_client/src/interact_entity.rs b/crates/valence_server/src/interact_entity.rs
similarity index 77%
rename from crates/valence_client/src/interact_entity.rs
rename to crates/valence_server/src/interact_entity.rs
index c6025843b..a1e645e95 100644
--- a/crates/valence_client/src/interact_entity.rs
+++ b/crates/valence_server/src/interact_entity.rs
@@ -1,14 +1,18 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use valence_entity::EntityManager;
-pub use valence_packet::packets::play::player_interact_entity_c2s::EntityInteraction;
-use valence_packet::packets::play::PlayerInteractEntityC2s;
+pub use valence_protocol::packets::play::player_interact_entity_c2s::EntityInteraction;
+use valence_protocol::packets::play::PlayerInteractEntityC2s;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_interact_entity);
+pub struct InteractEntityPlugin;
+
+impl Plugin for InteractEntityPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_interact_entity);
+ }
}
#[derive(Event, Copy, Clone, Debug)]
diff --git a/crates/valence_client/src/interact_item.rs b/crates/valence_server/src/interact_item.rs
similarity index 73%
rename from crates/valence_client/src/interact_item.rs
rename to crates/valence_server/src/interact_item.rs
index 09f61080c..335e9ab05 100644
--- a/crates/valence_client/src/interact_item.rs
+++ b/crates/valence_server/src/interact_item.rs
@@ -1,14 +1,18 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_core::hand::Hand;
-use valence_packet::packets::play::PlayerInteractItemC2s;
+use valence_protocol::packets::play::PlayerInteractItemC2s;
+use valence_protocol::Hand;
use crate::action::ActionSequence;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_player_interact_item);
+pub struct InteractItemPlugin;
+
+impl Plugin for InteractItemPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_player_interact_item);
+ }
}
#[derive(Event, Copy, Clone, Debug)]
diff --git a/crates/valence_client/src/keepalive.rs b/crates/valence_server/src/keepalive.rs
similarity index 77%
rename from crates/valence_client/src/keepalive.rs
rename to crates/valence_server/src/keepalive.rs
index 284160bc0..fab5368e0 100644
--- a/crates/valence_client/src/keepalive.rs
+++ b/crates/valence_server/src/keepalive.rs
@@ -1,14 +1,22 @@
-use std::time::Duration;
+use std::time::{Duration, Instant};
-use valence_packet::packets::play::{KeepAliveC2s, KeepAliveS2c};
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+use tracing::warn;
+use valence_protocol::packets::play::{KeepAliveC2s, KeepAliveS2c};
+use valence_protocol::WritePacket;
-use super::*;
+use crate::client::{Client, UpdateClientsSet};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.init_resource::()
- .add_systems(PostUpdate, send_keepalive.in_set(UpdateClientsSet))
- .add_systems(EventLoopPreUpdate, handle_keepalive_response);
+pub struct KeepalivePlugin;
+
+impl Plugin for KeepalivePlugin {
+ fn build(&self, app: &mut App) {
+ app.init_resource::()
+ .add_systems(PostUpdate, send_keepalive.in_set(UpdateClientsSet))
+ .add_systems(EventLoopPreUpdate, handle_keepalive_response);
+ }
}
#[derive(Resource, Debug)]
@@ -32,6 +40,16 @@ pub struct KeepaliveState {
last_send: Instant,
}
+/// Delay measured in milliseconds. Negative values indicate absence.
+#[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
+pub struct Ping(pub i32);
+
+impl Default for Ping {
+ fn default() -> Self {
+ Self(-1)
+ }
+}
+
impl KeepaliveState {
pub(super) fn new() -> Self {
Self {
diff --git a/crates/valence_layer/src/lib.rs b/crates/valence_server/src/layer.rs
similarity index 77%
rename from crates/valence_layer/src/lib.rs
rename to crates/valence_server/src/layer.rs
index 52fba6ff6..94621861e 100644
--- a/crates/valence_layer/src/lib.rs
+++ b/crates/valence_server/src/layer.rs
@@ -1,57 +1,25 @@
-#![doc = include_str!("../README.md")]
-#![deny(
- rustdoc::broken_intra_doc_links,
- rustdoc::private_intra_doc_links,
- rustdoc::missing_crate_level_docs,
- rustdoc::invalid_codeblock_attributes,
- rustdoc::invalid_rust_codeblocks,
- rustdoc::bare_urls,
- rustdoc::invalid_html_tags
-)]
-#![warn(
- trivial_casts,
- trivial_numeric_casts,
- unused_lifetimes,
- unused_import_braces,
- unreachable_pub,
- clippy::dbg_macro
-)]
-#![allow(clippy::type_complexity)]
+//! Defines chunk layers and entity layers. Chunk layers contain the chunks and
+//! dimension data of a world, while entity layers contain all the Minecraft
+//! entities.
+//!
+//! These two together are analogous to Minecraft "levels" or "worlds".
pub mod bvh;
pub mod chunk;
pub mod entity;
pub mod message;
-use std::marker::PhantomData;
-
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
pub use chunk::ChunkLayer;
pub use entity::EntityLayer;
-use valence_biome::BiomeRegistry;
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::ChunkPos;
-use valence_core::ident::Ident;
-use valence_core::Server;
-use valence_dimension::DimensionTypeRegistry;
use valence_entity::{InitEntitiesSet, UpdateTrackedDataSet};
-use valence_packet::protocol::encode::WritePacket;
-
-// Plugin is generic over the client type for hacky reasons.
-pub struct LayerPlugin(PhantomData);
+use valence_protocol::encode::WritePacket;
+use valence_protocol::{BlockPos, ChunkPos, Ident};
+use valence_registry::{BiomeRegistry, DimensionTypeRegistry};
+use valence_server_core::Server;
-impl LayerPlugin {
- pub fn new() -> Self {
- Self(PhantomData)
- }
-}
-
-impl Default for LayerPlugin {
- fn default() -> Self {
- Self::new()
- }
-}
+pub struct LayerPlugin;
/// When entity and chunk changes are written to layers. Systems that modify
/// chunks and entities should run _before_ this. Systems that need to read
@@ -64,7 +32,7 @@ pub struct UpdateLayersPreClientSet;
#[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct UpdateLayersPostClientSet;
-impl Plugin for LayerPlugin {
+impl Plugin for LayerPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
PostUpdate,
@@ -77,7 +45,7 @@ impl Plugin for LayerPlugin {
);
chunk::build(app);
- entity::build::(app);
+ entity::build(app);
}
}
diff --git a/crates/valence_layer/src/bvh.rs b/crates/valence_server/src/layer/bvh.rs
similarity index 99%
rename from crates/valence_layer/src/bvh.rs
rename to crates/valence_server/src/layer/bvh.rs
index f2c89c434..4f63cd01b 100644
--- a/crates/valence_layer/src/bvh.rs
+++ b/crates/valence_server/src/layer/bvh.rs
@@ -1,7 +1,9 @@
use std::mem;
use std::ops::Range;
-use valence_core::chunk_pos::{ChunkPos, ChunkView};
+use valence_protocol::ChunkPos;
+
+use crate::ChunkView;
/// A bounding volume hierarchy for chunk positions.
#[derive(Clone, Debug)]
diff --git a/crates/valence_layer/src/chunk.rs b/crates/valence_server/src/layer/chunk.rs
similarity index 89%
rename from crates/valence_layer/src/chunk.rs
rename to crates/valence_server/src/layer/chunk.rs
index ea7ad59bf..2f51effd0 100644
--- a/crates/valence_layer/src/chunk.rs
+++ b/crates/valence_server/src/layer/chunk.rs
@@ -10,31 +10,28 @@ use std::fmt;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use glam::{DVec3, Vec3};
+pub use chunk::{MAX_HEIGHT, *};
+pub use loaded::LoadedChunk;
use rustc_hash::FxHashMap;
-use valence_biome::{BiomeId, BiomeRegistry};
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::ChunkPos;
-use valence_core::ident::Ident;
-use valence_core::protocol::Encode;
-use valence_core::sound::{Sound, SoundCategory};
-use valence_core::Server;
-use valence_dimension::DimensionTypeRegistry;
+pub use unloaded::UnloadedChunk;
+use valence_math::{DVec3, Vec3};
use valence_nbt::Compound;
-use valence_packet::packets::play::particle_s2c::Particle;
-use valence_packet::packets::play::{ParticleS2c, PlaySoundS2c};
-use valence_packet::protocol::encode::{PacketWriter, WritePacket};
-use valence_packet::protocol::Packet;
-
-pub use self::chunk::{MAX_HEIGHT, *};
-pub use self::loaded::LoadedChunk;
-pub use self::unloaded::UnloadedChunk;
-use crate::bvh::GetChunkPos;
-use crate::message::Messages;
-use crate::{Layer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
+use valence_protocol::encode::{PacketWriter, WritePacket};
+use valence_protocol::packets::play::particle_s2c::Particle;
+use valence_protocol::packets::play::{ParticleS2c, PlaySoundS2c};
+use valence_protocol::sound::{Sound, SoundCategory, SoundId};
+use valence_protocol::{BlockPos, ChunkPos, CompressionThreshold, Encode, Ident, Packet};
+use valence_registry::biome::{BiomeId, BiomeRegistry};
+use valence_registry::DimensionTypeRegistry;
+use valence_server_core::Server;
+
+use super::bvh::GetChunkPos;
+use super::message::Messages;
+use super::{Layer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
/// A [`Component`] containing the [chunks](LoadedChunk) and [dimension
-/// information](valence_dimension::DimensionTypeId) of a Minecraft world.
+/// information](valence_registry::dimension_type::DimensionTypeId) of a
+/// Minecraft world.
#[derive(Component, Debug)]
pub struct ChunkLayer {
messages: ChunkLayerMessages,
@@ -42,14 +39,13 @@ pub struct ChunkLayer {
info: ChunkLayerInfo,
}
-/// Chunk layer information. Not public API.
-#[doc(hidden)]
-pub struct ChunkLayerInfo {
+/// Chunk layer information.
+pub(crate) struct ChunkLayerInfo {
dimension_type_name: Ident,
height: u32,
min_y: i32,
biome_registry_len: usize,
- compression_threshold: Option,
+ threshold: CompressionThreshold,
}
impl fmt::Debug for ChunkLayerInfo {
@@ -59,7 +55,7 @@ impl fmt::Debug for ChunkLayerInfo {
.field("height", &self.height)
.field("min_y", &self.min_y)
.field("biome_registry_len", &self.biome_registry_len)
- .field("compression_threshold", &self.compression_threshold)
+ .field("threshold", &self.threshold)
// Ignore sky light mask and array.
.finish()
}
@@ -67,9 +63,8 @@ impl fmt::Debug for ChunkLayerInfo {
type ChunkLayerMessages = Messages;
-#[doc(hidden)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
-pub enum GlobalMsg {
+pub(crate) enum GlobalMsg {
/// Send packet data to all clients viewing the layer.
Packet,
/// Send packet data to all clients viewing the layer, except the client
@@ -77,9 +72,8 @@ pub enum GlobalMsg {
PacketExcept { except: Entity },
}
-#[doc(hidden)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
-pub enum LocalMsg {
+pub(crate) enum LocalMsg {
/// Send packet data to all clients viewing the layer in view of `pos`.
PacketAt {
pos: ChunkPos,
@@ -126,12 +120,9 @@ impl GetChunkPos for LocalMsg {
}
impl ChunkLayer {
- #[doc(hidden)]
- pub const LOAD: u8 = 0;
- #[doc(hidden)]
- pub const UNLOAD: u8 = 1;
- #[doc(hidden)]
- pub const OVERWRITE: u8 = 2;
+ pub(crate) const LOAD: u8 = 0;
+ pub(crate) const UNLOAD: u8 = 1;
+ pub(crate) const OVERWRITE: u8 = 2;
/// Creates a new chunk layer.
#[track_caller]
@@ -159,7 +150,7 @@ impl ChunkLayer {
height: dim.height as u32,
min_y: dim.min_y,
biome_registry_len: biomes.iter().len(),
- compression_threshold: server.compression_threshold(),
+ threshold: server.compression_threshold(),
},
}
}
@@ -352,13 +343,11 @@ impl ChunkLayer {
Some((chunk, x, y, z))
}
- #[doc(hidden)]
- pub fn info(&self) -> &ChunkLayerInfo {
+ pub(crate) fn info(&self) -> &ChunkLayerInfo {
&self.info
}
- #[doc(hidden)]
- pub fn messages(&self) -> &ChunkLayerMessages {
+ pub(crate) fn messages(&self) -> &ChunkLayerMessages {
&self.messages
}
@@ -404,7 +393,10 @@ impl ChunkLayer {
self.view_writer(ChunkPos::from_pos(position))
.write_packet(&PlaySoundS2c {
- id: sound.to_id(),
+ id: SoundId::Direct {
+ id: sound.to_ident().into(),
+ range: None,
+ },
category,
position: (position * 8.0).as_ivec3(),
volume,
@@ -484,7 +476,7 @@ impl WritePacket for ChunkLayer {
P: Packet + Encode,
{
self.messages.send_global(GlobalMsg::Packet, |b| {
- PacketWriter::new(b, self.info.compression_threshold).write_packet_fallible(packet)
+ PacketWriter::new(b, self.info.threshold).write_packet_fallible(packet)
})
}
@@ -508,10 +500,7 @@ impl WritePacket for ExceptWriter<'_> {
GlobalMsg::PacketExcept {
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.info.compression_threshold)
- .write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.info.threshold).write_packet_fallible(packet),
)
}
@@ -538,8 +527,7 @@ impl WritePacket for ViewWriter<'_> {
self.layer
.messages
.send_local(LocalMsg::PacketAt { pos: self.pos }, |b| {
- PacketWriter::new(b, self.layer.info.compression_threshold)
- .write_packet_fallible(packet)
+ PacketWriter::new(b, self.layer.info.threshold).write_packet_fallible(packet)
})
}
@@ -568,10 +556,7 @@ impl WritePacket for ViewExceptWriter<'_> {
pos: self.pos,
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.info.compression_threshold)
- .write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.info.threshold).write_packet_fallible(packet),
)
}
@@ -602,10 +587,7 @@ impl WritePacket for RadiusWriter<'_> {
center: self.center,
radius_squared: self.radius,
},
- |b| {
- PacketWriter::new(b, self.layer.info.compression_threshold)
- .write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.info.threshold).write_packet_fallible(packet),
)
}
@@ -638,10 +620,7 @@ impl WritePacket for RadiusExceptWriter<'_> {
radius_squared: self.radius,
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.info.compression_threshold)
- .write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.info.threshold).write_packet_fallible(packet),
)
}
diff --git a/crates/valence_layer/src/chunk/chunk.rs b/crates/valence_server/src/layer/chunk/chunk.rs
similarity index 98%
rename from crates/valence_layer/src/chunk/chunk.rs
rename to crates/valence_server/src/layer/chunk/chunk.rs
index 3a7759f5d..e5b53eefc 100644
--- a/crates/valence_layer/src/chunk/chunk.rs
+++ b/crates/valence_server/src/layer/chunk/chunk.rs
@@ -1,6 +1,6 @@
-use valence_biome::BiomeId;
-use valence_block::BlockState;
use valence_nbt::Compound;
+use valence_protocol::BlockState;
+use valence_registry::biome::BiomeId;
use super::paletted_container::PalettedContainer;
@@ -316,8 +316,7 @@ pub(super) const fn bit_width(n: usize) -> usize {
#[cfg(test)]
mod tests {
use super::*;
- use crate::chunk::loaded::LoadedChunk;
- use crate::chunk::unloaded::UnloadedChunk;
+ use crate::layer::chunk::{LoadedChunk, UnloadedChunk};
#[test]
fn chunk_get_set() {
diff --git a/crates/valence_layer/src/chunk/loaded.rs b/crates/valence_server/src/layer/chunk/loaded.rs
similarity index 92%
rename from crates/valence_layer/src/chunk/loaded.rs
rename to crates/valence_server/src/layer/chunk/loaded.rs
index 68e0cad3f..da1969c8a 100644
--- a/crates/valence_layer/src/chunk/loaded.rs
+++ b/crates/valence_server/src/layer/chunk/loaded.rs
@@ -4,19 +4,14 @@ use std::mem;
use std::sync::atomic::{AtomicU32, Ordering};
use parking_lot::Mutex; // Using nonstandard mutex to avoid poisoning API.
-use valence_biome::BiomeId;
-use valence_block::BlockState;
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::ChunkPos;
-use valence_core::protocol::var_int::VarInt;
-use valence_core::protocol::var_long::VarLong;
-use valence_core::protocol::Encode;
use valence_nbt::{compound, Compound};
-use valence_packet::packets::play::chunk_data_s2c::ChunkDataBlockEntity;
-use valence_packet::packets::play::{
+use valence_protocol::encode::{PacketWriter, WritePacket};
+use valence_protocol::packets::play::chunk_data_s2c::ChunkDataBlockEntity;
+use valence_protocol::packets::play::{
BlockEntityUpdateS2c, BlockUpdateS2c, ChunkDataS2c, ChunkDeltaUpdateS2c,
};
-use valence_packet::protocol::encode::{PacketWriter, WritePacket};
+use valence_protocol::{BlockPos, BlockState, ChunkPos, Encode, VarInt, VarLong};
+use valence_registry::biome::BiomeId;
use valence_registry::RegistryIdx;
use super::chunk::{
@@ -170,16 +165,14 @@ impl LoadedChunk {
*self.viewer_count.get_mut()
}
- /// Increments the viewer count. For internal use only.
- #[doc(hidden)]
- pub fn inc_viewer_count(&self) {
+ /// Increments the viewer count.
+ pub(crate) fn inc_viewer_count(&self) {
self.viewer_count.fetch_add(1, Ordering::Relaxed);
}
- /// Decrements the viewer count. For internal use only.
- #[doc(hidden)]
+ /// Decrements the viewer count.
#[track_caller]
- pub fn dec_viewer_count(&self) {
+ pub(crate) fn dec_viewer_count(&self) {
let old = self.viewer_count.fetch_sub(1, Ordering::Relaxed);
debug_assert_ne!(old, 0, "viewer count underflow!");
}
@@ -217,7 +210,7 @@ impl LoadedChunk {
let global_z = pos.z * 16 + offset_z as i32;
messages.send_local_infallible(LocalMsg::PacketAt { pos }, |buf| {
- let mut writer = PacketWriter::new(buf, info.compression_threshold);
+ let mut writer = PacketWriter::new(buf, info.threshold);
writer.write_packet(&BlockUpdateS2c {
position: BlockPos::new(global_x, global_y, global_z),
@@ -231,7 +224,7 @@ impl LoadedChunk {
| (sect_y as i64 + info.min_y.div_euclid(16) as i64) & 0xfffff;
messages.send_local_infallible(LocalMsg::PacketAt { pos }, |buf| {
- let mut writer = PacketWriter::new(buf, info.compression_threshold);
+ let mut writer = PacketWriter::new(buf, info.threshold);
writer.write_packet(&ChunkDeltaUpdateS2c {
chunk_section_position,
@@ -267,7 +260,7 @@ impl LoadedChunk {
let global_z = pos.z * 16 + z as i32;
messages.send_local_infallible(LocalMsg::PacketAt { pos }, |buf| {
- let mut writer = PacketWriter::new(buf, info.compression_threshold);
+ let mut writer = PacketWriter::new(buf, info.threshold);
writer.write_packet(&BlockEntityUpdateS2c {
position: BlockPos::new(global_x, global_y, global_z),
@@ -303,8 +296,7 @@ impl LoadedChunk {
}
/// Writes the packet data needed to initialize this chunk.
- #[doc(hidden)]
- pub fn write_init_packets(
+ pub(crate) fn write_init_packets(
&self,
mut writer: impl WritePacket,
pos: ChunkPos,
@@ -367,20 +359,18 @@ impl LoadedChunk {
})
.collect();
- PacketWriter::new(&mut init_packets, info.compression_threshold).write_packet(
- &ChunkDataS2c {
- pos,
- heightmaps: Cow::Owned(heightmaps),
- blocks_and_biomes: &blocks_and_biomes,
- block_entities: Cow::Owned(block_entities),
- sky_light_mask: Cow::Borrowed(&[]),
- block_light_mask: Cow::Borrowed(&[]),
- empty_sky_light_mask: Cow::Borrowed(&[]),
- empty_block_light_mask: Cow::Borrowed(&[]),
- sky_light_arrays: Cow::Borrowed(&[]),
- block_light_arrays: Cow::Borrowed(&[]),
- },
- )
+ PacketWriter::new(&mut init_packets, info.threshold).write_packet(&ChunkDataS2c {
+ pos,
+ heightmaps: Cow::Owned(heightmaps),
+ blocks_and_biomes: &blocks_and_biomes,
+ block_entities: Cow::Owned(block_entities),
+ sky_light_mask: Cow::Borrowed(&[]),
+ block_light_mask: Cow::Borrowed(&[]),
+ empty_sky_light_mask: Cow::Borrowed(&[]),
+ empty_block_light_mask: Cow::Borrowed(&[]),
+ sky_light_arrays: Cow::Borrowed(&[]),
+ block_light_arrays: Cow::Borrowed(&[]),
+ })
}
writer.write_packet_bytes(&init_packets);
@@ -609,7 +599,7 @@ impl Chunk for LoadedChunk {
#[cfg(test)]
mod tests {
- use valence_core::ident;
+ use valence_protocol::ident;
use super::*;
@@ -639,7 +629,7 @@ mod tests {
height: 512,
min_y: -16,
biome_registry_len: 200,
- compression_threshold: None,
+ threshold: None,
};
let mut buf = vec![];
diff --git a/crates/valence_layer/src/chunk/paletted_container.rs b/crates/valence_server/src/layer/chunk/paletted_container.rs
similarity index 99%
rename from crates/valence_layer/src/chunk/paletted_container.rs
rename to crates/valence_server/src/layer/chunk/paletted_container.rs
index ced9967c9..302151d83 100644
--- a/crates/valence_layer/src/chunk/paletted_container.rs
+++ b/crates/valence_server/src/layer/chunk/paletted_container.rs
@@ -3,8 +3,7 @@ use std::io::Write;
use arrayvec::ArrayVec;
use num_integer::div_ceil;
-use valence_core::protocol::var_int::VarInt;
-use valence_core::protocol::Encode;
+use valence_protocol::{Encode, VarInt};
use super::chunk::bit_width;
diff --git a/crates/valence_layer/src/chunk/unloaded.rs b/crates/valence_server/src/layer/chunk/unloaded.rs
similarity index 98%
rename from crates/valence_layer/src/chunk/unloaded.rs
rename to crates/valence_server/src/layer/chunk/unloaded.rs
index 9bc2ab4bc..cd19114e1 100644
--- a/crates/valence_layer/src/chunk/unloaded.rs
+++ b/crates/valence_server/src/layer/chunk/unloaded.rs
@@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::collections::BTreeMap;
-use valence_biome::BiomeId;
-use valence_block::BlockState;
use valence_nbt::Compound;
+use valence_protocol::BlockState;
+use valence_registry::biome::BiomeId;
use super::chunk::{
check_biome_oob, check_block_oob, check_section_oob, BiomeContainer, BlockStateContainer,
diff --git a/crates/valence_layer/src/entity.rs b/crates/valence_server/src/layer/entity.rs
similarity index 90%
rename from crates/valence_layer/src/entity.rs
rename to crates/valence_server/src/layer/entity.rs
index 35b18f0be..142eb296f 100644
--- a/crates/valence_layer/src/entity.rs
+++ b/crates/valence_server/src/layer/entity.rs
@@ -5,33 +5,29 @@ use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_ecs::query::Has;
use rustc_hash::FxHashMap;
-use valence_core::block_pos::BlockPos;
-use valence_core::chunk_pos::ChunkPos;
-use valence_core::despawn::Despawned;
-use valence_core::protocol::Encode;
-use valence_core::Server;
use valence_entity::query::UpdateEntityQuery;
use valence_entity::{EntityId, EntityLayerId, OldEntityLayerId, OldPosition, Position};
-use valence_packet::protocol::encode::{PacketWriter, WritePacket};
-use valence_packet::protocol::Packet;
+use valence_protocol::encode::{PacketWriter, WritePacket};
+use valence_protocol::{BlockPos, ChunkPos, CompressionThreshold, Encode, Packet};
+use valence_server_core::{Despawned, Server};
-use crate::bvh::GetChunkPos;
-use crate::message::Messages;
-use crate::{Layer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
+use super::bvh::GetChunkPos;
+use super::message::Messages;
+use super::{Layer, UpdateLayersPostClientSet, UpdateLayersPreClientSet};
+use crate::client::Client;
/// A [`Component`] containing Minecraft entities.
#[derive(Component, Debug)]
pub struct EntityLayer {
messages: EntityLayerMessages,
entities: FxHashMap>,
- compression_threshold: Option,
+ threshold: CompressionThreshold,
}
type EntityLayerMessages = Messages;
-#[doc(hidden)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
-pub enum GlobalMsg {
+pub(crate) enum GlobalMsg {
/// Send packet data to all clients viewing the layer. Message data is
/// serialized packet data.
Packet,
@@ -43,10 +39,9 @@ pub enum GlobalMsg {
DespawnLayer,
}
-#[doc(hidden)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
// NOTE: Variant order is significant. Despawns should be ordered before spawns.
-pub enum LocalMsg {
+pub(crate) enum LocalMsg {
/// Despawn entities if the client is not already viewing `dest_layer`.
/// Message data is the serialized form of `EntityId`.
DespawnEntity { pos: ChunkPos, dest_layer: Entity },
@@ -100,7 +95,7 @@ impl EntityLayer {
Self {
messages: Messages::new(),
entities: Default::default(),
- compression_threshold: server.compression_threshold(),
+ threshold: server.compression_threshold(),
}
}
@@ -116,8 +111,7 @@ impl EntityLayer {
.flat_map(|entities| entities.iter().copied())
}
- #[doc(hidden)]
- pub fn messages(&self) -> &EntityLayerMessages {
+ pub(crate) fn messages(&self) -> &EntityLayerMessages {
&self.messages
}
}
@@ -192,7 +186,7 @@ impl WritePacket for EntityLayer {
P: Packet + Encode,
{
self.messages.send_global(GlobalMsg::Packet, |b| {
- PacketWriter::new(b, self.compression_threshold).write_packet_fallible(packet)
+ PacketWriter::new(b, self.threshold).write_packet_fallible(packet)
})
}
@@ -216,9 +210,7 @@ impl WritePacket for ExceptWriter<'_> {
GlobalMsg::PacketExcept {
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.compression_threshold).write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.threshold).write_packet_fallible(packet),
)
}
@@ -245,7 +237,7 @@ impl<'a> WritePacket for ViewWriter<'a> {
self.layer
.messages
.send_local(LocalMsg::PacketAt { pos: self.pos }, |b| {
- PacketWriter::new(b, self.layer.compression_threshold).write_packet_fallible(packet)
+ PacketWriter::new(b, self.layer.threshold).write_packet_fallible(packet)
})
}
@@ -274,9 +266,7 @@ impl WritePacket for ViewExceptWriter<'_> {
pos: self.pos,
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.compression_threshold).write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.threshold).write_packet_fallible(packet),
)
}
@@ -307,9 +297,7 @@ impl WritePacket for RadiusWriter<'_> {
center: self.center,
radius_squared: self.radius_squared,
},
- |b| {
- PacketWriter::new(b, self.layer.compression_threshold).write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.threshold).write_packet_fallible(packet),
)
}
@@ -342,9 +330,7 @@ impl WritePacket for RadiusExceptWriter<'_> {
radius_squared: self.radius_squared,
except: self.except,
},
- |b| {
- PacketWriter::new(b, self.layer.compression_threshold).write_packet_fallible(packet)
- },
+ |b| PacketWriter::new(b, self.layer.threshold).write_packet_fallible(packet),
)
}
@@ -360,13 +346,13 @@ impl WritePacket for RadiusExceptWriter<'_> {
}
}
-pub(super) fn build(app: &mut App) {
+pub(super) fn build(app: &mut App) {
app.add_systems(
PostUpdate,
(
(
change_entity_positions,
- send_entity_update_messages::,
+ send_entity_update_messages,
send_layer_despawn_messages,
ready_entity_layers,
)
@@ -484,7 +470,7 @@ fn change_entity_positions(
}
}
-fn send_entity_update_messages(
+fn send_entity_update_messages(
entities: Query<(Entity, UpdateEntityQuery, Has), Without>,
mut layers: Query<&mut EntityLayer>,
) {
@@ -509,8 +495,7 @@ fn send_entity_update_messages(
};
layer.messages.send_local_infallible(msg, |b| {
- update
- .write_update_packets(PacketWriter::new(b, layer.compression_threshold))
+ update.write_update_packets(PacketWriter::new(b, layer.threshold))
});
} else {
panic!(
diff --git a/crates/valence_layer/src/message.rs b/crates/valence_server/src/layer/message.rs
similarity index 98%
rename from crates/valence_layer/src/message.rs
rename to crates/valence_server/src/layer/message.rs
index a2e3ca18a..c52269d1d 100644
--- a/crates/valence_layer/src/message.rs
+++ b/crates/valence_server/src/layer/message.rs
@@ -2,9 +2,10 @@ use core::fmt;
use std::convert::Infallible;
use std::ops::Range;
-use valence_core::chunk_pos::{ChunkPos, ChunkView};
+use valence_protocol::ChunkPos;
-use crate::bvh::{ChunkBvh, GetChunkPos};
+use crate::layer::bvh::{ChunkBvh, GetChunkPos};
+use crate::ChunkView;
/// A message buffer of global messages (`G`) and local messages (`L`) meant for
/// consumption by clients. Local messages are those that have some spatial
diff --git a/crates/valence_server/src/lib.rs b/crates/valence_server/src/lib.rs
new file mode 100644
index 000000000..4b29dd3ac
--- /dev/null
+++ b/crates/valence_server/src/lib.rs
@@ -0,0 +1,56 @@
+#![doc = include_str!("../README.md")]
+#![deny(
+ rustdoc::broken_intra_doc_links,
+ rustdoc::private_intra_doc_links,
+ rustdoc::missing_crate_level_docs,
+ rustdoc::invalid_codeblock_attributes,
+ rustdoc::invalid_rust_codeblocks,
+ rustdoc::bare_urls,
+ rustdoc::invalid_html_tags
+)]
+#![warn(
+ trivial_casts,
+ trivial_numeric_casts,
+ unused_lifetimes,
+ unused_import_braces,
+ unreachable_pub,
+ clippy::dbg_macro
+)]
+#![allow(clippy::type_complexity)]
+
+pub mod abilities;
+pub mod action;
+mod chunk_view;
+pub mod client;
+pub mod client_command;
+pub mod client_settings;
+pub mod custom_payload;
+pub mod event_loop;
+pub mod hand_swing;
+pub mod interact_block;
+pub mod interact_entity;
+pub mod interact_item;
+pub mod keepalive;
+pub mod layer;
+pub mod message;
+pub mod movement;
+pub mod op_level;
+pub mod resource_pack;
+pub mod spawn;
+pub mod status;
+pub mod teleport;
+pub mod title;
+
+pub use chunk_view::ChunkView;
+pub use event_loop::{EventLoopPostUpdate, EventLoopPreUpdate, EventLoopUpdate};
+pub use layer::{ChunkLayer, EntityLayer, Layer, LayerBundle};
+pub use valence_protocol::{
+ block, ident, item, math, text, uuid, BlockPos, BlockState, ChunkPos, CompressionThreshold,
+ Difficulty, Direction, GameMode, Hand, Ident, ItemKind, ItemStack, PlayerTextures, Text,
+ MINECRAFT_VERSION, PROTOCOL_VERSION,
+};
+pub use valence_server_core::*;
+pub use {
+ bevy_app as app, bevy_ecs as ecs, rand, valence_entity as entity, valence_nbt as nbt,
+ valence_protocol as protocol, valence_registry as registry,
+};
diff --git a/crates/valence_client/src/message.rs b/crates/valence_server/src/message.rs
similarity index 80%
rename from crates/valence_client/src/message.rs
rename to crates/valence_server/src/message.rs
index c0f6941ad..0a6b00791 100644
--- a/crates/valence_client/src/message.rs
+++ b/crates/valence_server/src/message.rs
@@ -2,15 +2,19 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_core::text::IntoText;
-use valence_packet::packets::play::{ChatMessageC2s, GameMessageS2c};
-use valence_packet::protocol::encode::WritePacket;
+use valence_protocol::encode::WritePacket;
+use valence_protocol::packets::play::{ChatMessageC2s, GameMessageS2c};
+use valence_protocol::text::IntoText;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_chat_message);
+pub struct MessagePlugin;
+
+impl Plugin for MessagePlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_chat_message);
+ }
}
pub trait SendMessage {
diff --git a/crates/valence_client/src/movement.rs b/crates/valence_server/src/movement.rs
similarity index 94%
rename from crates/valence_client/src/movement.rs
rename to crates/valence_server/src/movement.rs
index 2cf34b73e..5b5835799 100644
--- a/crates/valence_client/src/movement.rs
+++ b/crates/valence_server/src/movement.rs
@@ -1,18 +1,22 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use glam::DVec3;
use valence_entity::{HeadYaw, Look, OnGround, Position};
-use valence_packet::packets::play::{
+use valence_math::DVec3;
+use valence_protocol::packets::play::{
FullC2s, LookAndOnGroundC2s, OnGroundOnlyC2s, PositionAndOnGroundC2s, VehicleMoveC2s,
};
-use super::teleport::TeleportState;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
+use crate::teleport::TeleportState;
-pub(super) fn build(app: &mut App) {
- app.init_resource::()
- .add_event::()
- .add_systems(EventLoopPreUpdate, handle_client_movement);
+pub struct MovementPlugin;
+
+impl Plugin for MovementPlugin {
+ fn build(&self, app: &mut App) {
+ app.init_resource::()
+ .add_event::()
+ .add_systems(EventLoopPreUpdate, handle_client_movement);
+ }
}
/// Configuration resource for client movement checks.
diff --git a/crates/valence_client/src/op_level.rs b/crates/valence_server/src/op_level.rs
similarity index 60%
rename from crates/valence_client/src/op_level.rs
rename to crates/valence_server/src/op_level.rs
index 5426961f1..55dd586f1 100644
--- a/crates/valence_client/src/op_level.rs
+++ b/crates/valence_server/src/op_level.rs
@@ -1,7 +1,16 @@
-use super::*;
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+use valence_protocol::packets::play::EntityStatusS2c;
+use valence_protocol::WritePacket;
-pub(super) fn build(app: &mut App) {
- app.add_systems(PostUpdate, update_op_level.in_set(UpdateClientsSet));
+use crate::client::{Client, UpdateClientsSet};
+
+pub struct OpLevelPlugin;
+
+impl Plugin for OpLevelPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_systems(PostUpdate, update_op_level.in_set(UpdateClientsSet));
+ }
}
#[derive(Component, Clone, PartialEq, Eq, Default, Debug)]
diff --git a/crates/valence_client/src/resource_pack.rs b/crates/valence_server/src/resource_pack.rs
similarity index 78%
rename from crates/valence_client/src/resource_pack.rs
rename to crates/valence_server/src/resource_pack.rs
index 9d3edec94..f0a9cc5a9 100644
--- a/crates/valence_client/src/resource_pack.rs
+++ b/crates/valence_server/src/resource_pack.rs
@@ -1,14 +1,19 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_core::text::Text;
-use valence_packet::packets::play::{ResourcePackSendS2c, ResourcePackStatusC2s};
+use valence_protocol::packets::play::{ResourcePackSendS2c, ResourcePackStatusC2s};
+use valence_protocol::text::Text;
+use valence_protocol::WritePacket;
-use super::*;
+use crate::client::Client;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_systems(EventLoopPreUpdate, handle_resource_pack_status);
+pub struct ResourcePackPlugin;
+
+impl Plugin for ResourcePackPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_systems(EventLoopPreUpdate, handle_resource_pack_status);
+ }
}
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
diff --git a/crates/valence_client/src/spawn.rs b/crates/valence_server/src/spawn.rs
similarity index 85%
rename from crates/valence_client/src/spawn.rs
rename to crates/valence_server/src/spawn.rs
index 97afcb2df..61c361a18 100644
--- a/crates/valence_client/src/spawn.rs
+++ b/crates/valence_server/src/spawn.rs
@@ -1,9 +1,17 @@
//! Handles spawning and respawning the client.
-use valence_registry::codec::RegistryCodec;
+use std::borrow::Cow;
+
+use bevy_ecs::prelude::*;
+use bevy_ecs::query::WorldQuery;
+use valence_entity::EntityLayerId;
+use valence_protocol::packets::play::{GameJoinS2c, PlayerRespawnS2c, PlayerSpawnPositionS2c};
+use valence_protocol::{BlockPos, GameMode, GlobalPos, Ident, VarInt, WritePacket};
use valence_registry::tags::TagsRegistry;
+use valence_registry::{BiomeRegistry, RegistryCodec};
-use super::*;
+use crate::client::{Client, ViewDistance, VisibleChunkLayer};
+use crate::layer::ChunkLayer;
// Components for the join game and respawn packet.
@@ -44,6 +52,17 @@ impl Default for HasRespawnScreen {
}
}
+/// The position and angle that clients will respawn with. Also
+/// controls the position that compasses point towards.
+#[derive(Component, Copy, Clone, PartialEq, Default, Debug)]
+pub struct RespawnPosition {
+ /// The position that clients will respawn at. This can be changed at any
+ /// time to set the position that compasses point towards.
+ pub pos: BlockPos,
+ /// The yaw angle that clients will respawn with (in degrees).
+ pub yaw: f32,
+}
+
/// A convenient [`WorldQuery`] for obtaining client spawn components. Also see
/// [`ClientSpawnQueryReadOnly`].
#[derive(WorldQuery)]
@@ -99,7 +118,7 @@ pub(super) fn initial_join(
dimension_name,
hashed_seed: spawn.hashed_seed.0 as i64,
max_players: VarInt(0), // Ignored by clients.
- view_distance: VarInt(spawn.view_distance.0 as i32),
+ view_distance: VarInt(spawn.view_distance.get() as i32),
simulation_distance: VarInt(16), // TODO.
reduced_debug_info: spawn.reduced_debug_info.0,
enable_respawn_screen: spawn.has_respawn_screen.0,
@@ -109,7 +128,7 @@ pub(super) fn initial_join(
portal_cooldown: VarInt(spawn.portal_cooldown.0),
});
- client.enc.append_bytes(tags.sync_tags_packet());
+ client.write_packet_bytes(tags.sync_tags_packet());
/*
// TODO: enable all the features?
diff --git a/crates/valence_client/src/status.rs b/crates/valence_server/src/status.rs
similarity index 76%
rename from crates/valence_client/src/status.rs
rename to crates/valence_server/src/status.rs
index 74bf9218f..5571188ae 100644
--- a/crates/valence_client/src/status.rs
+++ b/crates/valence_server/src/status.rs
@@ -1,13 +1,17 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_packet::packets::play::ClientStatusC2s;
+use valence_protocol::packets::play::ClientStatusC2s;
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
-pub(super) fn build(app: &mut App) {
- app.add_event::()
- .add_event::()
- .add_systems(EventLoopPreUpdate, handle_status);
+pub struct StatusPlugin;
+
+impl Plugin for StatusPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::()
+ .add_event::()
+ .add_systems(EventLoopPreUpdate, handle_status);
+ }
}
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
diff --git a/crates/valence_client/src/teleport.rs b/crates/valence_server/src/teleport.rs
similarity index 82%
rename from crates/valence_client/src/teleport.rs
rename to crates/valence_server/src/teleport.rs
index dd8b6ae49..28b5d837b 100644
--- a/crates/valence_client/src/teleport.rs
+++ b/crates/valence_server/src/teleport.rs
@@ -1,20 +1,29 @@
-use glam::DVec3;
-use valence_packet::packets::play::player_position_look_s2c::PlayerPositionLookFlags;
-use valence_packet::packets::play::{PlayerPositionLookS2c, TeleportConfirmC2s};
+use bevy_app::prelude::*;
+use bevy_ecs::prelude::*;
+use tracing::warn;
+use valence_entity::{Look, Position};
+use valence_math::DVec3;
+use valence_protocol::packets::play::player_position_look_s2c::PlayerPositionLookFlags;
+use valence_protocol::packets::play::{PlayerPositionLookS2c, TeleportConfirmC2s};
+use valence_protocol::WritePacket;
-use super::*;
+use crate::client::{update_view_and_layers, Client, UpdateClientsSet};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
use crate::spawn::update_respawn_position;
-pub(super) fn build(app: &mut App) {
- app.add_systems(
- PostUpdate,
- teleport
- .after(update_view_and_layers)
- .before(update_respawn_position)
- .in_set(UpdateClientsSet),
- )
- .add_systems(EventLoopPreUpdate, handle_teleport_confirmations);
+pub struct TeleportPlugin;
+
+impl Plugin for TeleportPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_systems(
+ PostUpdate,
+ teleport
+ .after(update_view_and_layers)
+ .before(update_respawn_position)
+ .in_set(UpdateClientsSet),
+ )
+ .add_systems(EventLoopPreUpdate, handle_teleport_confirmations);
+ }
}
#[derive(Component, Debug)]
diff --git a/crates/valence_client/src/title.rs b/crates/valence_server/src/title.rs
similarity index 93%
rename from crates/valence_client/src/title.rs
rename to crates/valence_server/src/title.rs
index f6b1fe2c8..6f0613f91 100644
--- a/crates/valence_client/src/title.rs
+++ b/crates/valence_server/src/title.rs
@@ -1,9 +1,8 @@
-use valence_core::text::IntoText;
-use valence_packet::packets::play::{
+use valence_protocol::encode::WritePacket;
+use valence_protocol::packets::play::{
ClearTitleS2c, OverlayMessageS2c, SubtitleS2c, TitleFadeS2c, TitleS2c,
};
-
-use super::*;
+use valence_protocol::text::IntoText;
pub trait SetTitle {
/// Displays a title to a client.
diff --git a/crates/valence_server_core/Cargo.toml b/crates/valence_server_core/Cargo.toml
new file mode 100644
index 000000000..2cfd1a838
--- /dev/null
+++ b/crates/valence_server_core/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "valence_server_core"
+version.workspace = true
+edition.workspace = true
+
+[dependencies]
+bevy_ecs.workspace = true
+bevy_app.workspace = true
+uuid.workspace = true
+rand.workspace = true
+valence_protocol.workspace = true
\ No newline at end of file
diff --git a/crates/valence_server_core/README.md b/crates/valence_server_core/README.md
new file mode 100644
index 000000000..f59b33aed
--- /dev/null
+++ b/crates/valence_server_core/README.md
@@ -0,0 +1,3 @@
+# valence_server_core
+
+Contains some miscellaneous types for the `valence_server` family of crates, like `valence_entity`. `valence_registry`, and `valence_server`.
diff --git a/crates/valence_core/src/despawn.rs b/crates/valence_server_core/src/despawn.rs
similarity index 100%
rename from crates/valence_core/src/despawn.rs
rename to crates/valence_server_core/src/despawn.rs
index a3bb97cfb..17a9c22b4 100644
--- a/crates/valence_core/src/despawn.rs
+++ b/crates/valence_server_core/src/despawn.rs
@@ -17,8 +17,8 @@ use bevy_ecs::prelude::*;
pub struct Despawned;
pub(super) fn despawn_marked_entities(
- mut commands: Commands,
entities: Query>,
+ mut commands: Commands,
) {
for entity in &entities {
commands.entity(entity).despawn();
diff --git a/crates/valence_core/src/lib.rs b/crates/valence_server_core/src/lib.rs
similarity index 65%
rename from crates/valence_core/src/lib.rs
rename to crates/valence_server_core/src/lib.rs
index aa1f59eea..fbec52fa6 100644
--- a/crates/valence_core/src/lib.rs
+++ b/crates/valence_server_core/src/lib.rs
@@ -18,24 +18,8 @@
)]
#![allow(clippy::unusual_byte_groupings)]
-pub mod aabb;
-pub mod block_pos;
-pub mod chunk_pos;
-pub mod despawn;
-pub mod difficulty;
-pub mod direction;
-pub mod game_mode;
-pub mod hand;
-pub mod ident;
-pub mod item;
-pub mod player_textures;
-pub mod property;
-pub mod protocol;
-pub mod scratch;
-pub mod sound;
-pub mod text;
-pub mod translation_key;
-pub mod uuid;
+mod despawn;
+mod uuid;
use std::num::NonZeroU32;
use std::time::Duration;
@@ -43,27 +27,11 @@ use std::time::Duration;
use bevy_app::prelude::*;
use bevy_app::ScheduleRunnerPlugin;
use bevy_ecs::prelude::*;
+pub use despawn::*;
+use valence_protocol::CompressionThreshold;
use crate::despawn::despawn_marked_entities;
-
-/// Used only by macros. Not public API.
-#[doc(hidden)]
-pub mod __private {
- pub use anyhow::{anyhow, bail, ensure, Context, Result};
-
- pub use crate::protocol::var_int::VarInt;
- pub use crate::protocol::{Decode, Encode};
-}
-
-// Needed to make proc macros work.
-extern crate self as valence_core;
-
-/// The Minecraft protocol version this library currently targets.
-pub const PROTOCOL_VERSION: i32 = 763;
-
-/// The stringified name of the Minecraft version this library currently
-/// targets.
-pub const MINECRAFT_VERSION: &str = "1.20.1";
+pub use crate::uuid::*;
/// Minecraft's standard ticks per second (TPS).
pub const DEFAULT_TPS: NonZeroU32 = match NonZeroU32::new(20) {
@@ -71,35 +39,8 @@ pub const DEFAULT_TPS: NonZeroU32 = match NonZeroU32::new(20) {
None => unreachable!(),
};
-pub struct CorePlugin;
-
-impl Plugin for CorePlugin {
- fn build(&self, app: &mut App) {
- let settings = app.world.get_resource_or_insert_with(CoreSettings::default);
-
- let compression_threshold = settings.compression_threshold;
- let tick_rate = settings.tick_rate;
-
- app.insert_resource(Server {
- current_tick: 0,
- compression_threshold,
- });
-
- let tick_period = Duration::from_secs_f64((tick_rate.get() as f64).recip());
-
- // Make the app loop forever at the configured TPS.
- app.add_plugins(ScheduleRunnerPlugin::run_loop(tick_period));
-
- fn increment_tick_counter(mut server: ResMut) {
- server.current_tick += 1;
- }
-
- app.add_systems(Last, (increment_tick_counter, despawn_marked_entities));
- }
-}
-
-#[derive(Resource, Debug)]
-pub struct CoreSettings {
+#[derive(Clone, Resource)]
+pub struct ServerSettings {
/// The target ticks per second (TPS) of the server. This is the number of
/// game updates that should occur in one second.
///
@@ -126,10 +67,10 @@ pub struct CoreSettings {
///
/// Compression is enabled with an unspecified value. This value may
/// change in future versions.
- pub compression_threshold: Option,
+ pub compression_threshold: CompressionThreshold,
}
-impl Default for CoreSettings {
+impl Default for ServerSettings {
fn default() -> Self {
Self {
tick_rate: DEFAULT_TPS,
@@ -138,12 +79,41 @@ impl Default for CoreSettings {
}
}
+pub struct ServerPlugin;
+
+impl Plugin for ServerPlugin {
+ fn build(&self, app: &mut App) {
+ let settings = app
+ .world
+ .get_resource_or_insert_with(ServerSettings::default)
+ .clone();
+
+ app.insert_resource(Server {
+ current_tick: 0,
+ threshold: settings.compression_threshold,
+ tick_rate: settings.tick_rate,
+ });
+
+ let tick_period = Duration::from_secs_f64((settings.tick_rate.get() as f64).recip());
+
+ // Make the app loop forever at the configured TPS.
+ app.add_plugins(ScheduleRunnerPlugin::run_loop(tick_period));
+
+ fn increment_tick_counter(mut server: ResMut) {
+ server.current_tick += 1;
+ }
+
+ app.add_systems(Last, (increment_tick_counter, despawn_marked_entities));
+ }
+}
+
/// Contains global server state accessible as a [`Resource`].
-#[derive(Resource, Default)]
+#[derive(Resource)]
pub struct Server {
/// Incremented on every tick.
current_tick: i64,
- compression_threshold: Option,
+ threshold: CompressionThreshold,
+ tick_rate: NonZeroU32,
}
impl Server {
@@ -152,8 +122,14 @@ impl Server {
self.current_tick
}
- /// Returns the server's compression threshold.
- pub fn compression_threshold(&self) -> Option {
- self.compression_threshold
+ /// Returns the server's [compression
+ /// threshold](ServerSettings::compression_threshold).
+ pub fn compression_threshold(&self) -> CompressionThreshold {
+ self.threshold
+ }
+
+ // Returns the server's [tick rate](ServerPlugin::tick_rate).
+ pub fn tick_rate(&self) -> NonZeroU32 {
+ self.tick_rate
}
}
diff --git a/crates/valence_core/src/uuid.rs b/crates/valence_server_core/src/uuid.rs
similarity index 100%
rename from crates/valence_core/src/uuid.rs
rename to crates/valence_server_core/src/uuid.rs
diff --git a/crates/valence_text/Cargo.toml b/crates/valence_text/Cargo.toml
new file mode 100644
index 000000000..25ab42f77
--- /dev/null
+++ b/crates/valence_text/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "valence_text"
+version.workspace = true
+edition.workspace = true
+repository.workspace = true
+documentation.workspace = true
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+serde = { workspace = true, features = ["derive"] }
+serde_json.workspace = true
+thiserror.workspace = true
+uuid = { workspace = true, features = ["serde"] }
+valence_ident.workspace = true
+valence_nbt.workspace = true
\ No newline at end of file
diff --git a/crates/valence_text/README.md b/crates/valence_text/README.md
new file mode 100644
index 000000000..ad3a1fa3f
--- /dev/null
+++ b/crates/valence_text/README.md
@@ -0,0 +1,3 @@
+# valence_text
+
+A library for parsing and writing Minecraft's [JSON text format](https://minecraft.fandom.com/wiki/Raw_JSON_text_format)
diff --git a/crates/valence_core/src/text/color.rs b/crates/valence_text/src/color.rs
similarity index 100%
rename from crates/valence_core/src/text/color.rs
rename to crates/valence_text/src/color.rs
diff --git a/crates/valence_core/src/text/into_text.rs b/crates/valence_text/src/into_text.rs
similarity index 99%
rename from crates/valence_core/src/text/into_text.rs
rename to crates/valence_text/src/into_text.rs
index c13b679a7..6efbf6359 100644
--- a/crates/valence_core/src/text/into_text.rs
+++ b/crates/valence_text/src/into_text.rs
@@ -12,7 +12,7 @@ use super::{ClickEvent, Color, Font, HoverEvent, Text};
/// # Usage
///
/// ```
-/// # use valence_core::text::{IntoText, color::NamedColor};
+/// # use valence_text::{IntoText, color::NamedColor};
/// let mut my_text = "".into_text();
/// my_text = my_text.color(NamedColor::Red).bold();
/// my_text = my_text.add_child("CRABBBBB".obfuscated());
diff --git a/crates/valence_core/src/text.rs b/crates/valence_text/src/lib.rs
similarity index 80%
rename from crates/valence_core/src/text.rs
rename to crates/valence_text/src/lib.rs
index 5bb024c2e..fde4cb1f9 100644
--- a/crates/valence_core/src/text.rs
+++ b/crates/valence_text/src/lib.rs
@@ -1,22 +1,20 @@
-//! Formatted text.
+#![doc = include_str!("../README.md")]
use std::borrow::Cow;
-use std::io::Write;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use std::{fmt, ops};
-use anyhow::Context;
use serde::de::Visitor;
use serde::{de, Deserialize, Deserializer, Serialize};
use uuid::Uuid;
+use valence_ident::Ident;
use valence_nbt::Value;
-use crate::ident::Ident;
-use crate::protocol::{Decode, Encode};
-
pub mod color;
mod into_text;
+#[cfg(test)]
+mod tests;
pub use color::Color;
pub use into_text::IntoText;
@@ -34,7 +32,7 @@ pub use into_text::IntoText;
///
/// With [`IntoText`] in scope, you can write the following:
/// ```
-/// use valence_core::text::{Color, IntoText, Text};
+/// use valence_text::{Color, IntoText, Text};
///
/// let txt = "The text is ".into_text()
/// + "Red".color(Color::RED)
@@ -218,7 +216,7 @@ pub enum HoverEvent {
/// Number of the items in the stack
count: Option,
/// NBT information about the item (sNBT format)
- tag: Cow<'static, str>, // TODO replace with newtype for sNBT?
+ tag: Cow<'static, str>,
},
/// Shows an entity.
ShowEntity {
@@ -591,20 +589,6 @@ impl Default for TextContent {
}
}
-impl Encode for Text {
- fn encode(&self, w: impl Write) -> anyhow::Result<()> {
- serde_json::to_string(self)?.encode(w)
- }
-}
-
-impl Decode<'_> for Text {
- fn decode(r: &mut &[u8]) -> anyhow::Result {
- let str = <&str>::decode(r)?;
-
- Self::from_str(str).context("decoding text JSON")
- }
-}
-
impl<'de> Deserialize<'de> for Text {
fn deserialize>(deserializer: D) -> Result {
struct TextVisitor;
@@ -664,142 +648,3 @@ impl<'de> Deserialize<'de> for Text {
deserializer.deserialize_any(TextVisitor)
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::{ident, translation_key};
-
- #[test]
- fn text_round_trip() {
- let before = "foo".color(Color::RED).bold()
- + ("bar".obfuscated().color(Color::YELLOW)
- + "baz".underlined().not_bold().italic().color(Color::BLACK));
-
- let json = format!("{before:#}");
-
- let after = Text::from_str(&json).unwrap();
-
- println!("==== Before ====\n");
- println!("{before:#?}");
- println!("==== After ====\n");
- println!("{after:#?}");
-
- assert_eq!(before, after);
- assert_eq!(before.to_string(), after.to_string());
- }
-
- #[test]
- fn non_object_data_types() {
- let input = r#"["foo", true, false, 1.9E10, 9999]"#;
- let txt: Text = serde_json::from_str(input).unwrap();
-
- assert_eq!(txt, "foo".into_text() + true + false + 1.9E10 + 9999);
- }
-
- #[test]
- fn translate() {
- let txt = Text::translate(
- translation_key::CHAT_TYPE_ADVANCEMENT_TASK,
- ["arg1".into_text(), "arg2".into_text()],
- );
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- assert_eq!(
- serialized,
- r#"{"translate":"chat.type.advancement.task","with":[{"text":"arg1"},{"text":"arg2"}]}"#
- );
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn score() {
- let txt = Text::score("foo", "bar", Some(Cow::from("baz")));
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- assert_eq!(
- serialized,
- r#"{"score":{"name":"foo","objective":"bar","value":"baz"}}"#
- );
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn selector() {
- let separator = Text::text("bar").color(Color::RED).bold();
- let txt = Text::selector("foo", Some(separator));
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- assert_eq!(
- serialized,
- r##"{"selector":"foo","separator":{"text":"bar","color":"red","bold":true}}"##
- );
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn keybind() {
- let txt = Text::keybind("foo");
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- assert_eq!(serialized, r#"{"keybind":"foo"}"#);
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn block_nbt() {
- let txt = Text::block_nbt("foo", "bar", Some(true), Some("baz".into_text()));
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- let expected = r#"{"block":"foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
- assert_eq!(serialized, expected);
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn entity_nbt() {
- let txt = Text::entity_nbt("foo", "bar", Some(true), Some("baz".into_text()));
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- let expected =
- r#"{"entity":"foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
- assert_eq!(serialized, expected);
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn storage_nbt() {
- let txt = Text::storage_nbt(ident!("foo"), "bar", Some(true), Some("baz".into_text()));
- let serialized = txt.to_string();
- let deserialized = Text::from_str(&serialized).unwrap();
- let expected = r#"{"storage":"minecraft:foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
- assert_eq!(serialized, expected);
- assert_eq!(txt, deserialized);
- }
-
- #[test]
- fn text_to_legacy_lossy() {
- let text = "Heavily formatted green text\n"
- .bold()
- .italic()
- .strikethrough()
- .underlined()
- .obfuscated()
- .color(Color::GREEN)
- + "Lightly formatted red text\n"
- .not_bold()
- .not_strikethrough()
- .not_obfuscated()
- .color(Color::RED)
- + "Not formatted blue text"
- .not_italic()
- .not_underlined()
- .color(Color::BLUE);
-
- assert_eq!(
- text.to_legacy_lossy(),
- "§a§k§l§m§n§oHeavily formatted green text\n§r§c§n§oLightly formatted red \
- text\n§r§9Not formatted blue text"
- );
- }
-}
diff --git a/crates/valence_text/src/tests.rs b/crates/valence_text/src/tests.rs
new file mode 100644
index 000000000..f910c5fb3
--- /dev/null
+++ b/crates/valence_text/src/tests.rs
@@ -0,0 +1,136 @@
+use valence_ident::ident;
+
+use super::*;
+
+#[test]
+fn text_round_trip() {
+ let before = "foo".color(Color::RED).bold()
+ + ("bar".obfuscated().color(Color::YELLOW)
+ + "baz".underlined().not_bold().italic().color(Color::BLACK));
+
+ let json = format!("{before:#}");
+
+ let after = Text::from_str(&json).unwrap();
+
+ println!("==== Before ====\n");
+ println!("{before:#?}");
+ println!("==== After ====\n");
+ println!("{after:#?}");
+
+ assert_eq!(before, after);
+ assert_eq!(before.to_string(), after.to_string());
+}
+
+#[test]
+fn non_object_data_types() {
+ let input = r#"["foo", true, false, 1.9E10, 9999]"#;
+ let txt: Text = serde_json::from_str(input).unwrap();
+
+ assert_eq!(txt, "foo".into_text() + true + false + 1.9E10 + 9999);
+}
+
+#[test]
+fn translate() {
+ let txt = Text::translate(
+ "chat.type.advancement.task",
+ ["arg1".into_text(), "arg2".into_text()],
+ );
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ assert_eq!(
+ serialized,
+ r#"{"translate":"chat.type.advancement.task","with":[{"text":"arg1"},{"text":"arg2"}]}"#
+ );
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn score() {
+ let txt = Text::score("foo", "bar", Some(Cow::from("baz")));
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ assert_eq!(
+ serialized,
+ r#"{"score":{"name":"foo","objective":"bar","value":"baz"}}"#
+ );
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn selector() {
+ let separator = Text::text("bar").color(Color::RED).bold();
+ let txt = Text::selector("foo", Some(separator));
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ assert_eq!(
+ serialized,
+ r##"{"selector":"foo","separator":{"text":"bar","color":"red","bold":true}}"##
+ );
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn keybind() {
+ let txt = Text::keybind("foo");
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ assert_eq!(serialized, r#"{"keybind":"foo"}"#);
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn block_nbt() {
+ let txt = Text::block_nbt("foo", "bar", Some(true), Some("baz".into_text()));
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ let expected = r#"{"block":"foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
+ assert_eq!(serialized, expected);
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn entity_nbt() {
+ let txt = Text::entity_nbt("foo", "bar", Some(true), Some("baz".into_text()));
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ let expected = r#"{"entity":"foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
+ assert_eq!(serialized, expected);
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn storage_nbt() {
+ let txt = Text::storage_nbt(ident!("foo"), "bar", Some(true), Some("baz".into_text()));
+ let serialized = txt.to_string();
+ let deserialized = Text::from_str(&serialized).unwrap();
+ let expected =
+ r#"{"storage":"minecraft:foo","nbt":"bar","interpret":true,"separator":{"text":"baz"}}"#;
+ assert_eq!(serialized, expected);
+ assert_eq!(txt, deserialized);
+}
+
+#[test]
+fn text_to_legacy_lossy() {
+ let text = "Heavily formatted green text\n"
+ .bold()
+ .italic()
+ .strikethrough()
+ .underlined()
+ .obfuscated()
+ .color(Color::GREEN)
+ + "Lightly formatted red text\n"
+ .not_bold()
+ .not_strikethrough()
+ .not_obfuscated()
+ .color(Color::RED)
+ + "Not formatted blue text"
+ .not_italic()
+ .not_underlined()
+ .color(Color::BLUE);
+
+ assert_eq!(
+ text.to_legacy_lossy(),
+ "§a§k§l§m§n§oHeavily formatted green text\n§r§c§n§oLightly formatted red text\n§r§9Not \
+ formatted blue text"
+ );
+}
diff --git a/crates/valence_weather/Cargo.toml b/crates/valence_weather/Cargo.toml
index 0022c6f42..63a67dff3 100644
--- a/crates/valence_weather/Cargo.toml
+++ b/crates/valence_weather/Cargo.toml
@@ -7,9 +7,6 @@ documentation.workspace = true
license.workspace = true
[dependencies]
-valence_client.workspace = true
-valence_layer.workspace = true
-valence_core.workspace = true
-valence_packet.workspace = true
+valence_server.workspace = true
bevy_ecs.workspace = true
bevy_app.workspace = true
\ No newline at end of file
diff --git a/crates/valence_weather/src/lib.rs b/crates/valence_weather/src/lib.rs
index 73e898fc4..881e927a4 100644
--- a/crates/valence_weather/src/lib.rs
+++ b/crates/valence_weather/src/lib.rs
@@ -20,11 +20,11 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
-use valence_client::{Client, FlushPacketsSet, UpdateClientsSet, VisibleChunkLayer};
-use valence_layer::ChunkLayer;
-use valence_packet::packets::play::game_state_change_s2c::GameEventKind;
-use valence_packet::packets::play::GameStateChangeS2c;
-use valence_packet::protocol::encode::WritePacket;
+use valence_server::client::{Client, FlushPacketsSet, UpdateClientsSet, VisibleChunkLayer};
+use valence_server::protocol::packets::play::game_state_change_s2c::GameEventKind;
+use valence_server::protocol::packets::play::GameStateChangeS2c;
+use valence_server::protocol::WritePacket;
+use valence_server::ChunkLayer;
pub struct WeatherPlugin;
diff --git a/crates/valence_world_border/Cargo.toml b/crates/valence_world_border/Cargo.toml
index 8a3ce4782..de46acd55 100644
--- a/crates/valence_world_border/Cargo.toml
+++ b/crates/valence_world_border/Cargo.toml
@@ -6,10 +6,4 @@ edition.workspace = true
[dependencies]
bevy_app.workspace = true
bevy_ecs.workspace = true
-glam.workspace = true
-valence_client.workspace = true
-valence_core.workspace = true
-valence_entity.workspace = true
-valence_layer.workspace = true
-valence_registry.workspace = true
-valence_packet.workspace = true
+valence_server.workspace = true
diff --git a/crates/valence_world_border/src/lib.rs b/crates/valence_world_border/src/lib.rs
index 37facf585..fb313baba 100644
--- a/crates/valence_world_border/src/lib.rs
+++ b/crates/valence_world_border/src/lib.rs
@@ -19,16 +19,15 @@
)]
use bevy_app::prelude::*;
-use valence_client::{Client, UpdateClientsSet, VisibleChunkLayer};
-use valence_core::CoreSettings;
-use valence_layer::ChunkLayer;
-use valence_packet::packets::play::{
+use bevy_ecs::prelude::*;
+use valence_server::client::{Client, UpdateClientsSet, VisibleChunkLayer};
+use valence_server::protocol::packets::play::{
WorldBorderCenterChangedS2c, WorldBorderInitializeS2c, WorldBorderInterpolateSizeS2c,
WorldBorderSizeChangedS2c, WorldBorderWarningBlocksChangedS2c,
WorldBorderWarningTimeChangedS2c,
};
-use valence_packet::protocol::encode::WritePacket;
-use valence_registry::*;
+use valence_server::protocol::WritePacket;
+use valence_server::{ChunkLayer, Server};
// https://minecraft.fandom.com/wiki/World_border
pub const DEFAULT_PORTAL_LIMIT: i32 = 29999984;
@@ -143,11 +142,11 @@ fn init_world_border_for_new_clients(
&WorldBorderWarnTime,
&WorldBorderWarnBlocks,
)>,
- settings: Res,
+ server: Res,
) {
for (mut client, layer) in &mut clients {
if let Ok((center, lerp, portal_tp_boundary, warn_time, warn_blocks)) = wbs.get(layer.0) {
- let millis = lerp.remaining_ticks as i64 * 1000 / settings.tick_rate.get() as i64;
+ let millis = lerp.remaining_ticks as i64 * 1000 / server.tick_rate().get() as i64;
client.write_packet(&WorldBorderInitializeS2c {
x: center.x,
@@ -165,7 +164,7 @@ fn init_world_border_for_new_clients(
fn tick_world_border_lerp(
mut wbs: Query<(&mut ChunkLayer, &mut WorldBorderLerp)>,
- settings: Res,
+ server: Res,
) {
for (mut layer, mut lerp) in &mut wbs {
if lerp.is_changed() {
@@ -176,7 +175,7 @@ fn tick_world_border_lerp(
lerp.current_diameter = lerp.target_diameter;
} else {
- let millis = lerp.remaining_ticks as i64 * 1000 / settings.tick_rate.get() as i64;
+ let millis = lerp.remaining_ticks as i64 * 1000 / server.tick_rate().get() as i64;
layer.write_packet(&WorldBorderInterpolateSizeS2c {
old_diameter: lerp.current_diameter,
@@ -238,10 +237,10 @@ fn change_world_border_portal_tp_boundary(
),
Changed,
>,
- settings: Res,
+ server: Res,
) {
for (mut layer, center, lerp, portal_tp_boundary, warn_time, warn_blocks) in &mut wbs {
- let millis = lerp.remaining_ticks as i64 * 1000 / settings.tick_rate.get() as i64;
+ let millis = lerp.remaining_ticks as i64 * 1000 / server.tick_rate().get() as i64;
layer.write_packet(&WorldBorderInitializeS2c {
x: center.x,
diff --git a/examples/anvil_loading.rs b/examples/anvil_loading.rs
index f5efc9555..664ba21dd 100644
--- a/examples/anvil_loading.rs
+++ b/examples/anvil_loading.rs
@@ -3,10 +3,10 @@
use std::path::PathBuf;
use clap::Parser;
+use valence::abilities::{FlyingSpeed, FovModifier, PlayerAbilitiesFlags};
+use valence::message::SendMessage;
use valence::prelude::*;
use valence_anvil::{AnvilLevel, ChunkLoadEvent, ChunkLoadStatus};
-use valence_client::abilities::{FlyingSpeed, FovModifier, PlayerAbilitiesFlags};
-use valence_client::message::SendMessage;
const SPAWN_POS: DVec3 = DVec3::new(0.0, 256.0, 0.0);
diff --git a/examples/bench_players.rs b/examples/bench_players.rs
index 4f147e702..670db45e0 100644
--- a/examples/bench_players.rs
+++ b/examples/bench_players.rs
@@ -2,8 +2,9 @@
use std::time::Instant;
+use valence::client::{VisibleChunkLayer, VisibleEntityLayers};
use valence::prelude::*;
-use valence_client::{VisibleChunkLayer, VisibleEntityLayers};
+use valence::ServerSettings;
const SPAWN_Y: i32 = 64;
@@ -12,7 +13,7 @@ struct TickStart(Instant);
fn main() {
App::new()
- .insert_resource(CoreSettings {
+ .insert_resource(ServerSettings {
compression_threshold: None,
..Default::default()
})
@@ -34,14 +35,9 @@ fn record_tick_start_time(mut commands: Commands) {
commands.insert_resource(TickStart(Instant::now()));
}
-fn print_tick_time(
- server: Res,
- settings: Res,
- time: Res,
- clients: Query<(), With>,
-) {
+fn print_tick_time(server: Res, time: Res