Go to file
Ryan Johnson cb9230ec34
ECS Rewrite (#184)
This PR redesigns Valence's architecture around the Bevy Entity
Component System framework (`bevy_ecs` and `bevy_app`). Along the way, a
large number of changes and improvements have been made.
- Valence is now a Bevy plugin. This allows Valence to integrate with
the wider Bevy ecosystem.
- The `Config` trait has been replaced with the plugin struct which is
much easier to configure. Async callbacks are grouped into their own
trait.
- `World` has been renamed to `Instance` to avoid confusion with
`bevy_ecs::world::World`.
- Entities, clients, player list, and inventories are all just ECS
components/resources. There is no need for us to have our own
generational arena/slotmap/etc for each one.
- Client events use Bevy's event system. Users can read events with the
`EventReader` system parameter. This also means that events are
dispatched at an earlier stage of the program where access to the full
server is available. There is a special "event loop" stage which is used
primarily to avoid the loss of ordering information between events.
- Chunks have been completely overhauled to be simpler and faster. The
distinction between loaded and unloaded chunks has been mostly
eliminated. The per-section bitset that tracked changes has been
removed, which should further reduce memory usage. More operations on
chunks are available such as removal and cloning.
- The full client's game profile is accessible rather than just the
textures.
- Replaced `vek` with `glam` for parity with Bevy.
- Basic inventory support has been added.
- Various small changes to `valence_protocol`.
- New Examples
- The terrain and anvil examples are now fully asynchronous and will not
block the main tick loop while chunks are loading.

# TODOs
- [x] Implement and dispatch client events.
- ~~[ ] Finish implementing the new entity/chunk update algorithm.~~ New
approach ended up being slower. And also broken.
- [x] [Update rust-mc-bot to
1.19.3](https://github.com/Eoghanmc22/rust-mc-bot/pull/3).
- [x] Use rust-mc-bot to test for and fix any performance regressions.
Revert to old entity/chunk update algorithm if the new one turns out to
be slower for some reason.
- [x] Make inventories an ECS component.
- [x] Make player lists an ECS ~~component~~ resource.
- [x] Expose all properties of the client's game profile.
- [x] Update the examples.
- [x] Update `valence_anvil`.
- ~~[ ] Update `valence_spatial_index` to use `glam` instead of `vek`.~~
Maybe later
- [x] Make entity events use a bitset.
- [x] Update docs.

Closes #69
Closes #179
Closes #53

---------

Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
Co-authored-by: AviiNL <me@avii.nl>
Co-authored-by: Danik Vitek <x3665107@gmail.com>
Co-authored-by: Snowiiii <71594357+Snowiiii@users.noreply.github.com>
2023-02-11 09:51:53 -08:00
.github ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
assets Custom resource packs (#68) 2022-09-17 19:32:40 -07:00
crates ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
extracted Disable biome extractor 2022-12-29 23:31:06 -08:00
extractor ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
.gitignore ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
Cargo.toml ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
CODE_OF_CONDUCT.md Add code of conduct (#126) 2022-10-19 18:07:43 -07:00
CONTRIBUTING.md ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
LICENSE.txt prepare for crates.io 2022-01-20 06:39:49 -08:00
README.md ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00
rustfmt.toml Change rustfmt settings 2022-08-28 21:31:07 -07:00

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.

Goals

Valence aims to be the following:

  • Complete. Abstractions for the full breadth of the Minecraft protocol.
  • Flexible. Valence provides direct access to the lowest levels of Minecraft's protocol when necessary.
  • Modular. Pick and choose the features you actually 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

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

  • valence_nbt: A speedy new library for Minecraft's Named Binary Tag (NBT) format.
  • valence_protocol: A library for working with Minecraft's protocol. Does not depend on Valence and can be used in other projects.
  • 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 (outdated) showing the examples and some of Valence's capabilities.

Getting Started

Running the Examples

After cloning the repository, run

cargo r -r --example

to view the list of examples. I recommend giving parkour, conway, 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. 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 latest 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.

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