valence/crates/valence_protocol
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
..
benches Refactor valence_protocol (#253) 2023-02-23 22:16:22 -08:00
build Provide API for getting the wall variant of blocks (#255) 2023-02-23 21:21:27 -08:00
src Fix ScoreboardPlayerUpdate packet (#285) 2023-03-11 02:41:48 -08:00
Cargo.toml ECS Rewrite (#184) 2023-02-11 09:51:53 -08:00