Commit graph

403 commits

Author SHA1 Message Date
Ryan Johnson 598abc22f9
Mention GitHub Discussions in README.md 2023-05-25 04:29:17 -07:00
Ryan Johnson b466a8ed8d
Mention GitHub Discussions in CONTRIBUTING.md 2023-05-25 04:24:50 -07:00
Carson McManus 67dced53e0
update aes and cfb8 to 0.8 (#340)
- update aes and cfb8 and make it compile
- update some usages to fix lints
- fix it so that it actually works
- small refactor
- fix lint

## Description

This updates the aes and cfb8 dependencies to 0.8

fixes #42
2023-05-24 09:18:04 -07:00
Ryan Johnson ad1f5d1b4c
Remove "test plan" from pull request template (#336)
## Description

Remove the "test plan" section from the pull request template. My
justification is:
- The steps needed to test a pull request is usually obvious.
- Often the test plan is just "run `cargo test` lol"
- For small changes and tweaks, a "test plan" is overkill and amounts to
frustrating busywork.
- Adds too much additional friction for new contributors.
- Large projects like Bevy are fine without it.
- Often not applicable to pull requests (like this one).
2023-05-23 08:45:15 -04:00
Ryan Johnson 6d1a29daa4
Update CONTRIBUTING.md (#339)
## Description

Tweak a few sentences and add a new section about specifying
dependencies.
2023-05-23 08:43:06 -04:00
Ben 81044440dd
Use a struct to store block collision shapes (#334)
## Description

Created a new CollisionShape struct for blocks (was previously an [f64;
6]).

## Test Plan

Explain the steps necessary to test your changes. If you used a
playground, include the code in the details below.

Steps:
1. Run the following code

<details>

<summary>Playground</summary>

```rust
use valence_block;

fn main() {
    let shapes = valence_block::BlockState::STONE.collision_shapes();
    println!("{:?}", shapes.collect::<Vec<_>>());
    // [CollisionShape { min_x: 0.0, min_y: 0.0, min_z: 0.0, max_x: 1.0, max_y: 1.0, max_z: 1.0 }]
    let shapes = valence_block::BlockState::OAK_STAIRS.collision_shapes();
    println!("{:?}", shapes.collect::<Vec<_>>());
    // [CollisionShape { min_x: 0.0, min_y: 0.0, min_z: 0.0, max_x: 1.0, max_y: 0.5, max_z: 1.0 }, CollisionShape { min_x: 0.0, min_y: 0.5, min_z: 0.0, max_x: 1.0, max_y: 1.0, max_z: 0.5 }]
}
```

</details>
2023-05-22 01:29:59 -07:00
Jenya705 8897eeacb9
Hitboxes (#330)
## Description

Added Hitbox component, a crate for it and systems which update
hitboxes.
Issue: https://github.com/valence-rs/valence/issues/299

## Test Plan

Use example "entity_hitbox"
2023-05-08 17:34:33 -07:00
Jenya705 161d523018
Advancement's reset flag (#331)
## Description

Added a new reset flag, which resets all old advancements and don't show
a toast for already completed advancements

## Test Plan

Use example "advancements". Now it saves old progress of player
2023-05-06 19:54:34 -07:00
Jenya705 41bcd1eb2c
Advancement api (#329)
## Description

Did an api for advancements.
Issue: https://github.com/valence-rs/valence/issues/325

Each advancement is an entity, it's children is either criteria, either
advancement.
Root advancement has no parent.

Also did an event AdvancementTabChange (listens if client changes
advancement's tab)

## Test Plan

Use an example "advancements"
2023-05-02 01:35:35 -07:00
AviiNL 1d2d8f888e
New ci (#328)
## Description

Completely re-written the ci build script for more parallelization and
speed.

## Test Plan

1. make/merge a pr
2. watch ci go wroom
3. ?
4. profit
2023-04-28 18:06:05 -07:00
AviiNL d3ed3123ca
Temp fix for heck with unicode enabled (#326)
## Description

This should _temporarily_ fix the heck issue described in #324 until
https://github.com/withoutboats/heck/issues/42 is fixed downstream.

When it is fixed downstream, this commit should get reverted.

Fixes #324
2023-04-28 11:53:10 +00:00
Ryan Johnson abf9064901
Add idle tick benchmark (#322)
## Description

Adds a benchmark to measure the duration of a whole server tick.

Also added `bevy_ecs` to `valence::prelude`.

## Test Plan

Steps:
1. `cargo bench idle_update`
2023-04-23 03:35:07 +00:00
Ryan Johnson 1da1a589f1
Create README.md for crates/ 2023-04-21 18:13:54 -07:00
Ryan Johnson eaf1e18610
Reorganize Project (#321)
## Description

- `valence` and `valence_protocol` have been divided into smaller crates
in order to parallelize the build and improve IDE responsiveness. In the
process, code architecture has been made clearer by removing circular
dependencies between modules. `valence` is now just a shell around the
other crates.
- `workspace.packages` and `workspace.dependencies` are now used. This
makes dependency managements and crate configuration much easier.
- `valence_protocol` is no more. Most things from `valence_protocol`
ended up in `valence_core`. We won't advertise `valence_core` as a
general-purpose protocol library since it contains too much
valence-specific stuff. Closes #308.
- Networking code (login, initial TCP connection handling, etc.) has
been extracted into the `valence_network` crate. The API has been
expanded and improved with better defaults. Player counts and initial
connections to the server are now tracked separately. Player counts
function by default without any user configuration.
- Some crates like `valence_anvil`, `valence_network`,
`valence_player_list`, `valence_inventory`, etc. are now optional. They
can be enabled/disabled with feature flags and `DefaultPlugins` just
like bevy.
- Whole-server unit tests have been moved to `valence/src/tests` in
order to avoid [cyclic
dev-dependencies](https://github.com/rust-lang/cargo/issues/4242).
- Tools like `valence_stresser` and `packet_inspector` have been moved
to a new `tools` directory. Renamed `valence_stresser` to `stresser`.
Closes #241.
- Moved all benches to `valence/benches/` to make them easier to run and
organize.

Ignoring transitive dependencies and `valence_core`, here's what the
dependency graph looks like now:

```mermaid
graph TD
	network --> client
	client --> instance
	biome --> registry
	dimension --> registry
	instance --> biome
	instance --> dimension
	instance --> entity
	player_list --> client
	inventory --> client
	anvil --> instance
	entity --> block
```

### Issues
- Inventory tests inspect many private implementation details of the
inventory module, forcing us to mark things as `pub` and
`#[doc(hidden)]`. It would be ideal if the tests only looked at
observable behavior.
- Consider moving packets in `valence_core` elsewhere. `Particle` wants
to use `BlockState`, but that's defined in `valence_block`, so we can't
use it without causing cycles.
- Unsure what exactly should go in `valence::prelude`.
- This could use some more tests of course, but I'm holding off on that
until I'm confident this is the direction we want to take things.

## TODOs
- [x] Update examples.
- [x] Update benches.
- [x] Update main README.
- [x] Add short READMEs to crates.
- [x] Test new schedule to ensure behavior is the same. 
- [x] Update tools.
- [x] Copy lints to all crates.
- [x] Fix docs, clippy, etc.
2023-04-21 14:43:59 -07:00
Sese Mueller 1db779136c
Fixed Panic when dropping item from inventory while chest is open #295 (#320)
## Description

Fixed #295 by checking the slot ids of the drop event and only updating
the player inventory/the target inventory accordingly.

## Test Plan
Steps:
1. Rerun the test from #295, it works
2. Test other inventories in game
...

(No details, it only uses the chest example.)

---------

Co-authored-by: Sese Mueller <sese4dasbinichagmail.com>
2023-04-18 21:08:13 +00:00
Ryan Johnson 58a3fbf6a3
Update example showcase video in README.md
Video courtesy of @emortaldev.
2023-04-12 22:59:55 -07:00
Ryan Johnson f2bf1d97dc
Fix player bugs (#318)
## Description

- Make sure player list packets get sent before player entity spawn
packets are sent to prevent invisible players.
- Correctly update pose and hand swing.

## Test Plan

Steps:
1. Load any example with two players.
2. See that players are visible.
3. See that crouching and hand swings are functioning.
2023-04-10 10:15:27 +00:00
Ryan Johnson d78627e478
Player list rework (#317)
## Description

- Redesigned the player list so that every entry is an entity in the
ECS. Entry components overlap with client components where possible.
- Clients are now automatically added and removed from the player list
unless configured not to.
- Updated player list example.

## Test Plan

Steps:
1. Run any of the examples.
2. Run player list example.
2023-04-10 01:40:03 -07:00
Bafbi a68792e605
Registry codec extractor (#316)
## Description

- #311 .
- Update the script to cp all the file of the output dir .

## Change to the gradle project

- Adding the fabric API .
- The serveur now need to start starting .

## Test plan

Do the same as before and compare the 1.9.4 output file and my generated
one .

---------

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2023-04-10 01:39:03 -07:00
Ryan Johnson 11ba70586e
Decoupled Packet Handlers (#315)
## Description

Closes #296 

- Redesigned the packet decoder to return packet _frames_ which are just
the packet ID + data in raw form.
- Made packet frame decoding happen in the client's tokio task. This has
a few advantages:
- Packet frame decoding (decompression + decryption + more) can happen
in parallel.
- Because packets are parsed as soon as they arrive, an accurate
timestamp can be included with the packet. This enables us to implement
client ping calculation accurately.
- `PacketEvent`s are now sent in the event loop instead of a giant match
on the serverbound packets. This is good because:
- Packets can now be handled from completely decoupled systems by
reading `PacketEvent` events.
- The entire packet is available in binary form to users, so we don't
need to worry about losing information when transforming packets to
events. I.e. an escape hatch is always available.
  - The separate packet handlers can run in parallel thanks to bevy_ecs.
- The inventory packet handler systems have been unified and moved
completely to the inventory module. This also fixed some issues where
certain inventory events could _only_ be handled one tick late.
- Reorganized the client module and moved things into submodules.
- The "default event handler" has been removed in favor of making
clients a superset of `PlayerEntityBundle`. It is no longer necessary to
insert `PlayerEntityBundle` when clients join. This does mean you can't
insert other entity types on the client, but that design doesn't work
for a variety of reasons. We will need an "entity visibility" system
later anyway.

## Test Plan

Steps:
1. Run examples and tests.
2023-04-08 19:55:31 +00:00
Ryan Johnson 1c405ab63c
Reimplement client self-exclusion (#314)
## Description

Stops packets for the client's own entity being sent back to the client.
This prevents the "ghost player" from appearing at spawn.

## Test Plan

Steps:
1. `cargo r --example bench_players`
2. Press F3
3. Look at where the player spawned. Notice that there is no ghost
player entity.
4. Look at received packets `rx`. Moving around in a chunk, you will not
receive packets for the player's own entity. `rx` should be close to
zero.
2023-04-05 17:56:30 -07:00
vytskalt cd8a9266ef
Update particles for 1.19.4 (#313)
## Description

Updated the Particle enum for 1.19.4

## Test Plan

Steps:
1. Run the particles.rs example

---------

Co-authored-by: Ryan <ryanj00a@gmail.com>
2023-04-02 13:22:23 -07:00
Ryan Johnson 9c9f672a22
Update to 1.19.4 (#302)
## Description

Closes #291

- Update extractors to support Minecraft 1.19.4
- Update code generators.
- Changed generated entity component names to avoid name collisions.
- Update `glam` version.
- Added `Encode` and `Decode` for `glam` types in `valence_protocol`.
- Fixed inconsistent packet names and assign packet IDs automatically.
- Remove `ident` and rename `ident_str` to `ident`.
- Rework registry codec configuration. Biomes and dimensions exist as
entities.`BiomeRegistry` and `DimensionTypeRegistry` resources have been
added. The vanilla registry codec is loaded at startup.

### Issues
- Creating new instances has become more tedious than it should be. This
will be addressed later.

## Test Plan

Steps:
1. Boot up a vanilla server with online mode disabled.
2. Run the `packet_inspector`.
3. Connect to the vanilla server through the packet inspector to ensure
all packets are updated correctly.
4. Close the vanilla server and try some valence examples.
2023-03-31 14:58:47 -07:00
Ryan Johnson 53573642ec
Make Ident consistent with vanilla. (#309)
## Description

Makes `Ident` consistent with vanilla by prepending the default
namespace if none is provided in the constructor.

Previously, the constructor did not normalize `foo` to `minecraft:foo`.
This could lead to subtle bugs when the ident is eventually unwrapped
with `Ident::as_str`. (comparing `foo` with `minecraft:foo` while inside
the `Ident` was still handled correctly).

## Test Plan

Steps:
1. `cargo test`
2023-03-25 18:44:45 -07:00
Carson McManus ba625b3217
don't increment state_id when the server modifies cursor item (#306)
## Description

The client actually doesn't acknowledge the state id update when you
modify the cursor item, so don't increment it so we stay in sync.

fixes #304

## Test Plan

Explain the steps necessary to test your changes. If you used a
playground, include the code in the details below.

Steps:
1. Run the playground from #304 (not included here for brevity)
2. open inventory (not chest)
3. pick up one of the stacks
4. see that you don't get resynced, and the apples stay in your cursor
2023-03-24 08:46:05 -07:00
Carson McManus a57800959f
Rough click slot packet validation (#293)
## Description

This adds some validation for incoming inventory packets that makes it
so that you can't just spawn items by sending malicious packets. It adds
type 1 and type 2 validations as outlined in #292.

This also adds some new helpers, `InventoryWindow` and
`InventoryWindowMut`.

fixes #292

<details>

<summary>Playground</summary>

```rust
use valence::client::{default_event_handler, despawn_disconnected_clients};
use valence::prelude::event::PlayerInteractBlock;
use valence::prelude::*;

#[allow(unused_imports)]
use crate::extras::*;

const SPAWN_Y: i32 = 64;
const CHEST_POS: [i32; 3] = [0, SPAWN_Y + 1, 3];

pub fn build_app(app: &mut App) {
    app.add_plugin(ServerPlugin::new(()).with_connection_mode(ConnectionMode::Offline))
        .add_startup_system(setup)
        .add_system(default_event_handler.in_schedule(EventLoopSchedule))
        .add_system(init_clients)
        .add_system(despawn_disconnected_clients)
        .add_systems((toggle_gamemode_on_sneak, open_chest).in_schedule(EventLoopSchedule));
}

fn setup(mut commands: Commands, server: Res<Server>) {
    let mut instance = 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);
        }
    }
    instance.set_block(CHEST_POS, BlockState::CHEST);

    commands.spawn(instance);

    let mut inventory = Inventory::new(InventoryKind::Generic9x3);
    inventory.set_slot(0, ItemStack::new(ItemKind::Apple, 100, None));
    inventory.set_slot(1, ItemStack::new(ItemKind::Diamond, 40, None));
    inventory.set_slot(2, ItemStack::new(ItemKind::Diamond, 30, None));
    commands.spawn(inventory);
}

fn init_clients(
    mut clients: Query<(&mut Position, &mut Location, &mut Inventory), Added<Client>>,
    instances: Query<Entity, With<Instance>>,
) {
    for (mut pos, mut loc, mut inv) in &mut clients {
        pos.0 = [0.5, SPAWN_Y as f64 + 1.0, 0.5].into();
        loc.0 = instances.single();

        inv.set_slot(24, ItemStack::new(ItemKind::Apple, 100, None));
        inv.set_slot(25, ItemStack::new(ItemKind::Apple, 10, None));
    }
}

// Add new systems here!

fn open_chest(
    mut commands: Commands,
    inventories: Query<Entity, (With<Inventory>, Without<Client>)>,
    mut events: EventReader<PlayerInteractBlock>,
) {
    let Ok(inventory) = inventories.get_single() else {
        return;
    };

    for event in events.iter() {
        if event.position != CHEST_POS.into() {
            continue;
        }
        let open_inventory = OpenInventory::new(inventory);
        commands.entity(event.client).insert(open_inventory);
    }
}

```

</details>

## Test Plan

Steps:
1. `cargo test`

---------

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2023-03-24 05:53:32 -07:00
Ryan Johnson 8d93ddee24
Revise examples guideline and remove some examples. (#301)
# Description

- Removed the advice about making examples as small as possible in
CONTRIBUTING.md
- Remove a couple of low-value examples. I would like to remove more,
but their functionality would have to be covered by better examples
first.

My reasons are:
- Examples are tedious to update and maintain. Boilerplate is
inevitable.
- The "Boilerplate to code" ratio is higher when examples are smaller.
- Examples are likely the first thing that new users will try out, so we
ought to make a good first impression by showing something substantial.
- Complicated examples are better for showing how to use Valence in
practice and serve as a useful reference.
- Lots of small examples can distract from the more impressive ones.
Tiny examples don't add much value.
2023-03-23 06:54:07 -07:00
Ryan Johnson 1aae22ca3e
dump_schedule utility (#300)
## Description

Adds the `dump_schedule` crate which is a simple tool that writes
valence's schedule graph to a file named ~~`graph.gv`~~ `graph.svg`.

## Test Plan

Steps:
1. `cargo r -p dump_schedule`
2. Paste the contents of `graph.gv` to https://edotor.net/
3. Look at the pretty graph.
2023-03-23 01:01:50 -07:00
AviiNL 628a0ff3c3
fix key input with filters, also removed regex from gui and make text… (#298)
… filters case-insensitive

Closes #297

## Description

Up and down arrow to select previous/next packet now ignore filtered
packets.

## Test Plan

1. Query the server using refresh on the server browser
2. Uncheck QueryResponseS2c in the packet-selector list
3. Click HandshakeC2s
4. Press down arrow until last packet is selected
5. It shouldn't go "blank" anymore when going from QueryRequestC2s to
QueryPingC2s

As an additive request, I've removed the regex check from the main GUI
filter box, such that this is now case-insensitive when filtering
specific packets.
CLI still uses regex to be able to filter on multiple packets
(unchanged)
2023-03-21 23:49:44 -07:00
Ryan Johnson 4cf6e1a207
Entity Rework (#294)
## Description

Closes #269
Closes #199 

- Removes `McEntity` and replaces it with bundles of components, one for
each entity type.
- Tracked data types are now separate components rather than stuffing
everything into a `TrackedData` enum.
- Tracked data is now cached in binary form within each entity,
eliminating some work when entities enter the view of clients.
- Complete redesign of entity code generator.
- More docs for some components.
- Field bits are moved out of the entity extractor and into the valence
entity module.
- Moved hitbox code to separate module.
- Refactor instance update systems to improve parallelism.

### TODOs
- [x] Update examples.
- [x] Update `default_event_handler`.
- [x] Fix bugs.

## Test Plan

Steps:
1. Check out the entity module docs with `cargo d --open`.
2. Run examples.
2023-03-21 23:29:38 -07:00
qualterz c9fbd1a24e
Weather implementation (#260)
<!-- 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 basic weather systems.

The weather component attached to a world instance would be handled for
all clients, except those that have their own weather component; these
clients would be handled separately.

## 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
fn handle_command_events(
    instances: Query<Entity, With<Instance>>,
    mut exec_cmds: EventReader<CommandExecution>,
    mut commands: Commands,
) {
    for cmd in exec_cmds.iter() {
        let msg = cmd.command.to_string();
        let ent = instances.single();

        match msg.as_str() {
            "ar" => {
                commands.entity(ent).insert(Rain(WEATHER_LEVEL.end));
            }
            "rr" => {
                commands.entity(ent).remove::<Rain>();
            }
            "at" => {
                commands.entity(ent).insert(Thunder(WEATHER_LEVEL.end));
            }
            "rt" => {
                commands.entity(ent).remove::<Thunder>();
            }
            _ => (),
        };
    }
}
```

</details>

<!-- You need to include steps regardless of whether or not you are
using a playground. -->
Steps:
1. Run `cargo test --package valence --lib -- weather::test`

#### Related
Part of #210
Past approach #106

<!-- Link to any issues that have context for this or that this PR
fixes. -->
2023-03-16 08:43:26 -04:00
Ryan Johnson 2c0fb2d8c4
Refactor Schedule (#289)
## Description

- Tweak the system schedule to be more parallel-friendly and explicit.
Dependencies between systems is clearer.
- System and resource configuration is better encapsulated in each
module by using plugins.

The schedule graph for `Main` now looks like this (using
`bevy_mod_debugdump`):


![graph](https://user-images.githubusercontent.com/31678482/225321113-0ec4f4dd-86f6-45fe-8158-12a451536770.svg)

### Unresolved

- What to do about ambiguous systems? Many systems here are ambiguous
because they take `&mut Client`, but the order they write packets isn't
really important. Marking them as ambiguous explicitly with
`.ambiguous_with*` across module boundaries seems difficult and
cumbersome.

## Test Plan

Steps:
1. Run examples. Check that I didn't screw up the system order.
2023-03-15 16:12:59 -07:00
Joe Sorensen 255b78e02c
tiny one line change to fix writing packets not working (#290)
## Description

With component division, the WritePacket trait was pub(crate), which
disallowed writing packets outside of valence. This 1 line PR fixes
that.

## Test Plan

It might be a good idea to include examples/tests that use packet
writing to catch this, but it's most likely not strictly necessary.
2023-03-15 07:36:55 -07:00
AviiNL 68cf6e83a0
Abstract scoreboard display position (#286)
## Description

The scoreboard display packet has a position field that can contain one
of the following:
- 0: List
- 1: Sidebar
- 2: BelowName
- 3..=18: Team specific sidebar indexed as 3 + team color (according to
wiki.vg)

I'm not really sure how team specific sidebars are supposed to work, so
left that as a byte, maybe that can have some more abstraction?

## Test Plan

<details>

<summary>Playground</summary>

```rust
use valence::client::despawn_disconnected_clients;
use valence::client::event::default_event_handler;
use valence::prelude::*;
use valence::protocol::packet::s2c::play::scoreboard_display::ScoreboardPosition;
use valence::protocol::packet::s2c::play::scoreboard_objective_update::{Mode, RenderType};
use valence::protocol::packet::s2c::play::scoreboard_player_update::Action;
use valence::protocol::packet::s2c::play::{
    ScoreboardDisplayS2c, ScoreboardObjectiveUpdateS2c, ScoreboardPlayerUpdateS2c,
};
use valence::protocol::var_int::VarInt;

const SPAWN_Y: i32 = 64;

pub fn build_app(app: &mut App) {
    app.add_plugin(ServerPlugin::new(()))
        .add_system(default_event_handler.in_schedule(EventLoopSchedule))
        .add_startup_system(setup)
        .add_system(init_clients)
        .add_system(scoreboard)
        .add_system(despawn_disconnected_clients)
        .add_systems(PlayerList::default_systems());
}

fn setup(mut commands: Commands, server: Res<Server>) {
    let mut instance = 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);
        }
    }

    commands.spawn(instance);
}

fn init_clients(
    mut clients: Query<&mut Client, Added<Client>>,
    instances: Query<Entity, With<Instance>>,
) {
    for mut client in &mut clients {
        client.set_position([0.0, SPAWN_Y as f64 + 1.0, 0.0]);
        client.set_instance(instances.single());
        client.set_game_mode(GameMode::Creative);
    }
}

// Add new systems here!
fn scoreboard(mut clients: Query<&mut Client, Added<Client>>) {
    for mut client in &mut clients {
        client.write_packet(&ScoreboardObjectiveUpdateS2c {
            objective_name: "sidebar",
            mode: Mode::Create {
                objective_display_name: "Sidebar".into_text(),
                render_type: RenderType::Integer,
            },
        });
        client.write_packet(&ScoreboardPlayerUpdateS2c {
            action: Action::Update {
                objective_score: VarInt(42),
                objective_name: "sidebar",
            },
            entity_name: "name",
        });
        client.write_packet(&ScoreboardDisplayS2c {
            position: ScoreboardPosition::Sidebar, // Position is now an Enum
            score_name: "sidebar",
        });
    }
}
```

</details>

---------

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2023-03-12 04:51:49 -07:00
Ryan Johnson 41907261e3
Update feature_request.md
Removed line break.
2023-03-11 20:07:00 -08:00
Ryan Johnson 5300e6478a
Replace yaml issue templates with markdown templates (#287)
## Description

Replaces the issue forms with the old markdown issue templates. Some
details have changed too.

I've found the issue forms to be inflexible and the interface a bit
clunky. We can switch back if the situation improves.
2023-03-11 20:04:46 -08:00
Ryan Johnson b46cc502aa
Client Component Division (#266)
## Description

Divides the `Client` component into a set of smaller components as
described by #199 (with many deviations). `McEntity` will be dealt with
in a future PR.

- Divide `Client` into smaller components (There's a lot to look at).
- Move common components to `component` module.
- Remove `Username` type from `valence_protocol` because the added
complexity wasn't adding much benefit.
- Clean up the inventory module.

I've stopped worrying about the "Effect When Added" and "Effect When
Removed" behavior of components so much, and instead assume that all
components of a particular thing are required unless otherwise stated.

## Test Plan

Steps:
1. Run examples and tests.

A large number of tweaks have been made to the inventory module. I tried
to preserve semantics but I could have made a mistake there.

---------

Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
Co-authored-by: Carson McManus <carson.mcmanus1@gmail.com>
2023-03-11 06:04:14 -08:00
Guac 8bd20e964e
Fix ScoreboardPlayerUpdate packet (#285)
## Description

Fix the contents of the `ScoreboardPlayerUpdateS2c` packet resolving
#284.

## Test Plan

Run the included playground code.

<details>

<summary>Playground</summary>

```rust
use valence::client::despawn_disconnected_clients;
use valence::client::event::default_event_handler;
use valence::prelude::*;
use valence::protocol::packet::s2c::play::scoreboard_objective_update::{Mode, RenderType};
use valence::protocol::packet::s2c::play::scoreboard_player_update::Action;
use valence::protocol::packet::s2c::play::{
    ScoreboardObjectiveUpdateS2c, ScoreboardPlayerUpdateS2c,
};
use valence::protocol::var_int::VarInt;

pub fn build_app(app: &mut App) {
    app.add_plugin(ServerPlugin::new(()))
        .add_system(default_event_handler.in_schedule(EventLoopSchedule))
        .add_startup_system(setup)
        .add_system(init_clients)
        .add_system(scoreboard)
        .add_system(despawn_disconnected_clients);
}

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());
        }
    }

    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_instance(instance);
    }
}

// Add new systems here!
fn scoreboard(mut clients: Query<&mut Client, Added<Client>>) {
    for mut client in &mut clients {
        client.write_packet(&ScoreboardObjectiveUpdateS2c {
            objective_name: "test",
            mode: Mode::Create {
                objective_display_name: "test display".into_text(),
                render_type: RenderType::Integer,
            },
        });
        client.write_packet(&ScoreboardPlayerUpdateS2c {
            action: Action::Update {
                objective_score: VarInt(0),
                objective_name: "test",
            },
            entity_name: "name",
        });
        client.write_packet(&ScoreboardPlayerUpdateS2c {
            action: Action::Remove {
                objective_name: "test",
            },
            entity_name: "name",
        });
    }
}

```

</details>
2023-03-11 02:41:48 -08:00
AviiNL 104fbedf4c
Packet inspector updates (#283)
## Description

Updated packet inspector to have a more clear indication of which packet
is selected, and added up and down keybinds for selecting previous and
next packet respectively
2023-03-10 03:57:55 -08:00
AviiNL cd7dd8cc4c
Fix Particle packet id (#281)
Fixes #267

## Description

Swap packet ids `ParticleS2c` with `LightUpdateS2c`

## Test Plan

Steps:
1. Run the `particles.rs` example
2023-03-09 04:02:03 -08:00
AviiNL 491e3a61d7
Packet inspector gui (#238)
Fixes #235

## Description

A GUI Project for the packet inspector

## Test Plan

Steps:
1. Start (any) server
2. Start the proxy `cargo r -r -p packet_inspector_gui --
127.0.0.1:25560 127.0.0.1:25565`
3. Join server (127.0.0.1:25560)
4. Magic
2023-03-09 03:09:53 -08:00
AviiNL 52fadb6dd8
Rename valence_protocol to valence::protocol (#280)
## Description

Replaced the remaining `valence_protcol` with `valence::protocol` in the
examples
2023-03-09 03:08:31 -08:00
wjwzpeajhc 7cd483afb7
Replaced valence_protocol and valence_nbt imports with valence ones (#279)
## Description

This PR replace `valence_protocol` and `valence_nbt` imports in
`crates/valence/examples` with `valence` ones so you don't have to
change imports or import the crates when you copy the examples and have
only `valence` as a dependency.
2023-03-08 14:18:56 -08:00
AviiNL 4c0f070d27
Add caching layer to CI (#277)
Added a caching layer to the CI

This creates a cache on first run (should exist because of this pr now)
The hash is calculated from the Cargo.toml files (recursively if i've
done it correctly)
So whenever a Cargo.toml file changes, it invalidates the cache.

Local crates are _not_ cached, so they get recompiled regardless, but it
already shaves off like half the total time from the action runners.
2023-03-08 11:51:47 -05:00
Ryan Johnson e933fd69f5
Add RawPacket (#276)
## Description

Adds a `RawPacket` type to `valence_protocol`. This type simply reads
and writes data to a slice, analogous to the `RawBytes` type in the same
module.

## Test Plan

Steps:
1. `cargo t -p valence_protocol`
2023-03-07 20:15:30 -08:00
Ryan Johnson 4a541a907a
Tweak templates (#273)
## Description

Change the issue and pull request templates.

- Remove HTML comments from the markdown because it's often not deleted
and takes up space in the final commit description.
- Remove the "related" section in the PR template because links to other
issues will naturally end up in the "description" section.
- Remove some placeholder text in the feature request template.
- Remove the check boxes from the bug report template to avoid creating
"tasks".
- The number of sections in the bug report template was a bit daunting
IMO so I trimmed it down a bit.

Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
2023-03-07 08:01:30 -05:00
Ryan e49ab70f16 Fix typo in packet_group macro 2023-03-07 04:23:11 -08:00
Ryan Johnson e64f1b7123
Add packet_name (#274)
## Description

Adds `packet_name` method to the `Packet` trait to help with #238.

## Test Plan

Steps:
1. `cargo t -p valence_protocol`
2023-03-07 04:12:08 -08:00
Ryan Johnson a69cc5d1c3
Tweak README.md 2023-03-06 19:48:20 -08:00
Ryan Johnson 7e7af6e7c1
Set bevy version to 0.10 (#272)
## Description

Sets Bevy dependencies to version 0.10 instead of the previous commit
hash.
2023-03-06 18:50:48 -08:00