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>
This commit is contained in:
Guac 2023-03-11 02:41:48 -08:00 committed by GitHub
parent 104fbedf4c
commit 8bd20e964e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,16 +7,13 @@ pub struct ScoreboardPlayerUpdateS2c<'a> {
pub action: Action<'a>, pub action: Action<'a>,
} }
// TODO: this looks wrong.
#[derive(Clone, PartialEq, Debug, Encode, Decode)] #[derive(Clone, PartialEq, Debug, Encode, Decode)]
pub enum Action<'a> { pub enum Action<'a> {
Create {
objective_value: &'a str,
objective_type: VarInt,
},
Remove,
Update { Update {
objective_value: &'a str, objective_name: &'a str,
objective_type: VarInt, objective_score: VarInt,
},
Remove {
objective_name: &'a str,
}, },
} }