Go to file
Ryan Johnson f4714cf255
Redesign packet processing and improve Client update procedure. (#146)
Closes #82
Closes #43
Closes #64

# Changes and Improvements
- Packet encoding/decoding happens within `Client` instead of being sent
over a channel first. This is better for performance and lays the
groundwork for #83.
- Reduce the amount of copying necessary by leveraging the `bytes` crate
and recent changes to `EncodePacket`. Performance is noticeably improved
with maximum players in the `rust-mc-bot` test going from 750 to 1050.
- Packet encoding/decoding code is decoupled from IO. This is easier to
understand and more suitable for a future protocol lib.
- Precise control over the number of bytes that are buffered for
sending/receiving. This is important for limiting maximum memory usage
correctly.
- "packet controllers" are introduced, which are convenient structures
for managing packet IO before and during the play state.
- `byte_channel` module is created to help implement the
`PlayPacketController`. This is essentially a channel of bytes
implemented with an `Arc<Mutex<BytesMut>>`.
- Error handling in the update procedure for clients was improved using
`anyhow::Result<()>` to exit as early as possible. The `client` module
is a bit cleaner as a result.
- The `LoginPlay` packet is always sent before all other play packets.
We no longer have to worry about the behavior of packets sent before
that packet. Most packet deferring performed currently can be
eliminated.
- The packet_inspector was rewritten in response to the above changes.
- Timeouts on IO operations behave better.

# Known Issues
- The packet_inspector now re-encodes packets rather than just decoding
them. This will cause problems when trying to use it with the vanilla
server because there are missing clientbound packets and other issues.
This will be fixed when the protocol module is moved to a separate
crate.
2022-11-01 03:11:51 -07:00
.github Add --workspace flag to commands in CI (#101) 2022-10-04 02:12:32 -07:00
assets Custom resource packs (#68) 2022-09-17 19:32:40 -07:00
build Avoid calling to_kind() in is_air() (#142) 2022-10-29 13:56:48 -07:00
examples Redesign packet processing and improve Client update procedure. (#146) 2022-11-01 03:11:51 -07:00
extracted Add replaceable boolean to block states (#116) 2022-10-16 03:50:57 -07:00
extractor Add replaceable boolean to block states (#116) 2022-10-16 03:50:57 -07:00
packet_inspector Redesign packet processing and improve Client update procedure. (#146) 2022-11-01 03:11:51 -07:00
performance_tests Redesign packet processing and improve Client update procedure. (#146) 2022-11-01 03:11:51 -07:00
src Redesign packet processing and improve Client update procedure. (#146) 2022-11-01 03:11:51 -07:00
valence_nbt Bump valence_nbt version 2022-10-30 15:26:47 -07:00
.gitignore Add performance tests (#113) 2022-10-14 21:18:03 -07:00
Cargo.toml Redesign packet processing and improve Client update procedure. (#146) 2022-11-01 03:11:51 -07:00
CODE_OF_CONDUCT.md Add code of conduct (#126) 2022-10-19 18:07:43 -07:00
CONTRIBUTING.md Clarify top-down modules guideline and remove "separate data and functions" guideline. 2022-10-08 19:51:01 -07:00
LICENSE.txt prepare for crates.io 2022-01-20 06:39:49 -08:00
README.md Uncheck proxy support in README.md 2022-10-21 20:00:19 -07:00
rustfmt.toml Change rustfmt settings 2022-08-28 21:31:07 -07:00

A Rust framework for building Minecraft: Java Edition servers.

Like feather, Valence is an effort to build a Minecraft compatible server completely from scratch in Rust. The difference is that Valence has decided to organize the effort a little differently. All game logic is behind a trait. This approach has many advantages. Features such as a plugin system, dedicated executable, and vanilla game mechanics can be implemented on top of Valence. Valence is a Rust library like any other.

In the future we may decide to reimplement vanilla game mechanics as a separate project. If you're developing something like a minigame server without need for vanilla game mechanics, you can depend on Valence directly.

Goals

Valence aims to be the following:

  • Complete. Abstractions for the full breadth of the Minecraft protocol.
  • Flexible. Your use case should be achievable without manually sending and receiving packets or other hacks.
  • Minimal. The API surface is small with only the necessities exposed. Opinionated features such as a standalone executable, plugin system, and reimplementation of vanilla mechanics should be built in a separate crate on top of the foundation that Valence provides.
  • Intuitive. An API that is easy to use and difficult to misuse. Extensive documentation is important.
  • Efficient. Optimal use of system resources with multiple CPU cores in mind.
  • Up to date. Targets the most recent stable version of Minecraft. Support for multiple versions at once is not planned (although you can use a proxy).

Current Status

Valence is still early in development with many features unimplemented or incomplete. However, the foundations are in place. Here are some noteworthy achievements:

  • A new serde library for Minecraft's Named Binary Tag (NBT) format
  • Authentication, encryption, and compression
  • Block states
  • Chunks
  • Entities and tracked data
  • 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.
  • Items
  • Inventory
  • Block entities
  • Proxy support (Velocity, Bungeecord and Waterfall)
  • Sounds, particles, etc.
  • Utilities for continuous collision detection

Here is a short video showing the examples and some of its current capabilities.

Getting Started

Running the Examples

You may want to try running one of the examples. After cloning the repository, run

cargo r -r --example conway

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. Documentation is available here.

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" }

View the documentation by running cargo d --open in your project.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md. You can also join the Discord 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 (GitHub is preferred).

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