diff --git a/src/biome.rs b/src/biome.rs index 1f88a50..adaca42 100644 --- a/src/biome.rs +++ b/src/biome.rs @@ -2,7 +2,7 @@ use crate::ident; use crate::ident::Ident; -use crate::protocol_inner::packets::s2c::play::Biome as BiomeRegistryBiome; +use crate::protocol::packets::s2c::play::Biome as BiomeRegistryBiome; /// Identifies a particular [`Biome`] on the server. /// @@ -48,7 +48,7 @@ pub struct Biome { impl Biome { pub(crate) fn to_biome_registry_item(&self, id: i32) -> BiomeRegistryBiome { - use crate::protocol_inner::packets::s2c::play::{ + use crate::protocol::packets::s2c::play::{ BiomeAdditionsSound, BiomeEffects, BiomeMoodSound, BiomeMusic, BiomeParticle, BiomeParticleOptions, BiomeProperty, }; diff --git a/src/block.rs b/src/block.rs index 5da7371..fdd7942 100644 --- a/src/block.rs +++ b/src/block.rs @@ -9,7 +9,7 @@ use std::iter::FusedIterator; use anyhow::Context; pub use crate::block_pos::BlockPos; -use crate::protocol_inner::{Decode, Encode, VarInt}; +use crate::protocol::{Decode, Encode, VarInt}; include!(concat!(env!("OUT_DIR"), "/block.rs")); diff --git a/src/block_pos.rs b/src/block_pos.rs index f890262..c507d55 100644 --- a/src/block_pos.rs +++ b/src/block_pos.rs @@ -3,7 +3,7 @@ use std::io::{Read, Write}; use anyhow::bail; use vek::Vec3; -use crate::protocol_inner::{Decode, Encode}; +use crate::protocol::{Decode, Encode}; /// Represents an absolute block position in a world. #[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)] diff --git a/src/chunk.rs b/src/chunk.rs index 7ee75ef..17d2412 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -17,10 +17,10 @@ use crate::block_pos::BlockPos; pub use crate::chunk_pos::ChunkPos; use crate::config::Config; use crate::dimension::DimensionId; -use crate::protocol_inner::packets::s2c::play::{ +use crate::protocol::packets::s2c::play::{ BlockUpdate, ChunkData, ChunkDataHeightmaps, ChunkSectionUpdate, S2cPlayPacket, }; -use crate::protocol_inner::{Encode, NbtBridge, VarInt, VarLong}; +use crate::protocol::{Encode, NbtBridge, VarInt, VarLong}; use crate::server::SharedServer; /// A container for all [`Chunks`]s in a [`World`](crate::world::World). diff --git a/src/client.rs b/src/client.rs index 89a2eb4..6093995 100644 --- a/src/client.rs +++ b/src/client.rs @@ -23,11 +23,11 @@ use crate::entity::{ }; use crate::player_list::{PlayerListId, PlayerLists}; use crate::player_textures::SignedPlayerTextures; -use crate::protocol_inner::packets::c2s::play::{ +use crate::protocol::packets::c2s::play::{ C2sPlayPacket, DiggingStatus, InteractKind, PlayerCommandId, }; -pub use crate::protocol_inner::packets::s2c::play::TitleFade; -use crate::protocol_inner::packets::s2c::play::{ +pub use crate::protocol::packets::s2c::play::TitleFade; +use crate::protocol::packets::s2c::play::{ BiomeRegistry, ChatTypeRegistry, ChunkLoadDistance, ChunkRenderDistanceCenter, ClearTitles, DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy, EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw, @@ -36,7 +36,7 @@ use crate::protocol_inner::packets::s2c::play::{ PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn, PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative, S2cPlayPacket, UnloadChunk, UpdateSubtitle, UpdateTitle, }; -use crate::protocol_inner::{BoundedInt, ByteAngle, NbtBridge, RawBytes, VarInt}; +use crate::protocol::{BoundedInt, ByteAngle, NbtBridge, RawBytes, VarInt}; use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer}; use crate::slab_versioned::{Key, VersionedSlab}; use crate::text::Text; @@ -610,16 +610,10 @@ impl Client { /// Attempts to enqueue a play packet to be sent to this client. The client /// is disconnected if the clientbound packet buffer is full. - #[cfg(feature = "protocol")] pub fn send_packet(&mut self, packet: impl Into) { send_packet(&mut self.send, packet); } - #[cfg(not(feature = "protocol"))] - pub(crate) fn send_packet(&mut self, packet: impl Into) { - send_packet(&mut self.send, packet); - } - pub(crate) fn handle_serverbound_packets(&mut self, entities: &Entities) { self.events.clear(); for _ in 0..self.recv.len() { diff --git a/src/client/event.rs b/src/client/event.rs index 872675f..8cfa011 100644 --- a/src/client/event.rs +++ b/src/client/event.rs @@ -4,9 +4,9 @@ use vek::Vec3; use crate::block_pos::BlockPos; use crate::entity::EntityId; -use crate::protocol_inner::packets::c2s::play::BlockFace; -pub use crate::protocol_inner::packets::c2s::play::{ChatMode, DisplayedSkinParts, Hand, MainHand}; -pub use crate::protocol_inner::packets::s2c::play::GameMode; +use crate::protocol::packets::c2s::play::BlockFace; +pub use crate::protocol::packets::c2s::play::{ChatMode, DisplayedSkinParts, Hand, MainHand}; +pub use crate::protocol::packets::s2c::play::GameMode; /// Represents an action performed by a client. /// diff --git a/src/dimension.rs b/src/dimension.rs index 2664255..a382e45 100644 --- a/src/dimension.rs +++ b/src/dimension.rs @@ -1,7 +1,7 @@ //! Dimension configuration and identification. use crate::ident; -use crate::protocol_inner::packets::s2c::play::DimensionType; +use crate::protocol::packets::s2c::play::DimensionType; /// Identifies a particular [`Dimension`] on the server. /// diff --git a/src/entity.rs b/src/entity.rs index af1fa97..68c481b 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -12,10 +12,10 @@ use uuid::Uuid; use vek::{Aabb, Vec3}; use crate::config::Config; -use crate::protocol_inner::packets::s2c::play::{ +use crate::protocol::packets::s2c::play::{ EntitySpawn, EntityTrackerUpdate, ExperienceOrbSpawn, PlayerSpawn, S2cPlayPacket, }; -use crate::protocol_inner::{ByteAngle, RawBytes, VarInt}; +use crate::protocol::{ByteAngle, RawBytes, VarInt}; use crate::slab_versioned::{Key, VersionedSlab}; use crate::util::aabb_from_bottom_and_size; use crate::world::WorldId; diff --git a/src/entity/data.rs b/src/entity/data.rs index e80823c..54e9eaa 100644 --- a/src/entity/data.rs +++ b/src/entity/data.rs @@ -4,7 +4,7 @@ use crate::block::{BlockPos, BlockState}; use crate::entity::types::*; -use crate::protocol_inner::{Encode, VarInt}; +use crate::protocol::{Encode, VarInt}; use crate::text::Text; use crate::uuid::Uuid; diff --git a/src/entity/types.rs b/src/entity/types.rs index f9ee3f1..f4593a4 100644 --- a/src/entity/types.rs +++ b/src/entity/types.rs @@ -2,7 +2,7 @@ use std::io::{Read, Write}; -use crate::protocol_inner::{Decode, Encode, VarInt}; +use crate::protocol::{Decode, Encode, VarInt}; /// Represents an optional `u32` value excluding [`u32::MAX`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] diff --git a/src/ident.rs b/src/ident.rs index 477388f..5b4ec11 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -9,7 +9,7 @@ use serde::de::Visitor; use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::protocol_inner::{encode_string_bounded, BoundedString, Decode, Encode}; +use crate::protocol::{encode_string_bounded, BoundedString, Decode, Encode}; /// An identifier is a string split into a "namespace" part and a "name" part. /// For instance `minecraft:apple` and `apple` are both valid identifiers. diff --git a/src/lib.rs b/src/lib.rs index 1fdceb5..dbe74eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,12 +90,6 @@ //! //! [examples]: https://github.com/rj00a/valence/tree/main/examples //! -//! # Feature Flags -//! -//! * `protocol`: Enables low-level access to the [`protocol`] module, which -//! could be used to build your own proxy or client. This feature is -//! considered experimental and is subject to change. -//! //! [`Server`]: crate::server::Server //! [`Clients`]: crate::client::Clients //! [`Entities`]: crate::entity::Entities @@ -144,7 +138,7 @@ pub mod ident; pub mod player_list; pub mod player_textures; #[allow(dead_code)] -mod protocol_inner; +mod protocol; pub mod server; mod slab; mod slab_rc; @@ -154,12 +148,6 @@ pub mod text; pub mod util; pub mod world; -/// Provides low-level access to the Minecraft protocol. -#[cfg(feature = "protocol")] -pub mod protocol { - pub use crate::protocol_inner::*; -} - /// The Minecraft protocol version this library currently targets. pub const PROTOCOL_VERSION: i32 = 760; /// The name of the Minecraft version this library currently targets, e.g. diff --git a/src/player_list.rs b/src/player_list.rs index 1caf66a..ba9f00a 100644 --- a/src/player_list.rs +++ b/src/player_list.rs @@ -9,11 +9,11 @@ use uuid::Uuid; use crate::client::GameMode; use crate::config::Config; use crate::player_textures::SignedPlayerTextures; -use crate::protocol_inner::packets::s2c::play::{ +use crate::protocol::packets::s2c::play::{ PlayerListAddPlayer, PlayerListHeaderFooter, S2cPlayPacket, UpdatePlayerList, }; -use crate::protocol_inner::packets::Property; -use crate::protocol_inner::VarInt; +use crate::protocol::packets::Property; +use crate::protocol::VarInt; use crate::slab_rc::{Key, SlabRc}; use crate::text::Text; diff --git a/src/protocol_inner.rs b/src/protocol.rs similarity index 99% rename from src/protocol_inner.rs rename to src/protocol.rs index d5af64b..d0c26ac 100644 --- a/src/protocol_inner.rs +++ b/src/protocol.rs @@ -1,3 +1,7 @@ +//! Provides low-level access to the Minecraft protocol. +//! +//! Hopefully you will not need to use this module. + use std::io::{Read, Write}; use std::mem; diff --git a/src/protocol_inner/byte_angle.rs b/src/protocol/byte_angle.rs similarity index 93% rename from src/protocol_inner/byte_angle.rs rename to src/protocol/byte_angle.rs index d303138..8fd1307 100644 --- a/src/protocol_inner/byte_angle.rs +++ b/src/protocol/byte_angle.rs @@ -1,6 +1,6 @@ use std::io::{Read, Write}; -use crate::protocol_inner::{Decode, Encode}; +use crate::protocol::{Decode, Encode}; /// Represents an angle in steps of 1/256 of a full turn. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/src/protocol_inner/codec.rs b/src/protocol/codec.rs similarity index 98% rename from src/protocol_inner/codec.rs rename to src/protocol/codec.rs index 2fb4d72..0054372 100644 --- a/src/protocol_inner/codec.rs +++ b/src/protocol/codec.rs @@ -14,7 +14,7 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader}; use tokio::time::timeout; use super::packets::{DecodePacket, EncodePacket}; -use crate::protocol_inner::{Decode, Encode, VarInt, MAX_PACKET_SIZE}; +use crate::protocol::{Decode, Encode, VarInt, MAX_PACKET_SIZE}; pub struct Encoder { write: W, @@ -271,7 +271,7 @@ mod tests { use tokio::sync::oneshot; use super::*; - use crate::protocol_inner::packets::test::TestPacket; + use crate::protocol::packets::test::TestPacket; #[tokio::test] async fn encode_decode() { diff --git a/src/protocol_inner/packets.rs b/src/protocol/packets.rs similarity index 99% rename from src/protocol_inner/packets.rs rename to src/protocol/packets.rs index c2d07d8..628c6df 100644 --- a/src/protocol_inner/packets.rs +++ b/src/protocol/packets.rs @@ -19,7 +19,7 @@ use vek::Vec3; use crate::block_pos::BlockPos; use crate::ident::Ident; use crate::nbt::Compound; -use crate::protocol_inner::{ +use crate::protocol::{ BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, NbtBridge, RawBytes, VarInt, VarLong, }; diff --git a/src/protocol_inner/packets/c2s.rs b/src/protocol/packets/c2s.rs similarity index 100% rename from src/protocol_inner/packets/c2s.rs rename to src/protocol/packets/c2s.rs diff --git a/src/protocol_inner/packets/s2c.rs b/src/protocol/packets/s2c.rs similarity index 100% rename from src/protocol_inner/packets/s2c.rs rename to src/protocol/packets/s2c.rs diff --git a/src/protocol_inner/var_int.rs b/src/protocol/var_int.rs similarity index 98% rename from src/protocol_inner/var_int.rs rename to src/protocol/var_int.rs index 5c2aaa4..f5588d5 100644 --- a/src/protocol_inner/var_int.rs +++ b/src/protocol/var_int.rs @@ -3,7 +3,7 @@ use std::io::{Read, Write}; use anyhow::bail; use byteorder::{ReadBytesExt, WriteBytesExt}; -use crate::protocol_inner::{Decode, Encode}; +use crate::protocol::{Decode, Encode}; /// An `i32` encoded with variable length. #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/src/protocol_inner/var_long.rs b/src/protocol/var_long.rs similarity index 97% rename from src/protocol_inner/var_long.rs rename to src/protocol/var_long.rs index add19b9..85ad906 100644 --- a/src/protocol_inner/var_long.rs +++ b/src/protocol/var_long.rs @@ -3,7 +3,7 @@ use std::io::{Read, Write}; use anyhow::bail; use byteorder::{ReadBytesExt, WriteBytesExt}; -use crate::protocol_inner::{Decode, Encode}; +use crate::protocol::{Decode, Encode}; /// An `i64` encoded with variable length. #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/src/server.rs b/src/server.rs index c7c560a..9c301e6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -34,20 +34,20 @@ use crate::dimension::{Dimension, DimensionId}; use crate::entity::Entities; use crate::player_list::PlayerLists; use crate::player_textures::SignedPlayerTextures; -use crate::protocol_inner::codec::{Decoder, Encoder}; -use crate::protocol_inner::packets::c2s::handshake::{Handshake, HandshakeNextState}; -use crate::protocol_inner::packets::c2s::login::{ +use crate::protocol::codec::{Decoder, Encoder}; +use crate::protocol::packets::c2s::handshake::{Handshake, HandshakeNextState}; +use crate::protocol::packets::c2s::login::{ EncryptionResponse, LoginStart, VerifyTokenOrMsgSig, }; -use crate::protocol_inner::packets::c2s::play::C2sPlayPacket; -use crate::protocol_inner::packets::c2s::status::{QueryPing, QueryRequest}; -use crate::protocol_inner::packets::s2c::login::{ +use crate::protocol::packets::c2s::play::C2sPlayPacket; +use crate::protocol::packets::c2s::status::{QueryPing, QueryRequest}; +use crate::protocol::packets::s2c::login::{ EncryptionRequest, LoginCompression, LoginDisconnect, LoginSuccess, }; -use crate::protocol_inner::packets::s2c::play::S2cPlayPacket; -use crate::protocol_inner::packets::s2c::status::{QueryPong, QueryResponse}; -use crate::protocol_inner::packets::Property; -use crate::protocol_inner::{BoundedArray, BoundedString, VarInt}; +use crate::protocol::packets::s2c::play::S2cPlayPacket; +use crate::protocol::packets::s2c::status::{QueryPong, QueryResponse}; +use crate::protocol::packets::Property; +use crate::protocol::{BoundedArray, BoundedString, VarInt}; use crate::util::valid_username; use crate::world::Worlds; use crate::{Ticks, PROTOCOL_VERSION, VERSION_NAME}; diff --git a/src/text.rs b/src/text.rs index 5db2a28..80b4ef8 100644 --- a/src/text.rs +++ b/src/text.rs @@ -8,7 +8,7 @@ use serde::de::Visitor; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::ident::Ident; -use crate::protocol_inner::{BoundedString, Decode, Encode}; +use crate::protocol::{BoundedString, Decode, Encode}; /// Represents formatted text in Minecraft's JSON text format. ///