Crate valence

Source
Expand description

❗ NOTE: This documentation is sourced from the main branch. If you’re looking for the most recent stable release, go here.


license chat on Discord GitHub sponsors

A Rust framework for building Minecraft: Java Edition servers.

Built on top of Bevy ECS, Valence is an effort to create a Minecraft compatible server completely from scratch in Rust. You can think of Valence as a game engine for Minecraft servers. It doesn’t do much by default, but by writing game logic yourself and leveraging Bevy’s powerful plugin system, you can make almost anything.

Opinionated features like dynamic scripting, dedicated executables, and vanilla game mechanics are all expected to be built as optional plugins. This level of modularity is desirable for those looking to build highly custom experiences in Minecraft such as minigame servers.

⚠️ Valence is still early in development with many features unimplemented or incomplete. Expect to encounter bugs, limitations, and breaking changes.

§Goals

Valence aims to be the following:

  • Complete. Abstractions for the full breadth of the Minecraft protocol.
  • Flexible. Can easily extend Valence from within user code. Direct access to the Minecraft protocol is provided.
  • Modular. Pick and choose the components you need.
  • Intuitive. An API that is easy to use and difficult to misuse. Extensive documentation and examples are important.
  • Efficient. Optimal use of system resources with multiple CPU cores in mind. Valence uses very little memory and can support thousands of players at the same time without lag (assuming you have the bandwidth).
  • Up to date. Targets the most recent stable version of Minecraft. Support for multiple versions at once is not planned. However, you can use a proxy with ViaBackwards to achieve backwards compatibility with older clients.

§Current Status

Here are some noteworthy achievements:

  • valence_nbt: A speedy new library for Minecraft’s Named Binary Tag (NBT) format.
  • Authentication, encryption, and compression
  • Block states
  • Chunks
  • Entities and metadata
  • Bounding volume hierarchy for fast spatial entity queries
  • Player list and player skins
  • Dimensions, biomes, and worlds
  • JSON Text API
  • A Fabric mod for extracting data from the game into JSON files. These files are processed by a build script to generate Rust code for the project. The JSON files can be used in other projects as well.
  • Inventories
  • Items
  • Particles
  • Anvil file format (read only)
  • Proxy support (Velocity, Bungeecord and Waterfall)

Here is a short video showing the examples and some of Valence’s capabilities.

§Getting Started

§Running the Examples

After cloning the repository, run this command to try an example.

cargo r -r --example parkour

I also recommend giving game_of_life, terrain, and cow_sphere a try.

Next, open your Minecraft client and connect to the address localhost. If all goes well you should be playing on the server.

§Adding Valence as a Dependency

Valence is published to crates.io. Run cargo add valence to add it to your project.

However, the crates.io version is likely outdated. To use the most recent development version, add Valence as a git dependency.

[dependencies]
valence = { git = "https://github.com/valence-rs/valence" }

Documentation from the main branch is available here.

§Contributing

Contributions are welcome! Please see CONTRIBUTING.md. You can join Discord or GitHub Discussions to discuss the project and ask questions.

§License

Code is licensed under MIT while the Valence logo is under CC BY-NC-ND 4.0

§Funding

If you would like to contribute financially, consider sponsoring me (rj00a) on GitHub or Patreon.

I would love to continue working on Valence and your support would help me do that. Thanks!

Re-exports§

pub use bevy_log as log;
pub use valence_advancement as advancement;
pub use valence_anvil as anvil;
pub use valence_boss_bar as boss_bar;
pub use valence_command as command;
pub use valence_command_macros as command_macros;
pub use valence_equipment as equipment;
pub use valence_inventory as inventory;
pub use valence_lang as lang;
pub use valence_network as network;
pub use valence_player_list as player_list;
pub use valence_scoreboard as scoreboard;
pub use valence_weather as weather;
pub use valence_world_border as world_border;

Modules§

abilities
action
app
This crate is about everything concerning the highest-level, application layer of a Bevy app.
block
brand
client
client_command
client_settings
custom_payload
ecs
Bevy ECS
entity
valence_entity
event_loop
hand_swing
ident
valence_ident
interact_block
interact_entity
interact_item
item
keepalive
layer
Defines chunk layers and entity layers. Chunk layers contain the chunks and dimension data of a world, while entity layers contain all the Minecraft entities.
math
valence_math
message
movement
nbt
Crates
op_level
prelude
Contains the most frequently used items in Valence projects.
protocol
valence_protocol
rand
Utilities for random number generation
registry
valence_registry
resource_pack
spawn
Handles spawning and respawning the client.
status
status_effect
status_effects
teleport
testing
text
valence_text
title
uuid
Generate and parse universally unique identifiers (UUIDs).

Macros§

ident
Creates a new Ident at compile time from a string literal. A compile error is raised if the string is not a valid resource identifier.

Structs§

BiomePos
BlockPos
Represents an absolute block position in world space.
BlockState
Represents the state of a block. This does not include block entity data such as the text on a sign, the design on a banner, or the content of a spawner.
ChunkLayer
A Component containing the chunks and dimension information of a Minecraft world.
ChunkPos
The X and Z position of a chunk.
ChunkView
Represents the set of all chunk positions that a client can see, defined by a center chunk position pos and view distance dist.
CompressionThreshold
How large a packet should be before it is compressed by the packet encoder.
DefaultPlugins
This plugin group will add all the default plugins for a Valence application.
Despawned
A marker Component for entities that should be despawned at the end of the tick.
EntityLayer
A Component containing Minecraft entities.
EventLoopPostUpdate
EventLoopPreUpdate
EventLoopUpdate
Ident
A wrapper around a string type S which guarantees the wrapped string is a valid resource identifier.
ItemStack
A stack of items in an inventory.
LayerBundle
Convenience Bundle for spawning a layer entity with both ChunkLayer and EntityLayer components.
Server
Contains global server state accessible as a Resource.
ServerPlugin
ServerSettings
Text
Represents formatted text in Minecraft’s JSON text format.
UniqueId
The universally unique identifier of an entity. Component wrapper for a Uuid.

Enums§

Difficulty
Direction
GameMode
Hand
ItemKind
Represents an item from the game

Constants§

DEFAULT_TPS
Minecraft’s standard ticks per second (TPS).
MINECRAFT_VERSION
The stringified name of the Minecraft version this library currently targets.
PROTOCOL_VERSION
The Minecraft protocol version this library currently targets.

Traits§

Layer
Common functionality for layers. Notable implementors are ChunkLayer and EntityLayer.