From 7d1c42732b74df1692a276da110bd028aaabaa63 Mon Sep 17 00:00:00 2001 From: Cheezer1656 <118921295+Cheezer1656@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:50:01 -0700 Subject: [PATCH] Fix combat example (#629) # Objective - Fixes #628 # Solution - In `init_client()`, I inserted the `CombatState` component into the player --- examples/combat.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/combat.rs b/examples/combat.rs index 870f662ad..57418b424 100644 --- a/examples/combat.rs +++ b/examples/combat.rs @@ -10,7 +10,7 @@ const SPAWN_Y: i32 = 64; const ARENA_RADIUS: i32 = 32; /// Attached to every client. -#[derive(Component)] +#[derive(Component, Default)] struct CombatState { /// The tick the client was last attacked. last_attacked_tick: i64, @@ -76,6 +76,7 @@ fn setup( fn init_clients( mut clients: Query< ( + Entity, &mut EntityLayerId, &mut VisibleChunkLayer, &mut VisibleEntityLayers, @@ -85,8 +86,10 @@ fn init_clients( Added, >, layers: Query, With)>, + mut commands: Commands, ) { for ( + entity, mut layer_id, mut visible_chunk_layer, mut visible_entity_layers, @@ -101,6 +104,8 @@ fn init_clients( visible_entity_layers.0.insert(layer); pos.set([0.0, f64::from(SPAWN_Y) + 1.0, 0.0]); *game_mode = GameMode::Creative; + + commands.entity(entity).insert(CombatState::default()); } }