From ab2e1081ed30ebe978d49145abe97e2803d04d7f Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 14 Nov 2022 22:30:20 -0800 Subject: [PATCH] Re-export common items at the root of valence_protocol (#156) --- packet_inspector/src/main.rs | 3 +-- src/chunk.rs | 6 +---- src/chunk_pos.rs | 2 +- src/client.rs | 13 +++------- src/client/event.rs | 6 +---- src/entity.rs | 4 +-- src/entity/data.rs | 6 +---- src/inventory.rs | 5 ++-- src/lib.rs | 14 +++++------ src/server.rs | 7 +++--- src/server/login.rs | 7 +----- src/server/packet_controller.rs | 3 +-- valence_protocol/src/block.rs | 4 +-- valence_protocol/src/block_pos.rs | 6 ++--- valence_protocol/src/cache.rs | 5 ++-- valence_protocol/src/impls.rs | 3 +-- valence_protocol/src/item.rs | 4 +-- valence_protocol/src/lib.rs | 41 ++++++++++++++++++------------- valence_protocol/src/text.rs | 4 +-- valence_protocol/src/types.rs | 6 +---- 20 files changed, 58 insertions(+), 91 deletions(-) diff --git a/packet_inspector/src/main.rs b/packet_inspector/src/main.rs index cff0266..0493fff 100644 --- a/packet_inspector/src/main.rs +++ b/packet_inspector/src/main.rs @@ -15,7 +15,6 @@ use tokio::net::{TcpListener, TcpStream}; use tokio::sync::Semaphore; use tokio::task::JoinHandle; use tokio::time::timeout; -use valence_protocol::codec::{PacketDecoder, PacketEncoder}; use valence_protocol::packets::c2s::handshake::Handshake; use valence_protocol::packets::c2s::login::{EncryptionResponse, LoginStart}; use valence_protocol::packets::c2s::play::C2sPlayPacket; @@ -24,7 +23,7 @@ use valence_protocol::packets::s2c::login::{LoginSuccess, S2cLoginPacket}; use valence_protocol::packets::s2c::play::S2cPlayPacket; use valence_protocol::packets::s2c::status::{PingResponse, StatusResponse}; use valence_protocol::types::HandshakeNextState; -use valence_protocol::{Decode, Encode, Packet}; +use valence_protocol::{Decode, Encode, Packet, PacketDecoder, PacketEncoder}; #[derive(Parser, Clone, Debug)] #[clap(author, version, about)] diff --git a/src/chunk.rs b/src/chunk.rs index 684bfab..ed02c23 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -14,14 +14,10 @@ use std::iter::FusedIterator; use paletted_container::PalettedContainer; use rayon::iter::{IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator}; use valence_nbt::compound; -use valence_protocol::block::BlockState; -use valence_protocol::block_pos::BlockPos; use valence_protocol::packets::s2c::play::{ BlockUpdate, ChunkDataAndUpdateLight, UpdateSectionBlocks, }; -use valence_protocol::var_int::VarInt; -use valence_protocol::var_long::VarLong; -use valence_protocol::Encode; +use valence_protocol::{BlockPos, BlockState, Encode, VarInt, VarLong}; use crate::biome::BiomeId; pub use crate::chunk_pos::ChunkPos; diff --git a/src/chunk_pos.rs b/src/chunk_pos.rs index 32f4bf8..9a38eb5 100644 --- a/src/chunk_pos.rs +++ b/src/chunk_pos.rs @@ -1,4 +1,4 @@ -use valence_protocol::block_pos::BlockPos; +use valence_protocol::BlockPos; /// The X and Z position of a chunk in a world. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/src/client.rs b/src/client.rs index 6c10318..ec1e17b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,10 +10,6 @@ pub use bitfield_struct::bitfield; pub use event::*; use rayon::iter::ParallelIterator; use uuid::Uuid; -use valence_protocol::block_pos::BlockPos; -use valence_protocol::byte_angle::ByteAngle; -use valence_protocol::ident::Ident; -use valence_protocol::item::ItemStack; use valence_protocol::packets::c2s::play::ClientCommand; use valence_protocol::packets::s2c::play::{ AcknowledgeBlockChange, ClearTitles, CombatDeath, CustomSoundEffect, DisconnectPlay, @@ -26,15 +22,14 @@ use valence_protocol::packets::s2c::play::{ UpdateEntityPositionAndRotation, UpdateEntityRotation, UpdateTime, }; use valence_protocol::packets::C2sPlayPacket; -use valence_protocol::raw_bytes::RawBytes; -use valence_protocol::text::Text; use valence_protocol::types::{ Action, AttributeProperty, GameMode, GameStateChangeReason, SoundCategory, SyncPlayerPosLookFlags, }; -use valence_protocol::username::Username; -use valence_protocol::var_int::VarInt; -use valence_protocol::{ident, types, Encode, Packet}; +use valence_protocol::{ + ident, types, BlockPos, ByteAngle, Encode, Ident, ItemStack, Packet, RawBytes, Text, Username, + VarInt, +}; use vek::Vec3; use crate::chunk_pos::ChunkPos; diff --git a/src/client/event.rs b/src/client/event.rs index dc6fbb3..79c42e7 100644 --- a/src/client/event.rs +++ b/src/client/event.rs @@ -1,15 +1,11 @@ use std::time::Duration; -use valence_protocol::block::BlockFace; -use valence_protocol::block_pos::BlockPos; use valence_protocol::entity_meta::Pose; -use valence_protocol::ident::Ident; -use valence_protocol::item::ItemStack; use valence_protocol::packets::c2s::play::ResourcePackC2s; use valence_protocol::types::{ ChatMode, ClickContainerMode, DisplayedSkinParts, EntityInteraction, Hand, MainHand, }; -use valence_protocol::var_int::VarInt; +use valence_protocol::{BlockFace, BlockPos, Ident, ItemStack, VarInt}; use vek::Vec3; use super::Client; diff --git a/src/entity.rs b/src/entity.rs index 7e1332e..032182c 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -9,13 +9,11 @@ use bitfield_struct::bitfield; pub use data::{EntityKind, TrackedData}; use rayon::iter::ParallelIterator; use uuid::Uuid; -use valence_protocol::byte_angle::ByteAngle; use valence_protocol::entity_meta::{Facing, PaintingKind, Pose}; use valence_protocol::packets::s2c::play::{ SetEntityMetadata, SetHeadRotation, SpawnEntity, SpawnExperienceOrb, SpawnPlayer, }; -use valence_protocol::raw_bytes::RawBytes; -use valence_protocol::var_int::VarInt; +use valence_protocol::{ByteAngle, RawBytes, VarInt}; use vek::{Aabb, Vec3}; use crate::config::Config; diff --git a/src/entity/data.rs b/src/entity/data.rs index e3f41ae..cef3dfb 100644 --- a/src/entity/data.rs +++ b/src/entity/data.rs @@ -3,11 +3,7 @@ #![allow(clippy::all, missing_docs, trivial_numeric_casts)] use uuid::Uuid; -use valence_protocol::block::BlockState; -use valence_protocol::block_pos::BlockPos; use valence_protocol::entity_meta::*; -use valence_protocol::text::Text; -use valence_protocol::var_int::VarInt; -use valence_protocol::Encode; +use valence_protocol::{BlockPos, BlockState, Encode, Text, VarInt}; include!(concat!(env!("OUT_DIR"), "/entity.rs")); diff --git a/src/inventory.rs b/src/inventory.rs index 4d2b146..24123a4 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -1,8 +1,7 @@ use std::ops::Range; use thiserror::Error; -use valence_protocol::item::ItemStack; -use valence_protocol::var_int::VarInt; +use valence_protocol::{ItemStack, VarInt}; use crate::slab_versioned::{Key, VersionedSlab}; @@ -277,7 +276,7 @@ pub struct InventoryError; #[cfg(test)] mod test { - use valence_protocol::item::{ItemKind, ItemStack}; + use valence_protocol::{ItemKind, ItemStack}; use super::*; diff --git a/src/lib.rs b/src/lib.rs index e339764..ec9caaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,16 +140,16 @@ pub mod prelude { }; pub use uuid::Uuid; pub use valence_nbt::Compound; - pub use valence_protocol::block::{BlockKind, BlockState, PropName, PropValue}; - pub use valence_protocol::block_pos::BlockPos; + pub use valence_protocol::block::{PropName, PropValue}; pub use valence_protocol::entity_meta::Pose; - pub use valence_protocol::ident::{Ident, IdentError}; - pub use valence_protocol::item::{ItemKind, ItemStack}; + pub use valence_protocol::ident::IdentError; pub use valence_protocol::packets::s2c::play::SetTitleAnimationTimes; - pub use valence_protocol::text::{Color, Text, TextFormat}; + pub use valence_protocol::text::Color; pub use valence_protocol::types::{GameMode, Hand, SoundCategory}; - pub use valence_protocol::username::Username; - pub use valence_protocol::{ident, MINECRAFT_VERSION, PROTOCOL_VERSION}; + pub use valence_protocol::{ + ident, BlockKind, BlockPos, BlockState, Ident, ItemKind, ItemStack, Text, TextFormat, + Username, MINECRAFT_VERSION, PROTOCOL_VERSION, + }; pub use vek::{Aabb, Mat2, Mat3, Mat4, Vec2, Vec3, Vec4}; pub use world::{World, WorldId, WorldMeta, Worlds}; diff --git a/src/server.rs b/src/server.rs index 0e10fac..6dd9aa6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -22,16 +22,15 @@ use tokio::runtime::{Handle, Runtime}; use tokio::sync::Semaphore; use uuid::Uuid; use valence_nbt::{compound, Compound, List}; -use valence_protocol::codec::{PacketDecoder, PacketEncoder}; use valence_protocol::packets::c2s::handshake::HandshakeOwned; use valence_protocol::packets::c2s::login::LoginStart; use valence_protocol::packets::c2s::status::{PingRequest, StatusRequest}; use valence_protocol::packets::s2c::login::{DisconnectLogin, LoginSuccess, SetCompression}; use valence_protocol::packets::s2c::status::{PingResponse, StatusResponse}; use valence_protocol::types::HandshakeNextState; -use valence_protocol::username::Username; -use valence_protocol::var_int::VarInt; -use valence_protocol::{ident, MINECRAFT_VERSION, PROTOCOL_VERSION}; +use valence_protocol::{ + ident, PacketDecoder, PacketEncoder, Username, VarInt, MINECRAFT_VERSION, PROTOCOL_VERSION, +}; use crate::biome::{validate_biomes, Biome, BiomeId}; use crate::client::{Client, Clients}; diff --git a/src/server/login.rs b/src/server/login.rs index 3be6392..a6f8163 100644 --- a/src/server/login.rs +++ b/src/server/login.rs @@ -15,17 +15,12 @@ use sha1::Sha1; use sha2::{Digest, Sha256}; use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf}; use uuid::Uuid; -use valence_protocol::ident::Ident; use valence_protocol::packets::c2s::login::{EncryptionResponse, LoginPluginResponse}; use valence_protocol::packets::s2c::login::{ DisconnectLogin, EncryptionRequest, LoginPluginRequest, }; -use valence_protocol::raw_bytes::RawBytes; -use valence_protocol::text::Text; use valence_protocol::types::{MsgSigOrVerifyToken, SignedProperty, SignedPropertyOwned}; -use valence_protocol::username::Username; -use valence_protocol::var_int::VarInt; -use valence_protocol::Decode; +use valence_protocol::{Decode, Ident, RawBytes, Text, Username, VarInt}; use crate::config::Config; use crate::player_textures::SignedPlayerTextures; diff --git a/src/server/packet_controller.rs b/src/server/packet_controller.rs index f87d403..80ff882 100644 --- a/src/server/packet_controller.rs +++ b/src/server/packet_controller.rs @@ -7,8 +7,7 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use tokio::runtime::Handle; use tokio::task::JoinHandle; use tokio::time::timeout; -use valence_protocol::codec::{PacketDecoder, PacketEncoder}; -use valence_protocol::{Decode, Encode, Packet}; +use valence_protocol::{Decode, Encode, Packet, PacketDecoder, PacketEncoder}; use crate::server::byte_channel::{byte_channel, ByteReceiver, ByteSender, TryRecvError}; diff --git a/valence_protocol/src/block.rs b/valence_protocol/src/block.rs index b88a48d..f63069f 100644 --- a/valence_protocol/src/block.rs +++ b/valence_protocol/src/block.rs @@ -7,9 +7,7 @@ use std::iter::FusedIterator; use anyhow::Context; -use crate::item::ItemKind; -use crate::var_int::VarInt; -use crate::{Decode, Encode, Result}; +use crate::{Decode, Encode, ItemKind, Result, VarInt}; include!(concat!(env!("OUT_DIR"), "/block.rs")); diff --git a/valence_protocol/src/block_pos.rs b/valence_protocol/src/block_pos.rs index bb0dffa..dad3a21 100644 --- a/valence_protocol/src/block_pos.rs +++ b/valence_protocol/src/block_pos.rs @@ -2,8 +2,7 @@ use std::io::Write; use anyhow::bail; -use crate::block::BlockFace; -use crate::{Decode, Encode}; +use crate::{BlockFace, Decode, Encode}; /// Represents an absolute block position in world space. #[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)] @@ -28,8 +27,7 @@ impl BlockPos { /// direction. /// /// ``` - /// use valence_protocol::block::BlockFace; - /// use valence_protocol::block_pos::BlockPos; + /// use valence_protocol::{BlockFace, BlockPos}; /// /// let pos = BlockPos::new(0, 0, 0); /// let adj = pos.get_in_direction(BlockFace::South); diff --git a/valence_protocol/src/cache.rs b/valence_protocol/src/cache.rs index 04bc1a2..e79a5a5 100644 --- a/valence_protocol/src/cache.rs +++ b/valence_protocol/src/cache.rs @@ -18,6 +18,7 @@ use crate::{Decode, Encode, Result}; /// /// [`EncodedBuf`]: EncodedBuf /// [^note]: Assuming `T` does not use internal mutability. +#[derive(Debug)] pub struct Cached { val: T, buf: EncodedBuf, @@ -85,8 +86,7 @@ where /// # Examples /// /// ``` -/// use valence_protocol::cache::EncodedBuf; -/// use valence_protocol::Encode; +/// use valence_protocol::{Encode, EncodedBuf}; /// /// let mut buf1 = Vec::new(); /// let mut buf2 = Vec::new(); @@ -101,6 +101,7 @@ where /// /// [`Text`]: crate::text::Text /// [`Compound`]: valence_nbt::Compound +#[derive(Debug)] pub struct EncodedBuf { buf: Vec, res: Result<()>, diff --git a/valence_protocol/src/impls.rs b/valence_protocol/src/impls.rs index c3e5930..6c48d63 100644 --- a/valence_protocol/src/impls.rs +++ b/valence_protocol/src/impls.rs @@ -10,8 +10,7 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use uuid::Uuid; use valence_nbt::Compound; -use crate::var_int::VarInt; -use crate::{Decode, Encode, Result, MAX_PACKET_SIZE}; +use crate::{Decode, Encode, Result, VarInt, MAX_PACKET_SIZE}; // ==== Primitive ==== // diff --git a/valence_protocol/src/item.rs b/valence_protocol/src/item.rs index 14e6a87..630130b 100644 --- a/valence_protocol/src/item.rs +++ b/valence_protocol/src/item.rs @@ -3,9 +3,7 @@ use std::io::Write; use anyhow::{ensure, Context}; use valence_nbt::Compound; -use crate::block::BlockKind; -use crate::var_int::VarInt; -use crate::{Decode, Encode, Result}; +use crate::{BlockKind, Decode, Encode, Result, VarInt}; include!(concat!(env!("OUT_DIR"), "/item.rs")); diff --git a/valence_protocol/src/lib.rs b/valence_protocol/src/lib.rs index 11cc9ae..c8ca0d3 100644 --- a/valence_protocol/src/lib.rs +++ b/valence_protocol/src/lib.rs @@ -8,8 +8,8 @@ //! # Examples //! //! ``` -//! use valence_protocol::codec::{PacketDecoder, PacketEncoder}; //! use valence_protocol::packets::c2s::play::RenameItem; +//! use valence_protocol::{PacketDecoder, PacketEncoder}; //! //! let mut enc = PacketEncoder::new(); //! @@ -43,9 +43,6 @@ //! # Feature Flags //! //! TODO -//! -//! [`PacketEncoder`]: codec::PacketEncoder -//! [`PacketDecoder`]: codec::PacketDecoder #![forbid(unsafe_code)] #![deny( @@ -75,31 +72,45 @@ extern crate self as valence_protocol; use std::io::Write; pub use anyhow::{Error, Result}; +pub use block::{BlockFace, BlockKind, BlockState}; +pub use block_pos::BlockPos; +pub use byte_angle::ByteAngle; +pub use cache::{Cached, EncodedBuf}; +pub use codec::{PacketDecoder, PacketEncoder}; +pub use ident::Ident; +pub use item::{ItemKind, ItemStack}; +pub use raw_bytes::RawBytes; +pub use text::{Text, TextFormat}; +pub use username::Username; +pub use uuid::Uuid; pub use valence_derive::{Decode, Encode, Packet}; -pub use valence_nbt as nbt; +pub use var_int::VarInt; +pub use var_long::VarLong; +pub use {uuid, valence_nbt as nbt}; use crate::byte_counter::ByteCounter; /// The Minecraft protocol version this library currently targets. pub const PROTOCOL_VERSION: i32 = 760; -/// The stringized name of the Minecraft version this library currently targets. +/// The stringified name of the Minecraft version this library currently +/// targets. pub const MINECRAFT_VERSION: &str = "1.19.2"; pub mod block; -pub mod block_pos; -pub mod bounded; -pub mod byte_angle; +mod block_pos; +mod bounded; +mod byte_angle; mod byte_counter; -pub mod cache; -pub mod codec; +mod cache; +mod codec; pub mod enchant; pub mod entity_meta; pub mod ident; mod impls; -pub mod item; +mod item; pub mod packets; -pub mod raw_bytes; +mod raw_bytes; pub mod text; pub mod types; pub mod username; @@ -230,8 +241,6 @@ pub trait Encode { /// ...]` attribute on the variant in question. Discriminant values are assigned /// to variants using rules similar to regular enum discriminants. /// -/// [`VarInt`]: var_int::VarInt -/// /// ``` /// use valence_protocol::Decode; /// @@ -277,8 +286,6 @@ pub trait Decode<'a>: Sized { /// A complete packet is data starting with a [`VarInt`] packet ID. [`Encode`] /// and [`Decode`] implementations on `Self`, if present, are expected to handle /// this leading `VarInt`. -/// -/// [`VarInt`]: var_int::VarInt pub trait Packet { /// The name of this packet. /// diff --git a/valence_protocol/src/text.rs b/valence_protocol/src/text.rs index 1858254..663dda8 100644 --- a/valence_protocol/src/text.rs +++ b/valence_protocol/src/text.rs @@ -8,9 +8,7 @@ use serde::de::Visitor; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use crate::byte_counter::ByteCounter; -use crate::ident::Ident; -use crate::var_int::VarInt; -use crate::{Decode, Encode, Result}; +use crate::{Decode, Encode, Ident, Result, VarInt}; /// Represents formatted text in Minecraft's JSON text format. /// diff --git a/valence_protocol/src/types.rs b/valence_protocol/src/types.rs index b573008..6425068 100644 --- a/valence_protocol/src/types.rs +++ b/valence_protocol/src/types.rs @@ -4,12 +4,8 @@ use bitfield_struct::bitfield; use serde::{Deserialize, Serialize}; use uuid::Uuid; use valence_nbt::Compound; -use valence_protocol::text::Text; -use crate::__private::VarInt; -use crate::block_pos::BlockPos; -use crate::ident::Ident; -use crate::{Decode, Encode}; +use crate::{BlockPos, Decode, Encode, Ident, Text, VarInt}; #[derive(Copy, Clone, Debug, PartialEq, Eq, Encode, Decode)] pub enum HandshakeNextState {