Skip to content

Commit

Permalink
Fix combat example (#629)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #628

# Solution

- In `init_client()`, I inserted the `CombatState` component into the
player
  • Loading branch information
Cheezer1656 authored Sep 2, 2024
1 parent d0f251e commit 7d1c427
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -76,6 +76,7 @@ fn setup(
fn init_clients(
mut clients: Query<
(
Entity,
&mut EntityLayerId,
&mut VisibleChunkLayer,
&mut VisibleEntityLayers,
Expand All @@ -85,8 +86,10 @@ fn init_clients(
Added<Client>,
>,
layers: Query<Entity, (With<ChunkLayer>, With<EntityLayer>)>,
mut commands: Commands,
) {
for (
entity,
mut layer_id,
mut visible_chunk_layer,
mut visible_entity_layers,
Expand All @@ -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());
}
}

Expand Down

0 comments on commit 7d1c427

Please sign in to comment.