Don't hide the protocol module behind a feature

This commit is contained in:
Ryan 2022-08-31 19:20:49 -07:00
parent 6e0a7e0a88
commit 5fb46178dd
23 changed files with 44 additions and 58 deletions

View file

@ -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,
};

View file

@ -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"));

View file

@ -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)]

View file

@ -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).

View file

@ -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<C: Config> Client<C> {
/// 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<S2cPlayPacket>) {
send_packet(&mut self.send, packet);
}
#[cfg(not(feature = "protocol"))]
pub(crate) fn send_packet(&mut self, packet: impl Into<S2cPlayPacket>) {
send_packet(&mut self.send, packet);
}
pub(crate) fn handle_serverbound_packets(&mut self, entities: &Entities<C>) {
self.events.clear();
for _ in 0..self.recv.len() {

View file

@ -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.
///

View file

@ -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.
///

View file

@ -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;

View file

@ -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;

View file

@ -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)]

View file

@ -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.

View file

@ -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.

View file

@ -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;

View file

@ -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;

View file

@ -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)]

View file

@ -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<W> {
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() {

View file

@ -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,
};

View file

@ -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)]

View file

@ -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)]

View file

@ -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};

View file

@ -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.
///