From 24cf864ed1961bd4122103e8371333b424e6f831 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 6 Jul 2022 18:27:59 -0700 Subject: [PATCH] Don't export items arbitrarily at the crate root --- examples/conway.rs | 13 +++++++------ examples/cow_sphere.rs | 10 +++++----- examples/terrain.rs | 9 +++++---- src/biome.rs | 3 ++- src/block.rs | 1 + src/chunk.rs | 7 ++++++- src/chunk_pos.rs | 2 +- src/client.rs | 15 ++++++++------- src/client/event.rs | 3 ++- src/config.rs | 6 +++++- src/entity.rs | 2 +- src/entity/data.rs | 6 ++++-- src/ident.rs | 4 ++-- src/lib.rs | 15 +-------------- src/player_list.rs | 2 +- src/protocol.rs | 2 +- src/protocol/packets.rs | 3 ++- src/server.rs | 11 ++++++----- src/spatial_index.rs | 3 ++- src/text.rs | 2 +- src/util.rs | 2 +- src/world.rs | 5 ++++- 22 files changed, 68 insertions(+), 58 deletions(-) diff --git a/examples/conway.rs b/examples/conway.rs index 40d095e..9fba71e 100644 --- a/examples/conway.rs +++ b/examples/conway.rs @@ -7,15 +7,16 @@ use std::sync::Mutex; use log::LevelFilter; use num::Integer; use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; +use valence::biome::Biome; +use valence::block::BlockState; use valence::client::{ClientEvent, ClientId, GameMode, Hand}; use valence::config::{Config, ServerListPing}; +use valence::dimension::{Dimension, DimensionId}; use valence::entity::meta::Pose; -use valence::entity::EntityData; -use valence::text::Color; -use valence::{ - async_trait, ident, Biome, BlockState, Dimension, DimensionId, EntityId, EntityKind, Server, - SharedServer, ShutdownResult, TextFormat, -}; +use valence::entity::{EntityData, EntityId, EntityKind}; +use valence::server::{Server, SharedServer, ShutdownResult}; +use valence::text::{Color, TextFormat}; +use valence::{async_trait, ident}; pub fn main() -> ShutdownResult { env_logger::Builder::new() diff --git a/examples/cow_sphere.rs b/examples/cow_sphere.rs index a4ec57e..e1c3930 100644 --- a/examples/cow_sphere.rs +++ b/examples/cow_sphere.rs @@ -4,14 +4,14 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; use log::LevelFilter; +use valence::async_trait; use valence::client::GameMode; use valence::config::{Config, ServerListPing}; -use valence::text::Color; +use valence::dimension::DimensionId; +use valence::entity::{EntityId, EntityKind}; +use valence::server::{Server, SharedServer, ShutdownResult}; +use valence::text::{Color, TextFormat}; use valence::util::to_yaw_and_pitch; -use valence::{ - async_trait, DimensionId, EntityId, EntityKind, Server, SharedServer, ShutdownResult, - TextFormat, -}; use vek::{Mat3, Vec3}; pub fn main() -> ShutdownResult { diff --git a/examples/terrain.rs b/examples/terrain.rs index b825434..9cb9432 100644 --- a/examples/terrain.rs +++ b/examples/terrain.rs @@ -5,14 +5,15 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use log::LevelFilter; use noise::{NoiseFn, Seedable, SuperSimplex}; use rayon::iter::ParallelIterator; +use valence::async_trait; use valence::block::{BlockState, PropName, PropValue}; +use valence::chunk::ChunkPos; use valence::client::GameMode; use valence::config::{Config, ServerListPing}; -use valence::text::Color; +use valence::dimension::DimensionId; +use valence::server::{Server, SharedServer, ShutdownResult}; +use valence::text::{Color, TextFormat}; use valence::util::chunks_in_view_distance; -use valence::{ - async_trait, ChunkPos, DimensionId, Server, SharedServer, ShutdownResult, TextFormat, -}; use vek::Lerp; pub fn main() -> ShutdownResult { diff --git a/src/biome.rs b/src/biome.rs index e75d18f..6d82bf4 100644 --- a/src/biome.rs +++ b/src/biome.rs @@ -1,4 +1,5 @@ -use crate::{ident, Ident}; +use crate::ident; +use crate::ident::Ident; /// Identifies a particular [`Biome`]. /// diff --git a/src/block.rs b/src/block.rs index 318982f..7067138 100644 --- a/src/block.rs +++ b/src/block.rs @@ -5,6 +5,7 @@ use std::io::{Read, Write}; use anyhow::Context; +pub use crate::block_pos::BlockPos; use crate::protocol::{Decode, Encode, VarInt}; include!(concat!(env!("OUT_DIR"), "/block.rs")); diff --git a/src/chunk.rs b/src/chunk.rs index 0a7241c..a7252df 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -9,12 +9,17 @@ use bitvec::vec::BitVec; use num::Integer; use rayon::iter::{IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator}; +use crate::biome::BiomeId; use crate::block::BlockState; +use crate::block_pos::BlockPos; +pub use crate::chunk_pos::ChunkPos; +use crate::dimension::DimensionId; use crate::protocol::packets::play::s2c::{ BlockUpdate, LevelChunkHeightmaps, LevelChunkWithLight, S2cPlayPacket, SectionBlocksUpdate, }; use crate::protocol::{Encode, Nbt, VarInt, VarLong}; -use crate::{BiomeId, BlockPos, ChunkPos, DimensionId, SharedServer, Ticks}; +use crate::server::SharedServer; +use crate::Ticks; pub struct Chunks { chunks: HashMap, diff --git a/src/chunk_pos.rs b/src/chunk_pos.rs index 8d06200..f784626 100644 --- a/src/chunk_pos.rs +++ b/src/chunk_pos.rs @@ -1,4 +1,4 @@ -use crate::BlockPos; +use crate::block::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 99a8de4..1597f54 100644 --- a/src/client.rs +++ b/src/client.rs @@ -12,9 +12,11 @@ use uuid::Uuid; use vek::Vec3; use crate::biome::{Biome, BiomeGrassColorModifier, BiomePrecipitation}; -use crate::dimension::{Dimension, DimensionEffects}; +use crate::block_pos::BlockPos; +use crate::chunk_pos::ChunkPos; +use crate::dimension::{Dimension, DimensionEffects, DimensionId}; use crate::entity::data::Player; -use crate::entity::{velocity_to_packet_units, EntityKind}; +use crate::entity::{velocity_to_packet_units, Entities, Entity, EntityId, EntityKind}; use crate::player_textures::SignedPlayerTextures; use crate::protocol::packets::play::c2s::{ C2sPlayPacket, DiggingStatus, InteractKind, PlayerCommandId, @@ -32,13 +34,12 @@ use crate::protocol::packets::play::s2c::{ SetTitleText, SpawnPosition, SystemChat, TeleportEntity, ENTITY_EVENT_MAX_BOUND, }; use crate::protocol::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt}; -use crate::server::C2sPacketChannels; +use crate::server::{C2sPacketChannels, NewClientData, SharedServer}; use crate::slotmap::{Key, SlotMap}; +use crate::text::Text; use crate::util::{chunks_in_view_distance, is_chunk_in_view_distance}; -use crate::{ - ident, BlockPos, ChunkPos, DimensionId, Entities, Entity, EntityId, NewClientData, - SharedServer, Text, Ticks, WorldId, Worlds, LIBRARY_NAMESPACE, -}; +use crate::world::{WorldId, Worlds}; +use crate::{ident, Ticks, LIBRARY_NAMESPACE}; pub struct Clients { sm: SlotMap, diff --git a/src/client/event.rs b/src/client/event.rs index 95c7720..eb58273 100644 --- a/src/client/event.rs +++ b/src/client/event.rs @@ -2,10 +2,11 @@ use std::time::Duration; use vek::Vec3; +use crate::block_pos::BlockPos; +use crate::entity::EntityId; use crate::protocol::packets::play::c2s::BlockFace; pub use crate::protocol::packets::play::c2s::{ChatMode, DisplayedSkinParts, Hand, MainHand}; pub use crate::protocol::packets::play::s2c::GameMode; -use crate::{BlockPos, EntityId}; #[derive(Debug)] pub enum ClientEvent { diff --git a/src/config.rs b/src/config.rs index f0c6a58..499dd5d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,11 @@ use std::panic::{RefUnwindSafe, UnwindSafe}; use async_trait::async_trait; use tokio::runtime::Handle as TokioHandle; -use crate::{Biome, Dimension, NewClientData, Server, SharedServer, Text, Ticks}; +use crate::biome::Biome; +use crate::dimension::Dimension; +use crate::server::{NewClientData, Server, SharedServer}; +use crate::text::Text; +use crate::Ticks; /// A trait containing callbacks which are invoked by the running Minecraft /// server. diff --git a/src/entity.rs b/src/entity.rs index 2f71e7e..a2ed36d 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -18,7 +18,7 @@ use crate::protocol::packets::play::s2c::{ use crate::protocol::{ByteAngle, RawBytes, VarInt}; use crate::slotmap::{Key, SlotMap}; use crate::util::aabb_from_bottom_and_size; -use crate::WorldId; +use crate::world::WorldId; pub struct Entities { sm: SlotMap, diff --git a/src/entity/data.rs b/src/entity/data.rs index f32d21b..801642b 100644 --- a/src/entity/data.rs +++ b/src/entity/data.rs @@ -1,8 +1,10 @@ #![allow(clippy::all, missing_docs)] -use crate::block::BlockState; +use crate::block::{BlockPos, BlockState}; use crate::entity::meta::*; +use crate::entity::EntityId; use crate::protocol::{Encode, VarInt}; -use crate::{BlockPos, EntityId, Text, Uuid}; +use crate::text::Text; +use crate::uuid::Uuid; include!(concat!(env!("OUT_DIR"), "/entity.rs")); diff --git a/src/ident.rs b/src/ident.rs index 19dce5c..1568ef1 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -249,8 +249,8 @@ macro_rules! ident { let errmsg = "invalid identifier in `ident` macro"; #[allow(clippy::redundant_closure_call)] (|args: ::std::fmt::Arguments| match args.as_str() { - Some(s) => $crate::Ident::new(s).expect(errmsg), - None => $crate::Ident::new(args.to_string()).expect(errmsg), + Some(s) => $crate::ident::Ident::new(s).expect(errmsg), + None => $crate::ident::Ident::new(args.to_string()).expect(errmsg), })(format_args!($($arg)*)) }} } diff --git a/src/lib.rs b/src/lib.rs index 4e05323..a2df103 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,21 +33,8 @@ pub mod util; pub mod world; pub use async_trait::async_trait; -pub use biome::{Biome, BiomeId}; -pub use block::BlockState; -pub use block_pos::BlockPos; -pub use chunk::{Chunk, Chunks}; -pub use chunk_pos::ChunkPos; -pub use client::{Client, Clients}; -pub use config::Config; -pub use dimension::{Dimension, DimensionId}; -pub use entity::{Entities, Entity, EntityId, EntityKind}; -pub use ident::Ident; -pub use server::{start_server, NewClientData, Server, SharedServer, ShutdownResult}; +pub use server::start_server; pub use spatial_index::SpatialIndex; -pub use text::{Text, TextFormat}; -pub use uuid::Uuid; -pub use world::{WorldId, WorldMeta, Worlds}; pub use {nbt, uuid, vek}; /// The Minecraft protocol version that this library targets. diff --git a/src/player_list.rs b/src/player_list.rs index b25b968..50c0292 100644 --- a/src/player_list.rs +++ b/src/player_list.rs @@ -11,7 +11,7 @@ use crate::protocol::packets::play::s2c::{ }; use crate::protocol::packets::Property; use crate::protocol::VarInt; -use crate::Text; +use crate::text::Text; pub struct PlayerList { entries: HashMap, diff --git a/src/protocol.rs b/src/protocol.rs index 55dfc62..09d2d5a 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -19,7 +19,7 @@ pub use var_int::VarInt; pub use var_long::VarLong; use vek::{Vec2, Vec3, Vec4}; -use crate::EntityId; +use crate::entity::EntityId; /// Trait for types that can be written to the Minecraft protocol. pub trait Encode { diff --git a/src/protocol/packets.rs b/src/protocol/packets.rs index 742293d..3d8e0ba 100644 --- a/src/protocol/packets.rs +++ b/src/protocol/packets.rs @@ -16,11 +16,12 @@ use uuid::Uuid; use vek::Vec3; use crate::block_pos::BlockPos; +use crate::ident::Ident; use crate::protocol::{ BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, Nbt, RawBytes, VarInt, VarLong, }; -use crate::{Ident, Text}; +use crate::text::Text; /// Trait for types that can be written to the Minecraft protocol as a complete /// packet. diff --git a/src/server.rs b/src/server.rs index 65a2e9f..b68f23c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -4,8 +4,8 @@ use std::iter::FusedIterator; use std::net::SocketAddr; use std::sync::atomic::{AtomicI64, Ordering}; use std::sync::{Arc, Mutex}; -use std::{thread, io}; use std::time::{Duration, Instant}; +use std::{io, thread}; use anyhow::{bail, ensure, Context}; use flume::{Receiver, Sender}; @@ -25,7 +25,11 @@ use tokio::runtime::{Handle, Runtime}; use tokio::sync::{oneshot, Semaphore}; use uuid::Uuid; +use crate::biome::{Biome, BiomeId}; +use crate::client::{Client, Clients}; use crate::config::{Config, ServerListPing}; +use crate::dimension::{Dimension, DimensionId}; +use crate::entity::Entities; use crate::player_textures::SignedPlayerTextures; use crate::protocol::codec::{Decoder, Encoder}; use crate::protocol::packets::handshake::{Handshake, HandshakeNextState}; @@ -39,10 +43,7 @@ use crate::protocol::packets::{login, Property}; use crate::protocol::{BoundedArray, BoundedString, VarInt}; use crate::util::valid_username; use crate::world::Worlds; -use crate::{ - Biome, BiomeId, Client, Clients, Dimension, DimensionId, Entities, Ticks, PROTOCOL_VERSION, - VERSION_NAME, -}; +use crate::{Ticks, PROTOCOL_VERSION, VERSION_NAME}; pub struct Server { pub shared: SharedServer, diff --git a/src/spatial_index.rs b/src/spatial_index.rs index 3b4291d..d9ca842 100644 --- a/src/spatial_index.rs +++ b/src/spatial_index.rs @@ -2,7 +2,8 @@ use vek::{Aabb, Vec3}; use crate::bvh::Bvh; pub use crate::bvh::TraverseStep; -use crate::{Entities, EntityId, WorldId}; +use crate::entity::{Entities, EntityId}; +use crate::world::WorldId; pub struct SpatialIndex { bvh: Bvh, diff --git a/src/text.rs b/src/text.rs index 3ff49b4..a724038 100644 --- a/src/text.rs +++ b/src/text.rs @@ -8,8 +8,8 @@ use std::io::{Read, Write}; use serde::de::Visitor; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use crate::ident::Ident; use crate::protocol::{BoundedString, Decode, Encode}; -use crate::Ident; /// Represents formatted text in Minecraft's JSON text format. /// diff --git a/src/util.rs b/src/util.rs index e3f4974..cf0ad0d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use num::cast::AsPrimitive; use num::Float; use vek::{Aabb, Vec3}; -use crate::ChunkPos; +use crate::chunk_pos::ChunkPos; /// Returns true if the given string meets the criteria for a valid Minecraft /// username. diff --git a/src/world.rs b/src/world.rs index 958684f..2c084f8 100644 --- a/src/world.rs +++ b/src/world.rs @@ -2,9 +2,12 @@ use std::iter::FusedIterator; use rayon::iter::ParallelIterator; +use crate::chunk::Chunks; +use crate::dimension::DimensionId; use crate::player_list::PlayerList; +use crate::server::SharedServer; use crate::slotmap::{Key, SlotMap}; -use crate::{Chunks, DimensionId, SharedServer, SpatialIndex}; +use crate::SpatialIndex; pub struct Worlds { sm: SlotMap,