<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->
## Description
Take 3 of #247.
I've added a minimal chat example - ignoring chat signing, etc. It's in
the file `crates/valence/examples/chat.rs`.
## Test Plan
Manual, unfortunately :(
Steps:
1. Open two minecraft clients, with two separate accounts (or usernames
if using offline mode)
2. Connect to the server in both clients
3. Type a chat message, checking it appears to both clients, with the
correct username.
4. Type a command, checking it appears only to the sender.
---------
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->
## Description
<!-- Describe the changes you've made. You may include any justification
you want here. -->
An implementation of a Minecraft server stresser for testing purposes.
The potential of this pull request is to implement a minimal stresser
binary package that would be bound to the local `valence_protocol`
package, so it would be always up to date with the latest Valence
Minecraft protocol implementation.
The MVP version is going to be able concurrently connect headless
clients to a target Minecraft server.
## Test Plan
<!-- Explain how you tested your changes, and include any code that you
used to test this. -->
<!-- If there is an example that is sufficient to use in place of a
playground, replace the playground section with a note that indicates
this. -->
<!-- <details>
<summary>Playground</summary>
```rust
PASTE YOUR PLAYGROUND CODE HERE
```
</details> -->
<!-- You need to include steps regardless of whether or not you are
using a playground. -->
Steps:
1. Ensure that the connection mode is offline
2. Run `cargo run --example bench_players` or any other example
3. Run `cargo run --package valence_stresser -- --target 127.0.0.1:25565
--count 1000`
4. Monitor the `bench_players` output
#### Related
closes#211
---------
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->
## Description
<!-- Describe the changes you've made. You may include any justification
you want here. -->
Dropping items is heavily coupled to inventories. Clients also predict
state changes when they try to drop items, so we need to be able to
replicate that change in order to stay in sync.
This will also remove `DropItem` events in favor of just `DropItemStack`
events. Having 2 event streams that basically mean the same thing seems
verbose and error prone.
As of right now, these changes require the event loop to have a
reference to the client's inventory. This seems like something we are
going to need to do a lot more of to complete #199.
## Test Plan
<!-- Explain how you tested your changes, and include any code that you
used to test this. -->
<!-- If there is an example that is sufficient to use in place of a
playground, replace the playground section with a note that indicates
this. -->
<details>
<summary>Playground</summary>
```rust
use tracing::info;
use valence::client::despawn_disconnected_clients;
use valence::client::event::{default_event_handler, DropItemStack};
use valence::prelude::*;
#[allow(unused_imports)]
use crate::extras::*;
const SPAWN_Y: i32 = 64;
pub fn build_app(app: &mut App) {
app.add_plugin(ServerPlugin::new(()).with_connection_mode(ConnectionMode::Offline))
.add_system_to_stage(EventLoop, default_event_handler)
.add_startup_system(setup)
.add_system(init_clients)
.add_system(despawn_disconnected_clients)
.add_system(toggle_gamemode_on_sneak)
.add_system(drop_items);
}
fn setup(world: &mut World) {
let mut instance = world
.resource::<Server>()
.new_instance(DimensionId::default());
for z in -5..5 {
for x in -5..5 {
instance.insert_chunk([x, z], Chunk::default());
}
}
for z in -25..25 {
for x in -25..25 {
instance.set_block([x, SPAWN_Y, z], BlockState::GRASS_BLOCK);
}
}
world.spawn(instance);
}
fn init_clients(
mut clients: Query<&mut Client, Added<Client>>,
instances: Query<Entity, With<Instance>>,
) {
let instance = instances.get_single().unwrap();
for mut client in &mut clients {
client.set_position([0.5, SPAWN_Y as f64 + 1.0, 0.5]);
client.set_instance(instance);
client.set_game_mode(GameMode::Creative);
}
}
fn drop_items(clients: Query<&Client>, mut drop_stack_events: EventReader<DropItemStack>) {
if drop_stack_events.is_empty() {
return;
}
for event in drop_stack_events.iter() {
info!("drop stack: {:?}", event);
}
}
```
</details>
<!-- You need to include steps regardless of whether or not you are
using a playground. -->
Steps:
1. `cargo test -p valence --tests`
2. Run playground `cargo run -p playground`
3. Open creative menu
4. Pick an item and click to drop it outside of the creative menu
5. Pick an entire stack of an item, place it in your hotbar
6. Hover over the item, press your drop key to drop an item from the
stack
7. Press shift to switch to survival
8. Select the item stack in your hotbar, press your drop key to drop an
item from the stack
9. Open your inventory, grab the stack, hover outside the window and
click to drop the entire stack
10. Grab another stack from creative, place it in your hotbar
11. switch back to survival, select the stack, and press your control +
drop key to drop the entire stack
12. For each item you dropped, you should see a log message with the
event
#### Related
<!-- Link to any issues that have context for this or that this PR
fixes. -->
This is my first time contributing here so I was pretty unfamiliar with
the codebase and may have done some things incorrectly.
## Description
- Added a sound extractor to extract sound event ids and identifiers
- Added a `Sound` enum (with a build script) to represent sound effects
- Added a `play_sound` method to `Instance` and `Client`
- Re-implemented sound effects in the parkour example
## Test Plan
I tested this using the sounds I added to the parkour example.
#### Related
Hopefully fixes#206
## Description
Add the ping computation system and capability to send ping to
connecting clients.
Currently the player list will only update upon connection. Should
another ticket be made for updating this since it seems out of scope for
this issue?
## Test Plan
Printing ping per keepalive packet on a different computer on my
network. It seems to work fine but would need extra feedback.
#### Related
#207
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->
## Description
<!-- Describe the changes you've made. You may include any justification
you want here. -->
I've used the popular `owo-colors` library to colourise the output of
the `packet_inspector`.
This makes it a lot easier to see who's sending what for debugging
purposes.
In future, I'd like to be able to filter out common, low-information
packets like `SetPlayerPosition` and `KeepAlive` as well, but that's not
in this PR.
![image](https://user-images.githubusercontent.com/28905212/218880818-69c0461c-bd23-45c4-9fd4-7c5868be4b67.png)
## Test Plan
No tests - just eyeball 😄.
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->
## Description
<!-- Describe the changes you've made. You may include any justification
you want here. -->
Added a quick and dirty bounds check because we haven't created drop
item/itemstack event(s) yet.
## Test Plan
<!-- Explain how you tested your changes, and include any code that you
used to test this. -->
<!-- If there is an example that is sufficient to use in place of a
playground, replace the playground section with a note that indicates
this. -->
use the `building` example
<!-- You need to include steps regardless of whether or not you are
using a playground. -->
Steps:
1. `cargo run --example building`
2. open inventory
3. pick an item
4. drop the item outside of the inventory window
5. see that the server does not panic
#### Related
<!-- Link to any issues that have context for this or that this PR
fixes. -->
fixes#233
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#69Closes#179Closes#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>
- Extends `Text`'s `Deserialize` impl to allow for deserializing JSON
data types other than objects.
- Add additional `From` impls for `Text`.
- Better `Debug` impl for `Text`.
- Tweaked text unit tests.
Adds `tracing` to `valence_protocol` so we can log debug info about
partially decoded packets. `packet_inspector` has been set to print log
messages at the debug level.