valence/src/lib.rs

139 lines
4.4 KiB
Rust
Raw Normal View History

2022-09-04 09:48:11 +10:00
//! <img src="https://raw.githubusercontent.com/rj00a/valence/main/assets/logo-full.svg" width="400">
//!
//! ---
//!
2022-07-15 16:18:20 +10:00
//! A Rust framework for building Minecraft servers.
2022-07-11 22:08:02 +10:00
//!
//! At a high level, a Valence [`Server`] is a collection of [`Clients`],
2022-09-02 17:06:45 +10:00
//! [`Entities`], and [`Worlds`]. When a client connects to the server they are
//! added to the collection of `Clients`. After connecting, clients should
//! be assigned to a [`World`] where they can interact with the entities
//! and [`Chunks`] that are a part of it.
2022-07-11 22:08:02 +10:00
//!
//! The Valence documentation assumes some familiarity with Minecraft and its
//! mechanics. See the [Minecraft Wiki] for general information and [wiki.vg]
//! for protocol documentation.
//!
2022-09-02 17:06:45 +10:00
//! For more information, see the repository [README].
//!
2022-07-11 22:08:02 +10:00
//! [Minecraft Wiki]: https://minecraft.fandom.com/wiki/Minecraft_Wiki
//! [wiki.vg]: https://wiki.vg/Main_Page
2022-09-02 17:06:45 +10:00
//! [README]: https://github.com/rj00a/valence
2022-07-11 22:08:02 +10:00
//!
//! # Logging
//!
//! Valence uses the [log] crate to report errors and other information. You may
//! want to use a logging implementation such as [env_logger] to see these
//! messages.
//!
//! [log]: https://docs.rs/log/latest/log/
//! [env_logger]: https://docs.rs/env_logger/latest/env_logger/
//!
//! # An Important Note on [`mem::swap`]
//!
//! In Valence, many types are owned by the library but given out as mutable
//! references for the user to modify. Examples of such types include [`World`],
//! [`Chunk`], [`Entity`], and [`Client`].
//!
//! **You must not call [`mem::swap`] on these references (or any other
//! function that would move their location in memory).** Doing so breaks
2022-07-15 16:18:20 +10:00
//! invariants within the library and the resulting behavior is safe but
2022-09-02 17:06:45 +10:00
//! unspecified. You can think of these types as being [pinned](std::pin).
2022-07-11 22:08:02 +10:00
//!
//! Preventing this illegal behavior using Rust's type system was considered too
2022-09-02 17:06:45 +10:00
//! cumbersome, so this note has been left here instead.
2022-07-11 22:08:02 +10:00
//!
//! [`mem::swap`]: std::mem::swap
//!
//! # Examples
//!
2022-09-02 17:06:45 +10:00
//! See the [examples] directory in the source repository.
2022-07-11 22:08:02 +10:00
//!
//! [examples]: https://github.com/rj00a/valence/tree/main/examples
//!
//! [`Server`]: crate::server::Server
//! [`Clients`]: crate::client::Clients
//! [`Entities`]: crate::entity::Entities
//! [`Worlds`]: crate::world::Worlds
//! [`World`]: crate::world::World
//! [`Chunks`]: crate::chunk::Chunks
//! [`Chunk`]: crate::chunk::Chunk
//! [`Entity`]: crate::entity::Entity
//! [`Client`]: crate::client::Client
2022-09-04 09:48:11 +10:00
#![doc(
2022-09-05 15:25:08 +10:00
html_logo_url = "https://raw.githubusercontent.com/valence-rs/valence/main/assets/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/valence-rs/valence/main/assets/logo.svg"
2022-09-04 09:48:11 +10:00
)]
2022-04-15 07:55:45 +10:00
#![forbid(unsafe_code)]
2022-04-29 17:48:41 +10:00
#![warn(
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
2022-07-11 22:08:02 +10:00
unused_import_braces
2022-04-29 17:48:41 +10:00
)]
2022-07-15 16:18:20 +10:00
#![allow(
clippy::derive_partial_eq_without_eq,
clippy::unusual_byte_groupings,
clippy::comparison_chain
)]
2022-04-15 07:55:45 +10:00
/// Used on [`Config`](config::Config) to allow for async methods in traits.
///
/// For more information see the [async_trait] crate.
///
/// [async_trait]: https://docs.rs/async-trait/latest/async_trait/
pub use async_trait::async_trait;
#[doc(inline)]
pub use server::start_server;
#[doc(inline)]
2022-09-02 17:06:45 +10:00
pub use {serde_nbt as nbt, uuid, vek};
2022-06-10 13:26:21 +10:00
pub mod biome;
2022-04-18 10:06:13 +10:00
pub mod block;
2022-04-15 07:55:45 +10:00
mod block_pos;
2022-06-13 19:34:03 +10:00
mod bvh;
2022-04-29 17:48:41 +10:00
pub mod chunk;
2022-06-28 10:52:23 +10:00
mod chunk_pos;
2022-04-29 17:48:41 +10:00
pub mod client;
2022-04-15 07:55:45 +10:00
pub mod config;
2022-06-10 13:26:21 +10:00
pub mod dimension;
2022-04-15 07:55:45 +10:00
pub mod entity;
2022-06-10 13:26:21 +10:00
pub mod ident;
2022-07-11 22:08:02 +10:00
pub mod player_list;
pub mod player_textures;
2022-07-11 22:08:02 +10:00
#[allow(dead_code)]
2022-09-06 11:37:55 +10:00
#[doc(hidden)]
2022-09-01 17:57:02 +10:00
pub mod protocol;
2022-04-29 17:48:41 +10:00
pub mod server;
mod slab;
2022-08-10 07:44:04 +10:00
mod slab_rc;
mod slab_versioned;
2022-07-11 22:08:02 +10:00
pub mod spatial_index;
2022-04-15 07:55:45 +10:00
pub mod text;
pub mod util;
2022-04-29 17:48:41 +10:00
pub mod world;
2022-04-15 07:55:45 +10:00
2022-07-11 22:08:02 +10:00
/// The Minecraft protocol version this library currently targets.
2022-08-31 11:41:17 +10:00
pub const PROTOCOL_VERSION: i32 = 760;
2022-07-11 22:08:02 +10:00
/// The name of the Minecraft version this library currently targets, e.g.
/// "1.8.2"
2022-08-31 11:41:17 +10:00
pub const VERSION_NAME: &str = "1.19.2";
2022-04-15 07:55:45 +10:00
2022-07-11 22:08:02 +10:00
/// The namespace for this library used internally for
/// [identifiers](crate::ident::Ident).
///
/// You should avoid using this namespace in your own identifiers.
2022-07-18 14:29:44 +10:00
pub const LIBRARY_NAMESPACE: &str = "valence";
2022-04-15 07:55:45 +10:00
/// A discrete unit of time where 1 tick is the duration of a
/// single game update.
///
2022-07-18 14:29:44 +10:00
/// The duration of a game update on a Valence server depends on the current
/// configuration. In some contexts, "ticks" refer to the configured tick rate
/// while others refer to Minecraft's [standard TPS](STANDARD_TPS).
2022-04-15 07:55:45 +10:00
pub type Ticks = i64;
2022-07-18 14:29:44 +10:00
/// Minecraft's standard ticks per second (TPS).
pub const STANDARD_TPS: Ticks = 20;