From cdddb2b71f00f9baa4483ce7152e1b363d1e4f82 Mon Sep 17 00:00:00 2001 From: 0xc0001a2040 <38496922+MrGunflame@users.noreply.github.com> Date: Sat, 11 Sep 2021 12:25:09 +0200 Subject: [PATCH 01/21] Fix typo --- docs/architecture.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture.md b/docs/architecture.md index ad65df865..a08833d68 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -78,7 +78,7 @@ The component can then be accessed both from Feather and from plugins. In Feather, events are components. An entity with the `PlayerJoinEvent` component just joined the game, for example. -The event sytsem serves as a mechanism to communicate between different crates and modules. +The event system serves as a mechanism to communicate between different crates and modules. For example, triggering a `BlockChangeEvent` _anywhere_ causes `feather-server` to send block update packets to players. From 9d0a2ce61247bb5cd9503108d64a2b6a0163b06f Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 19:40:48 +0200 Subject: [PATCH 02/21] First Health and Falldamage system --- feather/server/src/client.rs | 34 +++++++++++++- feather/server/src/entities.rs | 6 +++ feather/server/src/packet_handlers.rs | 6 ++- feather/server/src/packet_handlers/health.rs | 27 +++++++++++ feather/server/src/systems.rs | 7 ++- feather/server/src/systems/falldamage.rs | 49 ++++++++++++++++++++ feather/server/src/systems/health.rs | 18 +++++++ quill/common/src/components.rs | 43 +++++++++++++++++ 8 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 feather/server/src/packet_handlers/health.rs create mode 100644 feather/server/src/systems/falldamage.rs create mode 100644 feather/server/src/systems/health.rs diff --git a/feather/server/src/client.rs b/feather/server/src/client.rs index 96cdee503..27ea4fc96 100644 --- a/feather/server/src/client.rs +++ b/feather/server/src/client.rs @@ -15,7 +15,9 @@ use common::{ Window, }; use flume::{Receiver, Sender}; -use packets::server::{Particle, SetSlot, SpawnLivingEntity, UpdateLight, WindowConfirmation}; +use packets::server::{ + Particle, Respawn, SetSlot, SpawnLivingEntity, UpdateHealth, UpdateLight, WindowConfirmation, +}; use protocol::{ packets::{ self, @@ -28,7 +30,7 @@ use protocol::{ }, ClientPlayPacket, Nbt, ProtocolVersion, ServerPlayPacket, Writeable, }; -use quill_common::components::OnGround; +use quill_common::components::{Health, Hunger, OnGround}; use uuid::Uuid; use vec_arena::Arena; @@ -491,6 +493,34 @@ impl Client { }); } + pub fn update_health(&self, player_health: &Health) { + let player_hunger = Hunger::new(); + + self.send_packet(UpdateHealth { + health: player_health.health as f32, + food: player_hunger.food as i32, + food_saturation: player_hunger.saturation as f32, + }); + } + + pub fn respawn_player(&self, gamemode: Gamemode) { + let dimension = nbt::Blob::from_reader(&mut Cursor::new(include_bytes!( + "../../../assets/dimension.nbt" + ))) + .expect("dimenstion asset is malformed"); + + self.send_packet(Respawn { + dimension: Nbt(dimension), + world_name: "world".to_owned(), + hashed_seed: 0, + gamemode, + previous_gamemode: Gamemode::Survival, + is_debug: false, + is_flat: false, + copy_metadata: false, + }); + } + pub fn send_particle(&self, particle: &base::Particle, position: &Position) { self.send_packet(Particle { particle_kind: particle.kind, diff --git a/feather/server/src/entities.rs b/feather/server/src/entities.rs index 25564d149..86f5e493a 100644 --- a/feather/server/src/entities.rs +++ b/feather/server/src/entities.rs @@ -26,6 +26,7 @@ pub fn add_entity_components(builder: &mut EntityBuilder, init: &EntityInit) { builder.add(NetworkId::new()); } builder.add(PreviousPosition(*builder.get::().unwrap())); + builder.add(FallDistance(0.0)); add_spawn_packet(builder, init); } @@ -57,3 +58,8 @@ fn spawn_living_entity(entity: &EntityRef, client: &Client) -> SysResult { client.send_living_entity(network_id, uuid, pos, kind); Ok(()) } + +/// Increasing distance of an entity falling. Used to calculate +/// fall damage for entities with health. +#[derive(Copy, Clone, Debug)] +pub struct FallDistance(pub f64); diff --git a/feather/server/src/packet_handlers.rs b/feather/server/src/packet_handlers.rs index 4a6035037..dc0d2ad9c 100644 --- a/feather/server/src/packet_handlers.rs +++ b/feather/server/src/packet_handlers.rs @@ -17,6 +17,7 @@ use quill_common::components::Name; use crate::{NetworkId, Server}; mod entity_action; +mod health; mod interaction; pub mod inventory; mod movement; @@ -75,10 +76,13 @@ pub fn handle_packet( entity_action::handle_entity_action(game, player_id, packet) } + ClientPlayPacket::ClientStatus(packet) => { + health::handle_client_status(game, server, player_id, packet) + } + ClientPlayPacket::TeleportConfirm(_) | ClientPlayPacket::QueryBlockNbt(_) | ClientPlayPacket::SetDifficulty(_) - | ClientPlayPacket::ClientStatus(_) | ClientPlayPacket::TabComplete(_) | ClientPlayPacket::WindowConfirmation(_) | ClientPlayPacket::ClickWindowButton(_) diff --git a/feather/server/src/packet_handlers/health.rs b/feather/server/src/packet_handlers/health.rs new file mode 100644 index 000000000..281b5bc82 --- /dev/null +++ b/feather/server/src/packet_handlers/health.rs @@ -0,0 +1,27 @@ +use crate::{ClientId, Server}; +use base::Gamemode; +use common::Game; +use ecs::{Entity, SysResult}; +use protocol::packets::client::ClientStatus; + +pub fn handle_client_status( + game: &mut Game, + server: &mut Server, + player_id: Entity, + packet: ClientStatus, +) -> SysResult { + match packet { + ClientStatus::PerformRespawn => { + let client_id = game.ecs.get::(player_id).unwrap(); + let client = server.clients.get(*client_id).unwrap(); + + client.respawn_player(Gamemode::Survival); + + let player = game.ecs.entity(player_id)?; + game.reset_player(player); + } + ClientStatus::RequestStats => {} + } + + Ok(()) +} diff --git a/feather/server/src/systems.rs b/feather/server/src/systems.rs index ee7e85b37..f734febca 100644 --- a/feather/server/src/systems.rs +++ b/feather/server/src/systems.rs @@ -3,6 +3,8 @@ mod block; mod chat; mod entity; +mod falldamage; +mod health; mod particle; mod player_join; mod player_leave; @@ -32,10 +34,13 @@ pub fn register(server: Server, game: &mut Game, systems: &mut SystemExecutor().add_system(tick_clients); } diff --git a/feather/server/src/systems/falldamage.rs b/feather/server/src/systems/falldamage.rs new file mode 100644 index 000000000..62712ce24 --- /dev/null +++ b/feather/server/src/systems/falldamage.rs @@ -0,0 +1,49 @@ +use crate::{ + entities::{FallDistance, PreviousPosition}, + Game, Server, +}; +use base::Position; +use ecs::{SysResult, SystemExecutor}; +use quill_common::components::{Health, OnGround}; + +pub fn register(_: &mut Game, systems: &mut SystemExecutor) { + systems.group::().add_system(calculate_falldamage); +} + +fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { + for (_, (position, prev_position, on_ground, fall_distance, health)) in game + .ecs + .query::<( + &Position, + &PreviousPosition, + &OnGround, + &mut FallDistance, + &mut Health, + )>() + .iter() + { + match on_ground.0 { + false => { + let new_distance = prev_position.0.y - position.y; + + fall_distance.0 += new_distance.abs(); + } + // Apply fall damage. + true => { + let damage = (fall_distance.0.ceil() as u32).saturating_sub(3); + + health.deal_damage(damage); + + #[cfg(debug_assertions)] + if fall_distance.0 > 0.0 { + log::debug!("Entity fell {:?} ({:?} damage)", fall_distance, damage); + } + + // Reset fall distance. + fall_distance.0 = 0.0; + } + } + } + + Ok(()) +} diff --git a/feather/server/src/systems/health.rs b/feather/server/src/systems/health.rs new file mode 100644 index 000000000..d4c6e9763 --- /dev/null +++ b/feather/server/src/systems/health.rs @@ -0,0 +1,18 @@ +use crate::{client::ClientId, Game, Server}; +use ecs::{SysResult, SystemExecutor}; + +use quill_common::components::Health; + +pub fn register(_: &mut Game, systems: &mut SystemExecutor) { + systems.group::().add_system(update_health); +} + +fn update_health(game: &mut Game, server: &mut Server) -> SysResult { + for (_, (client_id, health)) in game.ecs.query::<(&ClientId, &mut Health)>().iter() { + if let Some(client) = server.clients.get(*client_id) { + client.update_health(&health); + } + } + + Ok(()) +} diff --git a/quill/common/src/components.rs b/quill/common/src/components.rs index f7ce6f137..b5c5370ba 100644 --- a/quill/common/src/components.rs +++ b/quill/common/src/components.rs @@ -119,3 +119,46 @@ impl Sprinting { } } bincode_component_impl!(Sprinting); + +/// An entity's health. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Health { + pub health: u32, + pub max_health: u32, +} + +impl Health { + /// Creates a new `Health` object with both health + /// and max_health initialized to the given value. + pub fn new(max_health: u32) -> Self { + Self { + health: max_health, + max_health, + } + } + + /// Reduce the health by at most the amount `damage`. If + /// the subtraction would underflow, health is set to 0. + pub fn deal_damage(&mut self, damage: u32) { + self.health = self.health.saturating_sub(damage); + } + + /// TODO + pub fn regenerate() { + todo!() + } +} + +pub struct Hunger { + pub food: u32, + pub saturation: u32, +} + +impl Hunger { + pub fn new() -> Self { + Self { + food: 20, + saturation: 5, + } + } +} From b2703901e7e8cd800aa2ce96f08fb0bb6112b398 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 19:43:21 +0200 Subject: [PATCH 03/21] Add reset_player --- feather/common/src/game.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/feather/common/src/game.rs b/feather/common/src/game.rs index 3d23442dc..35bcbbf17 100644 --- a/feather/common/src/game.rs +++ b/feather/common/src/game.rs @@ -2,10 +2,10 @@ use std::{cell::RefCell, mem, rc::Rc, sync::Arc}; use base::{BlockId, BlockPosition, ChunkPosition, Position, Text, Title}; use ecs::{ - Ecs, Entity, EntityBuilder, HasEcs, HasResources, NoSuchEntity, Resources, SysResult, - SystemExecutor, + Ecs, Entity, EntityBuilder, EntityRef, HasEcs, HasResources, NoSuchEntity, Resources, + SysResult, SystemExecutor, }; -use quill_common::{entities::Player, entity_init::EntityInit}; +use quill_common::{components::Health, entities::Player, entity_init::EntityInit}; use crate::{ chat::{ChatKind, ChatMessage}, @@ -229,6 +229,13 @@ impl Game { pub fn break_block(&mut self, pos: BlockPosition) -> bool { self.set_block(pos, BlockId::air()) } + + pub fn reset_player(&self, player: EntityRef) { + match player.get_mut::() { + Ok(mut health) => *health = Health::new(20), + Err(_) => (), + } + } } impl HasResources for Game { From b1f95b18fc6734c3c931f590e21ee4c9fc49b5b2 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 20:13:37 +0200 Subject: [PATCH 04/21] Add regenerate to Health --- quill/common/src/components.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/quill/common/src/components.rs b/quill/common/src/components.rs index b5c5370ba..5e1706c61 100644 --- a/quill/common/src/components.rs +++ b/quill/common/src/components.rs @@ -143,9 +143,12 @@ impl Health { self.health = self.health.saturating_sub(damage); } - /// TODO - pub fn regenerate() { - todo!() + /// Increase the health to at most `max_health` of `Health`. + pub fn regenerate(&mut self, health: u32) { + self.health = match self.health + health { + health if health > self.max_health => self.max_health, + health => health, + } } } From d9422d2bd48ce3aee9c2f95a6d3bdc1314933c0b Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 20:56:57 +0200 Subject: [PATCH 05/21] Remove abs causing weird behavoir when jumping before falling --- feather/server/src/systems/falldamage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feather/server/src/systems/falldamage.rs b/feather/server/src/systems/falldamage.rs index 62712ce24..ec1c21a94 100644 --- a/feather/server/src/systems/falldamage.rs +++ b/feather/server/src/systems/falldamage.rs @@ -26,7 +26,7 @@ fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { false => { let new_distance = prev_position.0.y - position.y; - fall_distance.0 += new_distance.abs(); + fall_distance.0 += new_distance; } // Apply fall damage. true => { From a4b9be7da836d17304493830bf10bea0d32fa969 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 21:00:30 +0200 Subject: [PATCH 06/21] Remove entities on 0 health --- feather/server/src/systems/health.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/feather/server/src/systems/health.rs b/feather/server/src/systems/health.rs index d4c6e9763..5a28f8741 100644 --- a/feather/server/src/systems/health.rs +++ b/feather/server/src/systems/health.rs @@ -8,11 +8,28 @@ pub fn register(_: &mut Game, systems: &mut SystemExecutor) { } fn update_health(game: &mut Game, server: &mut Server) -> SysResult { - for (_, (client_id, health)) in game.ecs.query::<(&ClientId, &mut Health)>().iter() { - if let Some(client) = server.clients.get(*client_id) { - client.update_health(&health); + let mut entities = Vec::new(); + + for (entity, health) in game.ecs.query::<&Health>().iter() { + match game.ecs.get::(entity) { + // Entity is player + Ok(client_id) => { + if let Some(client) = server.clients.get(*client_id) { + client.update_health(&health); + } + } + Err(_) => { + if health.health == 0 { + entities.push(entity); + } + } } } + // Destroy all entities with 0 health (that are not players). + for entity in entities { + game.remove_entity(entity)?; + } + Ok(()) } From b0372019147799bec96ef4caac837868e805bf31 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 21:01:11 +0200 Subject: [PATCH 07/21] Someone removed plugin_message --- feather/server/src/systems.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/feather/server/src/systems.rs b/feather/server/src/systems.rs index f734febca..6587c8dae 100644 --- a/feather/server/src/systems.rs +++ b/feather/server/src/systems.rs @@ -40,6 +40,7 @@ pub fn register(server: Server, game: &mut Game, systems: &mut SystemExecutor().add_system(tick_clients); From 841c7721749c42174de8fd3bcab34d4519d3abd9 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 21:58:45 +0200 Subject: [PATCH 08/21] Default for Hunger --- quill/common/src/components.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/quill/common/src/components.rs b/quill/common/src/components.rs index 5e1706c61..32d2e4d8b 100644 --- a/quill/common/src/components.rs +++ b/quill/common/src/components.rs @@ -165,3 +165,9 @@ impl Hunger { } } } + +impl Default for Hunger { + fn default() -> Self { + Self::new() + } +} From 88b6dacb42a4927e24b2fc993b374f527efd36df Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 21:59:15 +0200 Subject: [PATCH 09/21] Add Health to player --- feather/common/src/entities/player.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feather/common/src/entities/player.rs b/feather/common/src/entities/player.rs index 42cb12285..e98111835 100644 --- a/feather/common/src/entities/player.rs +++ b/feather/common/src/entities/player.rs @@ -2,7 +2,7 @@ use anyhow::bail; use base::EntityKind; use ecs::{EntityBuilder, SysResult}; use quill_common::{ - components::{CreativeFlying, Sneaking, Sprinting}, + components::{CreativeFlying, Health, Sneaking, Sprinting}, entities::Player, }; @@ -13,6 +13,7 @@ pub fn build_default(builder: &mut EntityBuilder) { .add(CreativeFlying(false)) .add(Sneaking(false)) .add(Sprinting(false)) + .add(Health::new(20)) .add(EntityKind::Player); } From f975e31e5349d0099a8e6d6bf7abf8159840bb55 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sat, 11 Sep 2021 22:43:09 +0200 Subject: [PATCH 10/21] Update reset_player --- feather/common/src/game.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/feather/common/src/game.rs b/feather/common/src/game.rs index 35bcbbf17..0f3915a9e 100644 --- a/feather/common/src/game.rs +++ b/feather/common/src/game.rs @@ -231,9 +231,8 @@ impl Game { } pub fn reset_player(&self, player: EntityRef) { - match player.get_mut::() { - Ok(mut health) => *health = Health::new(20), - Err(_) => (), + if let Ok(mut health) = player.get_mut::() { + *health = Health::new(20); } } } From 0d376996f86b674f6caedf53f6095e0622ed95f5 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sun, 12 Sep 2021 08:18:02 +0200 Subject: [PATCH 11/21] Update falldamage calculation --- feather/server/src/systems/falldamage.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/feather/server/src/systems/falldamage.rs b/feather/server/src/systems/falldamage.rs index ec1c21a94..34bd40dc4 100644 --- a/feather/server/src/systems/falldamage.rs +++ b/feather/server/src/systems/falldamage.rs @@ -2,7 +2,7 @@ use crate::{ entities::{FallDistance, PreviousPosition}, Game, Server, }; -use base::Position; +use base::{Gamemode, Position}; use ecs::{SysResult, SystemExecutor}; use quill_common::components::{Health, OnGround}; @@ -11,7 +11,7 @@ pub fn register(_: &mut Game, systems: &mut SystemExecutor) { } fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { - for (_, (position, prev_position, on_ground, fall_distance, health)) in game + for (entity, (position, prev_position, on_ground, fall_distance, health)) in game .ecs .query::<( &Position, @@ -22,9 +22,17 @@ fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { )>() .iter() { + // Only calculate fall damage for players that are Survival/Adventure mode. + if let Ok(gamemode) = game.ecs.get::(entity) { + if *gamemode != Gamemode::Survival && *gamemode != Gamemode::Adventure { + continue; + } + } + match on_ground.0 { false => { - let new_distance = prev_position.0.y - position.y; + // Prevent negative fall damage to accumulate while flying upwards/jumping. + let new_distance = f64::max(0.0, prev_position.0.y - position.y); fall_distance.0 += new_distance; } From 3958d97368c44dba0d881c3ba2f418203676d2f3 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sun, 12 Sep 2021 08:19:29 +0200 Subject: [PATCH 12/21] Make reset_player failiable, default to default_gamemode on respawn --- feather/common/src/game.rs | 8 ++++---- feather/server/src/packet_handlers/health.rs | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/feather/common/src/game.rs b/feather/common/src/game.rs index 0f3915a9e..4732debb1 100644 --- a/feather/common/src/game.rs +++ b/feather/common/src/game.rs @@ -230,10 +230,10 @@ impl Game { self.set_block(pos, BlockId::air()) } - pub fn reset_player(&self, player: EntityRef) { - if let Ok(mut health) = player.get_mut::() { - *health = Health::new(20); - } + pub fn reset_player(&self, player: EntityRef) -> SysResult { + let mut health = player.get_mut::()?; + *health = Health::new(20); + Ok(()) } } diff --git a/feather/server/src/packet_handlers/health.rs b/feather/server/src/packet_handlers/health.rs index 281b5bc82..f63f9e0d4 100644 --- a/feather/server/src/packet_handlers/health.rs +++ b/feather/server/src/packet_handlers/health.rs @@ -1,5 +1,4 @@ use crate::{ClientId, Server}; -use base::Gamemode; use common::Game; use ecs::{Entity, SysResult}; use protocol::packets::client::ClientStatus; @@ -15,10 +14,10 @@ pub fn handle_client_status( let client_id = game.ecs.get::(player_id).unwrap(); let client = server.clients.get(*client_id).unwrap(); - client.respawn_player(Gamemode::Survival); + client.respawn_player(server.options.default_gamemode); let player = game.ecs.entity(player_id)?; - game.reset_player(player); + game.reset_player(player)?; } ClientStatus::RequestStats => {} } From 7d33f78a12413197c399e89f57d7410688920b8c Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sun, 12 Sep 2021 08:31:39 +0200 Subject: [PATCH 13/21] Remove unnecessary borrow --- feather/server/src/systems/health.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feather/server/src/systems/health.rs b/feather/server/src/systems/health.rs index 5a28f8741..9b174fce9 100644 --- a/feather/server/src/systems/health.rs +++ b/feather/server/src/systems/health.rs @@ -15,7 +15,7 @@ fn update_health(game: &mut Game, server: &mut Server) -> SysResult { // Entity is player Ok(client_id) => { if let Some(client) = server.clients.get(*client_id) { - client.update_health(&health); + client.update_health(health); } } Err(_) => { From b2fcfe591a9509a24a9b3ad1ecdcb4147e016a18 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Sun, 12 Sep 2021 08:32:03 +0200 Subject: [PATCH 14/21] Update doc --- feather/common/src/game.rs | 1 + feather/server/src/entities.rs | 3 +-- feather/server/src/systems.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/feather/common/src/game.rs b/feather/common/src/game.rs index 4732debb1..1c17e925f 100644 --- a/feather/common/src/game.rs +++ b/feather/common/src/game.rs @@ -230,6 +230,7 @@ impl Game { self.set_block(pos, BlockId::air()) } + /// Reset the players state, preparing it for respawn. pub fn reset_player(&self, player: EntityRef) -> SysResult { let mut health = player.get_mut::()?; *health = Health::new(20); diff --git a/feather/server/src/entities.rs b/feather/server/src/entities.rs index 86f5e493a..e08d39d09 100644 --- a/feather/server/src/entities.rs +++ b/feather/server/src/entities.rs @@ -59,7 +59,6 @@ fn spawn_living_entity(entity: &EntityRef, client: &Client) -> SysResult { Ok(()) } -/// Increasing distance of an entity falling. Used to calculate -/// fall damage for entities with health. +/// Distance fallen since an entity was on ground. #[derive(Copy, Clone, Debug)] pub struct FallDistance(pub f64); diff --git a/feather/server/src/systems.rs b/feather/server/src/systems.rs index 6587c8dae..234c924ee 100644 --- a/feather/server/src/systems.rs +++ b/feather/server/src/systems.rs @@ -35,7 +35,7 @@ pub fn register(server: Server, game: &mut Game, systems: &mut SystemExecutor Date: Sun, 12 Sep 2021 10:46:06 +0200 Subject: [PATCH 15/21] Unload player entity when dead, recreate when respawning --- feather/server/src/packet_handlers/health.rs | 14 +++++++++++- feather/server/src/systems/health.rs | 23 +++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/feather/server/src/packet_handlers/health.rs b/feather/server/src/packet_handlers/health.rs index f63f9e0d4..dde96e5b6 100644 --- a/feather/server/src/packet_handlers/health.rs +++ b/feather/server/src/packet_handlers/health.rs @@ -1,7 +1,8 @@ -use crate::{ClientId, Server}; +use crate::{ClientId, NetworkId, Position, Server}; use common::Game; use ecs::{Entity, SysResult}; use protocol::packets::client::ClientStatus; +use uuid::Uuid; pub fn handle_client_status( game: &mut Game, @@ -18,6 +19,17 @@ pub fn handle_client_status( let player = game.ecs.entity(player_id)?; game.reset_player(player)?; + + let network_id = game.ecs.get::(player_id).unwrap(); + let position = game.ecs.get::(player_id).unwrap(); + let uuid = game.ecs.get::(player_id).unwrap(); + + // Recreate the player for all clients. + server.broadcast_nearby_with(*position, |client| { + if client.network_id() != *network_id { + client.send_player(*network_id, *uuid, *position); + } + }); } ClientStatus::RequestStats => {} } diff --git a/feather/server/src/systems/health.rs b/feather/server/src/systems/health.rs index 9b174fce9..7f2b0e230 100644 --- a/feather/server/src/systems/health.rs +++ b/feather/server/src/systems/health.rs @@ -1,6 +1,6 @@ -use crate::{client::ClientId, Game, Server}; +use crate::{client::ClientId, Game, NetworkId, Server}; +use base::Position; use ecs::{SysResult, SystemExecutor}; - use quill_common::components::Health; pub fn register(_: &mut Game, systems: &mut SystemExecutor) { @@ -8,26 +8,37 @@ pub fn register(_: &mut Game, systems: &mut SystemExecutor) { } fn update_health(game: &mut Game, server: &mut Server) -> SysResult { - let mut entities = Vec::new(); + let mut drop_entities = Vec::new(); - for (entity, health) in game.ecs.query::<&Health>().iter() { + for (entity, (health, &position, &network_id)) in + game.ecs.query::<(&Health, &Position, &NetworkId)>().iter() + { match game.ecs.get::(entity) { // Entity is player Ok(client_id) => { if let Some(client) = server.clients.get(*client_id) { client.update_health(health); } + + if health.health == 0 { + // Unload/hide the player from all other clients. + server.broadcast_nearby_with(position, |client| { + if client.is_entity_loaded(network_id) { + client.unload_entity(network_id); + } + }); + } } Err(_) => { if health.health == 0 { - entities.push(entity); + drop_entities.push(entity); } } } } // Destroy all entities with 0 health (that are not players). - for entity in entities { + for entity in drop_entities { game.remove_entity(entity)?; } From 973606f72db929cc5e592afd14049be6d63471be Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Mon, 13 Sep 2021 17:46:37 +0200 Subject: [PATCH 16/21] Reset fall distance when moving upwards --- feather/server/src/systems/falldamage.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/feather/server/src/systems/falldamage.rs b/feather/server/src/systems/falldamage.rs index 34bd40dc4..744b9a730 100644 --- a/feather/server/src/systems/falldamage.rs +++ b/feather/server/src/systems/falldamage.rs @@ -31,10 +31,13 @@ fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { match on_ground.0 { false => { - // Prevent negative fall damage to accumulate while flying upwards/jumping. - let new_distance = f64::max(0.0, prev_position.0.y - position.y); + let new_distance = prev_position.0.y - position.y; - fall_distance.0 += new_distance; + match new_distance < 0.0 { + // Reset fall distance when the player moves upwards. + true => fall_distance.0 = 0.0, + false => fall_distance.0 += new_distance, + } } // Apply fall damage. true => { From 6dba89af2636c999d83eb0e8bf2672b9854cdf47 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Mon, 13 Sep 2021 17:47:27 +0200 Subject: [PATCH 17/21] Only add FallDistance to entities with Health component --- feather/server/src/entities.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/feather/server/src/entities.rs b/feather/server/src/entities.rs index e08d39d09..c85b76a75 100644 --- a/feather/server/src/entities.rs +++ b/feather/server/src/entities.rs @@ -1,6 +1,6 @@ use base::{EntityKind, Position}; use ecs::{EntityBuilder, EntityRef, SysResult}; -use quill_common::entity_init::EntityInit; +use quill_common::{components::Health, entity_init::EntityInit}; use uuid::Uuid; use crate::{Client, NetworkId}; @@ -25,8 +25,13 @@ pub fn add_entity_components(builder: &mut EntityBuilder, init: &EntityInit) { if !builder.has::() { builder.add(NetworkId::new()); } + + // Track fall damage for the entities with `Health`. + if builder.has::() { + builder.add(FallDistance(0.0)); + } + builder.add(PreviousPosition(*builder.get::().unwrap())); - builder.add(FallDistance(0.0)); add_spawn_packet(builder, init); } From fa219919d1441f80b5acefd1acb6d22800831e3d Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Fri, 17 Sep 2021 22:59:53 +0200 Subject: [PATCH 18/21] Add Health components to entities --- feather/common/src/entities/bat.rs | 4 ++-- feather/common/src/entities/bee.rs | 4 ++-- feather/common/src/entities/blaze.rs | 7 +++++-- feather/common/src/entities/boat.rs | 4 ++-- feather/common/src/entities/cat.rs | 4 ++-- feather/common/src/entities/cave_spider.rs | 7 +++++-- feather/common/src/entities/chest_minecart.rs | 7 +++++-- feather/common/src/entities/chicken.rs | 7 +++++-- feather/common/src/entities/cod.rs | 4 ++-- feather/common/src/entities/command_block_minecart.rs | 3 ++- feather/common/src/entities/cow.rs | 4 ++-- feather/common/src/entities/creeper.rs | 7 +++++-- feather/common/src/entities/dolphin.rs | 7 +++++-- feather/common/src/entities/drowned.rs | 7 +++++-- feather/common/src/entities/elder_guardian.rs | 7 +++++-- feather/common/src/entities/end_crystal.rs | 7 +++++-- feather/common/src/entities/ender_dragon.rs | 7 +++++-- feather/common/src/entities/enderman.rs | 7 +++++-- feather/common/src/entities/endermite.rs | 7 +++++-- feather/common/src/entities/evoker.rs | 7 +++++-- feather/common/src/entities/experience_orb.rs | 7 +++++-- feather/common/src/entities/fox.rs | 4 ++-- feather/common/src/entities/furnace_minecart.rs | 3 ++- feather/common/src/entities/ghast.rs | 7 +++++-- feather/common/src/entities/giant.rs | 7 +++++-- feather/common/src/entities/guardian.rs | 7 +++++-- feather/common/src/entities/hoglin.rs | 7 +++++-- feather/common/src/entities/hopper_minecart.rs | 7 +++++-- feather/common/src/entities/husk.rs | 4 ++-- feather/common/src/entities/illusioner.rs | 7 +++++-- feather/common/src/entities/iron_golem.rs | 7 +++++-- feather/common/src/entities/item.rs | 4 ++-- feather/common/src/entities/minecart.rs | 7 +++++-- feather/common/src/entities/mooshroom.rs | 7 +++++-- feather/common/src/entities/ocelot.rs | 7 +++++-- feather/common/src/entities/panda.rs | 7 +++++-- feather/common/src/entities/parrot.rs | 7 +++++-- feather/common/src/entities/phantom.rs | 7 +++++-- feather/common/src/entities/pig.rs | 4 ++-- feather/common/src/entities/piglin.rs | 7 +++++-- feather/common/src/entities/piglin_brute.rs | 7 +++++-- feather/common/src/entities/pillager.rs | 7 +++++-- feather/common/src/entities/polar_bear.rs | 7 +++++-- feather/common/src/entities/pufferfish.rs | 7 +++++-- feather/common/src/entities/rabbit.rs | 7 +++++-- feather/common/src/entities/ravager.rs | 7 +++++-- feather/common/src/entities/salmon.rs | 7 +++++-- feather/common/src/entities/sheep.rs | 7 +++++-- feather/common/src/entities/shulker.rs | 7 +++++-- feather/common/src/entities/silverfish.rs | 7 +++++-- feather/common/src/entities/skeleton.rs | 7 +++++-- feather/common/src/entities/skeleton_horse.rs | 7 +++++-- feather/common/src/entities/snow_golem.rs | 7 +++++-- feather/common/src/entities/spawner_minecart.rs | 3 ++- feather/common/src/entities/spider.rs | 7 +++++-- feather/common/src/entities/squid.rs | 7 +++++-- feather/common/src/entities/stray.rs | 7 +++++-- feather/common/src/entities/strider.rs | 7 +++++-- feather/common/src/entities/tnt_minecart.rs | 7 +++++-- feather/common/src/entities/tropical_fish.rs | 7 +++++-- feather/common/src/entities/turtle.rs | 7 +++++-- feather/common/src/entities/vex.rs | 4 ++-- feather/common/src/entities/villager.rs | 7 +++++-- feather/common/src/entities/vindicator.rs | 7 +++++-- feather/common/src/entities/wandering_trader.rs | 3 ++- feather/common/src/entities/witch.rs | 7 +++++-- feather/common/src/entities/wither.rs | 7 +++++-- feather/common/src/entities/wither_skeleton.rs | 7 +++++-- feather/common/src/entities/wolf.rs | 4 ++-- feather/common/src/entities/zoglin.rs | 7 +++++-- feather/common/src/entities/zombie.rs | 7 +++++-- feather/common/src/entities/zombie_horse.rs | 7 +++++-- feather/common/src/entities/zombie_villager.rs | 7 +++++-- feather/common/src/entities/zombified_piglin.rs | 3 ++- 74 files changed, 319 insertions(+), 143 deletions(-) diff --git a/feather/common/src/entities/bat.rs b/feather/common/src/entities/bat.rs index f222c3e21..fe2980a10 100644 --- a/feather/common/src/entities/bat.rs +++ b/feather/common/src/entities/bat.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Bat; +use quill_common::{components::Health, entities::Bat}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Bat).add(EntityKind::Bat); + builder.add(Bat).add(Health::new(6)).add(EntityKind::Bat); } diff --git a/feather/common/src/entities/bee.rs b/feather/common/src/entities/bee.rs index d72385897..ab89155e1 100644 --- a/feather/common/src/entities/bee.rs +++ b/feather/common/src/entities/bee.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Bee; +use quill_common::{components::Health, entities::Bee}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Bee).add(EntityKind::Bee); + builder.add(Bee).add(Health::new(10)).add(EntityKind::Bee); } diff --git a/feather/common/src/entities/blaze.rs b/feather/common/src/entities/blaze.rs index 8345ca50b..d02f85f2c 100644 --- a/feather/common/src/entities/blaze.rs +++ b/feather/common/src/entities/blaze.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Blaze; +use quill_common::{components::Health, entities::Blaze}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Blaze).add(EntityKind::Blaze); + builder + .add(Blaze) + .add(Health::new(20)) + .add(EntityKind::Blaze); } diff --git a/feather/common/src/entities/boat.rs b/feather/common/src/entities/boat.rs index 74798544b..9ec63f7e6 100644 --- a/feather/common/src/entities/boat.rs +++ b/feather/common/src/entities/boat.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Boat; +use quill_common::{components::Health, entities::Boat}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Boat).add(EntityKind::Boat); + builder.add(Boat).add(Health::new(6)).add(EntityKind::Boat); } diff --git a/feather/common/src/entities/cat.rs b/feather/common/src/entities/cat.rs index 0d046eb71..c7d1e0da2 100644 --- a/feather/common/src/entities/cat.rs +++ b/feather/common/src/entities/cat.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Cat; +use quill_common::{components::Health, entities::Cat}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Cat).add(EntityKind::Cat); + builder.add(Cat).add(Health::new(10)).add(EntityKind::Cat); } diff --git a/feather/common/src/entities/cave_spider.rs b/feather/common/src/entities/cave_spider.rs index ef2f5079e..feb120c30 100644 --- a/feather/common/src/entities/cave_spider.rs +++ b/feather/common/src/entities/cave_spider.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::CaveSpider; +use quill_common::{components::Health, entities::CaveSpider}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(CaveSpider).add(EntityKind::CaveSpider); + builder + .add(CaveSpider) + .add(Health::new(12)) + .add(EntityKind::CaveSpider); } diff --git a/feather/common/src/entities/chest_minecart.rs b/feather/common/src/entities/chest_minecart.rs index 814cc3a15..254c78f02 100644 --- a/feather/common/src/entities/chest_minecart.rs +++ b/feather/common/src/entities/chest_minecart.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ChestMinecart; +use quill_common::{components::Health, entities::ChestMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(ChestMinecart).add(EntityKind::ChestMinecart); + builder + .add(ChestMinecart) + .add(Health::new(6)) + .add(EntityKind::ChestMinecart); } diff --git a/feather/common/src/entities/chicken.rs b/feather/common/src/entities/chicken.rs index acad9f090..730496aeb 100644 --- a/feather/common/src/entities/chicken.rs +++ b/feather/common/src/entities/chicken.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Chicken; +use quill_common::{components::Health, entities::Chicken}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Chicken).add(EntityKind::Chicken); + builder + .add(Chicken) + .add(Health::new(4)) + .add(EntityKind::Chicken); } diff --git a/feather/common/src/entities/cod.rs b/feather/common/src/entities/cod.rs index f00ab6ced..fb52225ca 100644 --- a/feather/common/src/entities/cod.rs +++ b/feather/common/src/entities/cod.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Cod; +use quill_common::{components::Health, entities::Cod}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Cod).add(EntityKind::Cod); + builder.add(Cod).add(Health::new(3)).add(EntityKind::Cod); } diff --git a/feather/common/src/entities/command_block_minecart.rs b/feather/common/src/entities/command_block_minecart.rs index 7ee4cf12d..21a0e2d3d 100644 --- a/feather/common/src/entities/command_block_minecart.rs +++ b/feather/common/src/entities/command_block_minecart.rs @@ -1,10 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::CommandBlockMinecart; +use quill_common::{components::Health, entities::CommandBlockMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); builder .add(CommandBlockMinecart) + .add(Health::new(6)) .add(EntityKind::CommandBlockMinecart); } diff --git a/feather/common/src/entities/cow.rs b/feather/common/src/entities/cow.rs index 0819836c1..f00c23cee 100644 --- a/feather/common/src/entities/cow.rs +++ b/feather/common/src/entities/cow.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Cow; +use quill_common::{components::Health, entities::Cow}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Cow).add(EntityKind::Cow); + builder.add(Cow).add(Health::new(10)).add(EntityKind::Cow); } diff --git a/feather/common/src/entities/creeper.rs b/feather/common/src/entities/creeper.rs index 31c416ef2..56e164e53 100644 --- a/feather/common/src/entities/creeper.rs +++ b/feather/common/src/entities/creeper.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Creeper; +use quill_common::{components::Health, entities::Creeper}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Creeper).add(EntityKind::Creeper); + builder + .add(Creeper) + .add(Health::new(20)) + .add(EntityKind::Creeper); } diff --git a/feather/common/src/entities/dolphin.rs b/feather/common/src/entities/dolphin.rs index ace8dc2d0..95d782dbc 100644 --- a/feather/common/src/entities/dolphin.rs +++ b/feather/common/src/entities/dolphin.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Dolphin; +use quill_common::{components::Health, entities::Dolphin}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Dolphin).add(EntityKind::Dolphin); + builder + .add(Dolphin) + .add(Health::new(10)) + .add(EntityKind::Dolphin); } diff --git a/feather/common/src/entities/drowned.rs b/feather/common/src/entities/drowned.rs index c91618ce1..737652686 100644 --- a/feather/common/src/entities/drowned.rs +++ b/feather/common/src/entities/drowned.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Drowned; +use quill_common::{components::Health, entities::Drowned}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Drowned).add(EntityKind::Drowned); + builder + .add(Drowned) + .add(Health::new(20)) + .add(EntityKind::Drowned); } diff --git a/feather/common/src/entities/elder_guardian.rs b/feather/common/src/entities/elder_guardian.rs index b5a642bc9..8ebd1e79c 100644 --- a/feather/common/src/entities/elder_guardian.rs +++ b/feather/common/src/entities/elder_guardian.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ElderGuardian; +use quill_common::{components::Health, entities::ElderGuardian}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(ElderGuardian).add(EntityKind::ElderGuardian); + builder + .add(ElderGuardian) + .add(Health::new(80)) + .add(EntityKind::ElderGuardian); } diff --git a/feather/common/src/entities/end_crystal.rs b/feather/common/src/entities/end_crystal.rs index 84849f55b..5a92d6f01 100644 --- a/feather/common/src/entities/end_crystal.rs +++ b/feather/common/src/entities/end_crystal.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::EndCrystal; +use quill_common::{components::Health, entities::EndCrystal}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(EndCrystal).add(EntityKind::EndCrystal); + builder + .add(EndCrystal) + .add(Health::new(5)) + .add(EntityKind::EndCrystal); } diff --git a/feather/common/src/entities/ender_dragon.rs b/feather/common/src/entities/ender_dragon.rs index ef6680a7c..1b9372528 100644 --- a/feather/common/src/entities/ender_dragon.rs +++ b/feather/common/src/entities/ender_dragon.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::EnderDragon; +use quill_common::{components::Health, entities::EnderDragon}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(EnderDragon).add(EntityKind::EnderDragon); + builder + .add(EnderDragon) + .add(Health::new(200)) + .add(EntityKind::EnderDragon); } diff --git a/feather/common/src/entities/enderman.rs b/feather/common/src/entities/enderman.rs index 833c752b9..df70690a3 100644 --- a/feather/common/src/entities/enderman.rs +++ b/feather/common/src/entities/enderman.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Enderman; +use quill_common::{components::Health, entities::Enderman}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Enderman).add(EntityKind::Enderman); + builder + .add(Enderman) + .add(Health::new(40)) + .add(EntityKind::Enderman); } diff --git a/feather/common/src/entities/endermite.rs b/feather/common/src/entities/endermite.rs index 1676d2014..953d0270a 100644 --- a/feather/common/src/entities/endermite.rs +++ b/feather/common/src/entities/endermite.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Endermite; +use quill_common::{components::Health, entities::Endermite}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Endermite).add(EntityKind::Endermite); + builder + .add(Endermite) + .add(Health::new(8)) + .add(EntityKind::Endermite); } diff --git a/feather/common/src/entities/evoker.rs b/feather/common/src/entities/evoker.rs index ee2f9d38f..c9c79c67e 100644 --- a/feather/common/src/entities/evoker.rs +++ b/feather/common/src/entities/evoker.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Evoker; +use quill_common::{components::Health, entities::Evoker}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Evoker).add(EntityKind::Evoker); + builder + .add(Evoker) + .add(Health::new(24)) + .add(EntityKind::Evoker); } diff --git a/feather/common/src/entities/experience_orb.rs b/feather/common/src/entities/experience_orb.rs index 0c696cfb6..f09eed9d1 100644 --- a/feather/common/src/entities/experience_orb.rs +++ b/feather/common/src/entities/experience_orb.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ExperienceOrb; +use quill_common::{components::Health, entities::ExperienceOrb}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(ExperienceOrb).add(EntityKind::ExperienceOrb); + builder + .add(ExperienceOrb) + .add(Health::new(5)) + .add(EntityKind::ExperienceOrb); } diff --git a/feather/common/src/entities/fox.rs b/feather/common/src/entities/fox.rs index 2267ab1e2..cb7c18cf4 100644 --- a/feather/common/src/entities/fox.rs +++ b/feather/common/src/entities/fox.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Fox; +use quill_common::{components::Health, entities::Fox}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Fox).add(EntityKind::Fox); + builder.add(Fox).add(Health::new(10)).add(EntityKind::Fox); } diff --git a/feather/common/src/entities/furnace_minecart.rs b/feather/common/src/entities/furnace_minecart.rs index d56fa0efc..563effdd3 100644 --- a/feather/common/src/entities/furnace_minecart.rs +++ b/feather/common/src/entities/furnace_minecart.rs @@ -1,10 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::FurnaceMinecart; +use quill_common::{components::Health, entities::FurnaceMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); builder .add(FurnaceMinecart) + .add(Health::new(6)) .add(EntityKind::FurnaceMinecart); } diff --git a/feather/common/src/entities/ghast.rs b/feather/common/src/entities/ghast.rs index 687175afa..3af2e18b5 100644 --- a/feather/common/src/entities/ghast.rs +++ b/feather/common/src/entities/ghast.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Ghast; +use quill_common::{components::Health, entities::Ghast}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Ghast).add(EntityKind::Ghast); + builder + .add(Ghast) + .add(Health::new(10)) + .add(EntityKind::Ghast); } diff --git a/feather/common/src/entities/giant.rs b/feather/common/src/entities/giant.rs index 11290d1d1..90b99caf3 100644 --- a/feather/common/src/entities/giant.rs +++ b/feather/common/src/entities/giant.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Giant; +use quill_common::{components::Health, entities::Giant}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Giant).add(EntityKind::Giant); + builder + .add(Giant) + .add(Health::new(100)) + .add(EntityKind::Giant); } diff --git a/feather/common/src/entities/guardian.rs b/feather/common/src/entities/guardian.rs index 04289c4bb..2438ce891 100644 --- a/feather/common/src/entities/guardian.rs +++ b/feather/common/src/entities/guardian.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Guardian; +use quill_common::{components::Health, entities::Guardian}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Guardian).add(EntityKind::Guardian); + builder + .add(Guardian) + .add(Health::new(30)) + .add(EntityKind::Guardian); } diff --git a/feather/common/src/entities/hoglin.rs b/feather/common/src/entities/hoglin.rs index 1be5d1dad..0d032ceeb 100644 --- a/feather/common/src/entities/hoglin.rs +++ b/feather/common/src/entities/hoglin.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Hoglin; +use quill_common::{components::Health, entities::Hoglin}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Hoglin).add(EntityKind::Hoglin); + builder + .add(Hoglin) + .add(Health::new(40)) + .add(EntityKind::Hoglin); } diff --git a/feather/common/src/entities/hopper_minecart.rs b/feather/common/src/entities/hopper_minecart.rs index 8cf8455fc..a3711137e 100644 --- a/feather/common/src/entities/hopper_minecart.rs +++ b/feather/common/src/entities/hopper_minecart.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::HopperMinecart; +use quill_common::{components::Health, entities::HopperMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(HopperMinecart).add(EntityKind::HopperMinecart); + builder + .add(HopperMinecart) + .add(Health::new(6)) + .add(EntityKind::HopperMinecart); } diff --git a/feather/common/src/entities/husk.rs b/feather/common/src/entities/husk.rs index dc276d868..c65af2f56 100644 --- a/feather/common/src/entities/husk.rs +++ b/feather/common/src/entities/husk.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Husk; +use quill_common::{components::Health, entities::Husk}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Husk).add(EntityKind::Husk); + builder.add(Husk).add(Health::new(20)).add(EntityKind::Husk); } diff --git a/feather/common/src/entities/illusioner.rs b/feather/common/src/entities/illusioner.rs index f188f09fb..990643c91 100644 --- a/feather/common/src/entities/illusioner.rs +++ b/feather/common/src/entities/illusioner.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Illusioner; +use quill_common::{components::Health, entities::Illusioner}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Illusioner).add(EntityKind::Illusioner); + builder + .add(Illusioner) + .add(Health::new(32)) + .add(EntityKind::Illusioner); } diff --git a/feather/common/src/entities/iron_golem.rs b/feather/common/src/entities/iron_golem.rs index ca0c91c9b..740a840b5 100644 --- a/feather/common/src/entities/iron_golem.rs +++ b/feather/common/src/entities/iron_golem.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::IronGolem; +use quill_common::{components::Health, entities::IronGolem}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(IronGolem).add(EntityKind::IronGolem); + builder + .add(IronGolem) + .add(Health::new(100)) + .add(EntityKind::IronGolem); } diff --git a/feather/common/src/entities/item.rs b/feather/common/src/entities/item.rs index 7fe8f4b44..00abecc7e 100644 --- a/feather/common/src/entities/item.rs +++ b/feather/common/src/entities/item.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Item; +use quill_common::{components::Health, entities::Item}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Item).add(EntityKind::Item); + builder.add(Item).add(Health::new(5)).add(EntityKind::Item); } diff --git a/feather/common/src/entities/minecart.rs b/feather/common/src/entities/minecart.rs index f28ed8687..57bfe846e 100644 --- a/feather/common/src/entities/minecart.rs +++ b/feather/common/src/entities/minecart.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Minecart; +use quill_common::{components::Health, entities::Minecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Minecart).add(EntityKind::Minecart); + builder + .add(Minecart) + .add(Health::new(6)) + .add(EntityKind::Minecart); } diff --git a/feather/common/src/entities/mooshroom.rs b/feather/common/src/entities/mooshroom.rs index 984f2c913..500eb49c4 100644 --- a/feather/common/src/entities/mooshroom.rs +++ b/feather/common/src/entities/mooshroom.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Mooshroom; +use quill_common::{components::Health, entities::Mooshroom}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Mooshroom).add(EntityKind::Mooshroom); + builder + .add(Mooshroom) + .add(Health::new(10)) + .add(EntityKind::Mooshroom); } diff --git a/feather/common/src/entities/ocelot.rs b/feather/common/src/entities/ocelot.rs index 0e1d4c528..52fb8f54d 100644 --- a/feather/common/src/entities/ocelot.rs +++ b/feather/common/src/entities/ocelot.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Ocelot; +use quill_common::{components::Health, entities::Ocelot}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Ocelot).add(EntityKind::Ocelot); + builder + .add(Ocelot) + .add(Health::new(10)) + .add(EntityKind::Ocelot); } diff --git a/feather/common/src/entities/panda.rs b/feather/common/src/entities/panda.rs index c63b7e116..e909fcc80 100644 --- a/feather/common/src/entities/panda.rs +++ b/feather/common/src/entities/panda.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Panda; +use quill_common::{components::Health, entities::Panda}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Panda).add(EntityKind::Panda); + builder + .add(Panda) + .add(Health::new(20)) + .add(EntityKind::Panda); } diff --git a/feather/common/src/entities/parrot.rs b/feather/common/src/entities/parrot.rs index 919865d45..cb75b078c 100644 --- a/feather/common/src/entities/parrot.rs +++ b/feather/common/src/entities/parrot.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Parrot; +use quill_common::{components::Health, entities::Parrot}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Parrot).add(EntityKind::Parrot); + builder + .add(Parrot) + .add(Health::new(6)) + .add(EntityKind::Parrot); } diff --git a/feather/common/src/entities/phantom.rs b/feather/common/src/entities/phantom.rs index 4339412d7..dfbc8c445 100644 --- a/feather/common/src/entities/phantom.rs +++ b/feather/common/src/entities/phantom.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Phantom; +use quill_common::{components::Health, entities::Phantom}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Phantom).add(EntityKind::Phantom); + builder + .add(Phantom) + .add(Health::new(20)) + .add(EntityKind::Phantom); } diff --git a/feather/common/src/entities/pig.rs b/feather/common/src/entities/pig.rs index 210cf2c0a..f766e9248 100644 --- a/feather/common/src/entities/pig.rs +++ b/feather/common/src/entities/pig.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Pig; +use quill_common::{components::Health, entities::Pig}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Pig).add(EntityKind::Pig); + builder.add(Pig).add(Health::new(10)).add(EntityKind::Pig); } diff --git a/feather/common/src/entities/piglin.rs b/feather/common/src/entities/piglin.rs index 3c759c2e5..3fc8907c6 100644 --- a/feather/common/src/entities/piglin.rs +++ b/feather/common/src/entities/piglin.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Piglin; +use quill_common::{components::Health, entities::Piglin}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Piglin).add(EntityKind::Piglin); + builder + .add(Piglin) + .add(Health::new(16)) + .add(EntityKind::Piglin); } diff --git a/feather/common/src/entities/piglin_brute.rs b/feather/common/src/entities/piglin_brute.rs index b9d371464..1a4f52c75 100644 --- a/feather/common/src/entities/piglin_brute.rs +++ b/feather/common/src/entities/piglin_brute.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::PiglinBrute; +use quill_common::{components::Health, entities::PiglinBrute}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(PiglinBrute).add(EntityKind::PiglinBrute); + builder + .add(PiglinBrute) + .add(Health::new(50)) + .add(EntityKind::PiglinBrute); } diff --git a/feather/common/src/entities/pillager.rs b/feather/common/src/entities/pillager.rs index 3e76f800b..c19947f12 100644 --- a/feather/common/src/entities/pillager.rs +++ b/feather/common/src/entities/pillager.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Pillager; +use quill_common::{components::Health, entities::Pillager}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Pillager).add(EntityKind::Pillager); + builder + .add(Pillager) + .add(Health::new(24)) + .add(EntityKind::Pillager); } diff --git a/feather/common/src/entities/polar_bear.rs b/feather/common/src/entities/polar_bear.rs index 532bf6791..7b87e66c9 100644 --- a/feather/common/src/entities/polar_bear.rs +++ b/feather/common/src/entities/polar_bear.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::PolarBear; +use quill_common::{components::Health, entities::PolarBear}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(PolarBear).add(EntityKind::PolarBear); + builder + .add(PolarBear) + .add(Health::new(30)) + .add(EntityKind::PolarBear); } diff --git a/feather/common/src/entities/pufferfish.rs b/feather/common/src/entities/pufferfish.rs index 65c67a85a..1c8081440 100644 --- a/feather/common/src/entities/pufferfish.rs +++ b/feather/common/src/entities/pufferfish.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Pufferfish; +use quill_common::{components::Health, entities::Pufferfish}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Pufferfish).add(EntityKind::Pufferfish); + builder + .add(Pufferfish) + .add(Health::new(3)) + .add(EntityKind::Pufferfish); } diff --git a/feather/common/src/entities/rabbit.rs b/feather/common/src/entities/rabbit.rs index 4b2582fb0..6c58cb6b8 100644 --- a/feather/common/src/entities/rabbit.rs +++ b/feather/common/src/entities/rabbit.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Rabbit; +use quill_common::{components::Health, entities::Rabbit}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Rabbit).add(EntityKind::Rabbit); + builder + .add(Rabbit) + .add(Health::new(3)) + .add(EntityKind::Rabbit); } diff --git a/feather/common/src/entities/ravager.rs b/feather/common/src/entities/ravager.rs index e0d574c73..88eee3888 100644 --- a/feather/common/src/entities/ravager.rs +++ b/feather/common/src/entities/ravager.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Ravager; +use quill_common::{components::Health, entities::Ravager}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Ravager).add(EntityKind::Ravager); + builder + .add(Ravager) + .add(Health::new(100)) + .add(EntityKind::Ravager); } diff --git a/feather/common/src/entities/salmon.rs b/feather/common/src/entities/salmon.rs index 178ef9d21..d68ca58a9 100644 --- a/feather/common/src/entities/salmon.rs +++ b/feather/common/src/entities/salmon.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Salmon; +use quill_common::{components::Health, entities::Salmon}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Salmon).add(EntityKind::Salmon); + builder + .add(Salmon) + .add(Health::new(3)) + .add(EntityKind::Salmon); } diff --git a/feather/common/src/entities/sheep.rs b/feather/common/src/entities/sheep.rs index d0ca5449d..f6ffa8cca 100644 --- a/feather/common/src/entities/sheep.rs +++ b/feather/common/src/entities/sheep.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Sheep; +use quill_common::{components::Health, entities::Sheep}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Sheep).add(EntityKind::Sheep); + builder + .add(Sheep) + .add(Health::new(8)) + .add(EntityKind::Sheep); } diff --git a/feather/common/src/entities/shulker.rs b/feather/common/src/entities/shulker.rs index 9643d8e29..9c7c3cbc3 100644 --- a/feather/common/src/entities/shulker.rs +++ b/feather/common/src/entities/shulker.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Shulker; +use quill_common::{components::Health, entities::Shulker}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Shulker).add(EntityKind::Shulker); + builder + .add(Shulker) + .add(Health::new(30)) + .add(EntityKind::Shulker); } diff --git a/feather/common/src/entities/silverfish.rs b/feather/common/src/entities/silverfish.rs index ab6e939ab..e2aab26f6 100644 --- a/feather/common/src/entities/silverfish.rs +++ b/feather/common/src/entities/silverfish.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Silverfish; +use quill_common::{components::Health, entities::Silverfish}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Silverfish).add(EntityKind::Silverfish); + builder + .add(Silverfish) + .add(Health::new(8)) + .add(EntityKind::Silverfish); } diff --git a/feather/common/src/entities/skeleton.rs b/feather/common/src/entities/skeleton.rs index 6f72c12b3..b1a35efd2 100644 --- a/feather/common/src/entities/skeleton.rs +++ b/feather/common/src/entities/skeleton.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Skeleton; +use quill_common::{components::Health, entities::Skeleton}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Skeleton).add(EntityKind::Skeleton); + builder + .add(Skeleton) + .add(Health::new(20)) + .add(EntityKind::Skeleton); } diff --git a/feather/common/src/entities/skeleton_horse.rs b/feather/common/src/entities/skeleton_horse.rs index cf8a2c96e..514ca3a03 100644 --- a/feather/common/src/entities/skeleton_horse.rs +++ b/feather/common/src/entities/skeleton_horse.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::SkeletonHorse; +use quill_common::{components::Health, entities::SkeletonHorse}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(SkeletonHorse).add(EntityKind::SkeletonHorse); + builder + .add(SkeletonHorse) + .add(Health::new(15)) + .add(EntityKind::SkeletonHorse); } diff --git a/feather/common/src/entities/snow_golem.rs b/feather/common/src/entities/snow_golem.rs index 01193a73e..e2a7495c0 100644 --- a/feather/common/src/entities/snow_golem.rs +++ b/feather/common/src/entities/snow_golem.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::SnowGolem; +use quill_common::{components::Health, entities::SnowGolem}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(SnowGolem).add(EntityKind::SnowGolem); + builder + .add(SnowGolem) + .add(Health::new(4)) + .add(EntityKind::SnowGolem); } diff --git a/feather/common/src/entities/spawner_minecart.rs b/feather/common/src/entities/spawner_minecart.rs index 550ccde67..cbe449c63 100644 --- a/feather/common/src/entities/spawner_minecart.rs +++ b/feather/common/src/entities/spawner_minecart.rs @@ -1,10 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::SpawnerMinecart; +use quill_common::{components::Health, entities::SpawnerMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); builder .add(SpawnerMinecart) + .add(Health::new(6)) .add(EntityKind::SpawnerMinecart); } diff --git a/feather/common/src/entities/spider.rs b/feather/common/src/entities/spider.rs index 9f1a6c688..12614c5e3 100644 --- a/feather/common/src/entities/spider.rs +++ b/feather/common/src/entities/spider.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Spider; +use quill_common::{components::Health, entities::Spider}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Spider).add(EntityKind::Spider); + builder + .add(Spider) + .add(Health::new(16)) + .add(EntityKind::Spider); } diff --git a/feather/common/src/entities/squid.rs b/feather/common/src/entities/squid.rs index 8743b62a1..a305ae31a 100644 --- a/feather/common/src/entities/squid.rs +++ b/feather/common/src/entities/squid.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Squid; +use quill_common::{components::Health, entities::Squid}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Squid).add(EntityKind::Squid); + builder + .add(Squid) + .add(Health::new(10)) + .add(EntityKind::Squid); } diff --git a/feather/common/src/entities/stray.rs b/feather/common/src/entities/stray.rs index dd38847aa..1b8609d2c 100644 --- a/feather/common/src/entities/stray.rs +++ b/feather/common/src/entities/stray.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Stray; +use quill_common::{components::Health, entities::Stray}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Stray).add(EntityKind::Stray); + builder + .add(Stray) + .add(Health::new(20)) + .add(EntityKind::Stray); } diff --git a/feather/common/src/entities/strider.rs b/feather/common/src/entities/strider.rs index b94f79706..b6b06de8b 100644 --- a/feather/common/src/entities/strider.rs +++ b/feather/common/src/entities/strider.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Strider; +use quill_common::{components::Health, entities::Strider}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Strider).add(EntityKind::Strider); + builder + .add(Strider) + .add(Health::new(20)) + .add(EntityKind::Strider); } diff --git a/feather/common/src/entities/tnt_minecart.rs b/feather/common/src/entities/tnt_minecart.rs index 77b2bca36..b5b601311 100644 --- a/feather/common/src/entities/tnt_minecart.rs +++ b/feather/common/src/entities/tnt_minecart.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::TntMinecart; +use quill_common::{components::Health, entities::TntMinecart}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(TntMinecart).add(EntityKind::TntMinecart); + builder + .add(TntMinecart) + .add(Health::new(6)) + .add(EntityKind::TntMinecart); } diff --git a/feather/common/src/entities/tropical_fish.rs b/feather/common/src/entities/tropical_fish.rs index 381e50aa0..b0d95ced2 100644 --- a/feather/common/src/entities/tropical_fish.rs +++ b/feather/common/src/entities/tropical_fish.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::TropicalFish; +use quill_common::{components::Health, entities::TropicalFish}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(TropicalFish).add(EntityKind::TropicalFish); + builder + .add(TropicalFish) + .add(Health::new(3)) + .add(EntityKind::TropicalFish); } diff --git a/feather/common/src/entities/turtle.rs b/feather/common/src/entities/turtle.rs index 16c776443..6792f3055 100644 --- a/feather/common/src/entities/turtle.rs +++ b/feather/common/src/entities/turtle.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Turtle; +use quill_common::{components::Health, entities::Turtle}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Turtle).add(EntityKind::Turtle); + builder + .add(Turtle) + .add(Health::new(30)) + .add(EntityKind::Turtle); } diff --git a/feather/common/src/entities/vex.rs b/feather/common/src/entities/vex.rs index 3a92f1cdf..41c228f6b 100644 --- a/feather/common/src/entities/vex.rs +++ b/feather/common/src/entities/vex.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Vex; +use quill_common::{components::Health, entities::Vex}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Vex).add(EntityKind::Vex); + builder.add(Vex).add(Health::new(14)).add(EntityKind::Vex); } diff --git a/feather/common/src/entities/villager.rs b/feather/common/src/entities/villager.rs index 5db272b24..d3bddeedd 100644 --- a/feather/common/src/entities/villager.rs +++ b/feather/common/src/entities/villager.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Villager; +use quill_common::{components::Health, entities::Villager}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Villager).add(EntityKind::Villager); + builder + .add(Villager) + .add(Health::new(20)) + .add(EntityKind::Villager); } diff --git a/feather/common/src/entities/vindicator.rs b/feather/common/src/entities/vindicator.rs index fff0ea097..02734b6e0 100644 --- a/feather/common/src/entities/vindicator.rs +++ b/feather/common/src/entities/vindicator.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Vindicator; +use quill_common::{components::Health, entities::Vindicator}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Vindicator).add(EntityKind::Vindicator); + builder + .add(Vindicator) + .add(Health::new(24)) + .add(EntityKind::Vindicator); } diff --git a/feather/common/src/entities/wandering_trader.rs b/feather/common/src/entities/wandering_trader.rs index db57b88c1..e94060695 100644 --- a/feather/common/src/entities/wandering_trader.rs +++ b/feather/common/src/entities/wandering_trader.rs @@ -1,10 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::WanderingTrader; +use quill_common::{components::Health, entities::WanderingTrader}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); builder .add(WanderingTrader) + .add(Health::new(20)) .add(EntityKind::WanderingTrader); } diff --git a/feather/common/src/entities/witch.rs b/feather/common/src/entities/witch.rs index a3161895a..dcac8d021 100644 --- a/feather/common/src/entities/witch.rs +++ b/feather/common/src/entities/witch.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Witch; +use quill_common::{components::Health, entities::Witch}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Witch).add(EntityKind::Witch); + builder + .add(Witch) + .add(Health::new(26)) + .add(EntityKind::Witch); } diff --git a/feather/common/src/entities/wither.rs b/feather/common/src/entities/wither.rs index 02fa1fe78..2b691d128 100644 --- a/feather/common/src/entities/wither.rs +++ b/feather/common/src/entities/wither.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Wither; +use quill_common::{components::Health, entities::Wither}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Wither).add(EntityKind::Wither); + builder + .add(Wither) + .add(Health::new(300)) + .add(EntityKind::Wither); } diff --git a/feather/common/src/entities/wither_skeleton.rs b/feather/common/src/entities/wither_skeleton.rs index 085b9e280..9cb943639 100644 --- a/feather/common/src/entities/wither_skeleton.rs +++ b/feather/common/src/entities/wither_skeleton.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::WitherSkeleton; +use quill_common::{components::Health, entities::WitherSkeleton}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(WitherSkeleton).add(EntityKind::WitherSkeleton); + builder + .add(WitherSkeleton) + .add(Health::new(20)) + .add(EntityKind::WitherSkeleton); } diff --git a/feather/common/src/entities/wolf.rs b/feather/common/src/entities/wolf.rs index cc07cb7db..9fd24cf70 100644 --- a/feather/common/src/entities/wolf.rs +++ b/feather/common/src/entities/wolf.rs @@ -1,8 +1,8 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Wolf; +use quill_common::{components::Health, entities::Wolf}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Wolf).add(EntityKind::Wolf); + builder.add(Wolf).add(Health::new(8)).add(EntityKind::Wolf); } diff --git a/feather/common/src/entities/zoglin.rs b/feather/common/src/entities/zoglin.rs index 79d6ab4e5..8a381ead1 100644 --- a/feather/common/src/entities/zoglin.rs +++ b/feather/common/src/entities/zoglin.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Zoglin; +use quill_common::{components::Health, entities::Zoglin}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Zoglin).add(EntityKind::Zoglin); + builder + .add(Zoglin) + .add(Health::new(40)) + .add(EntityKind::Zoglin); } diff --git a/feather/common/src/entities/zombie.rs b/feather/common/src/entities/zombie.rs index eeb456878..62bc6d529 100644 --- a/feather/common/src/entities/zombie.rs +++ b/feather/common/src/entities/zombie.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::Zombie; +use quill_common::{components::Health, entities::Zombie}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(Zombie).add(EntityKind::Zombie); + builder + .add(Zombie) + .add(Health::new(20)) + .add(EntityKind::Zombie); } diff --git a/feather/common/src/entities/zombie_horse.rs b/feather/common/src/entities/zombie_horse.rs index 44a7e0919..816aebf86 100644 --- a/feather/common/src/entities/zombie_horse.rs +++ b/feather/common/src/entities/zombie_horse.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ZombieHorse; +use quill_common::{components::Health, entities::ZombieHorse}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(ZombieHorse).add(EntityKind::ZombieHorse); + builder + .add(ZombieHorse) + .add(Health::new(15)) + .add(EntityKind::ZombieHorse); } diff --git a/feather/common/src/entities/zombie_villager.rs b/feather/common/src/entities/zombie_villager.rs index 29ae9d02c..2f31b033f 100644 --- a/feather/common/src/entities/zombie_villager.rs +++ b/feather/common/src/entities/zombie_villager.rs @@ -1,8 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ZombieVillager; +use quill_common::{components::Health, entities::ZombieVillager}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); - builder.add(ZombieVillager).add(EntityKind::ZombieVillager); + builder + .add(ZombieVillager) + .add(Health::new(20)) + .add(EntityKind::ZombieVillager); } diff --git a/feather/common/src/entities/zombified_piglin.rs b/feather/common/src/entities/zombified_piglin.rs index 83b300f7b..c30f8f2c7 100644 --- a/feather/common/src/entities/zombified_piglin.rs +++ b/feather/common/src/entities/zombified_piglin.rs @@ -1,10 +1,11 @@ use base::EntityKind; use ecs::EntityBuilder; -use quill_common::entities::ZombifiedPiglin; +use quill_common::{components::Health, entities::ZombifiedPiglin}; pub fn build_default(builder: &mut EntityBuilder) { super::build_default(builder); builder .add(ZombifiedPiglin) + .add(Health::new(20)) .add(EntityKind::ZombifiedPiglin); } From 2d626a6be37e61bbd765d9936d664c0e862131e3 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Fri, 17 Sep 2021 23:23:17 +0200 Subject: [PATCH 19/21] Split falldamage calculation between players and other entities --- feather/server/src/systems/falldamage.rs | 64 ++++++++++++++---------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/feather/server/src/systems/falldamage.rs b/feather/server/src/systems/falldamage.rs index 744b9a730..18d26f84b 100644 --- a/feather/server/src/systems/falldamage.rs +++ b/feather/server/src/systems/falldamage.rs @@ -22,37 +22,49 @@ fn calculate_falldamage(game: &mut Game, _: &mut Server) -> SysResult { )>() .iter() { - // Only calculate fall damage for players that are Survival/Adventure mode. - if let Ok(gamemode) = game.ecs.get::(entity) { - if *gamemode != Gamemode::Survival && *gamemode != Gamemode::Adventure { - continue; - } - } + match game.ecs.get::(entity) { + // Entity is player + Ok(gamemode) => match *gamemode { + // Only Survival/Adventure mode affected by fall damage. + // Fall damage for players is based on velocity (WIP). + Gamemode::Survival | Gamemode::Adventure => match on_ground.0 { + false => { + let new_distance = prev_position.0.y - position.y; + fall_distance.0 += new_distance; + } - match on_ground.0 { - false => { - let new_distance = prev_position.0.y - position.y; + true => { + let damage = (fall_distance.0.ceil() as u32).saturating_sub(3); + health.deal_damage(damage); - match new_distance < 0.0 { - // Reset fall distance when the player moves upwards. - true => fall_distance.0 = 0.0, - false => fall_distance.0 += new_distance, - } - } - // Apply fall damage. - true => { - let damage = (fall_distance.0.ceil() as u32).saturating_sub(3); + #[cfg(debug_assertions)] + if fall_distance.0 > 0.0 { + log::debug!("Entity fell {:?} ({:?} damage)", fall_distance, damage); + } - health.deal_damage(damage); + // Reset fall distance. + fall_distance.0 = 0.0; + } + }, + _ => (), + }, + // Other entities have fall damage based on distance. Moving upwards (+Y) does + // not reduce the accumulated fall damage. + Err(_) => match on_ground.0 { + false => fall_distance.0 += (prev_position.0.y - position.y).max(0.0), + true => { + let damage = (fall_distance.0.ceil() as u32).saturating_sub(3); + health.deal_damage(damage); - #[cfg(debug_assertions)] - if fall_distance.0 > 0.0 { - log::debug!("Entity fell {:?} ({:?} damage)", fall_distance, damage); - } + #[cfg(debug_assertions)] + if fall_distance.0 > 0.0 { + log::debug!("Entity fell {:?} ({:?} damage)", fall_distance, damage); + } - // Reset fall distance. - fall_distance.0 = 0.0; - } + // Reset fall distance. + fall_distance.0 = 0.0; + } + }, } } From 26be034ed6216fe9dcff87fe384cfb1af0eea0da Mon Sep 17 00:00:00 2001 From: 0xc0001a2040 <38496922+MrGunflame@users.noreply.github.com> Date: Wed, 29 Sep 2021 08:17:37 +0200 Subject: [PATCH 20/21] Update feather/server/src/client.rs Co-authored-by: Nufflee --- feather/server/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feather/server/src/client.rs b/feather/server/src/client.rs index 1b2bf84c8..3f540f6ea 100644 --- a/feather/server/src/client.rs +++ b/feather/server/src/client.rs @@ -517,7 +517,7 @@ impl Client { let dimension = nbt::Blob::from_reader(&mut Cursor::new(include_bytes!( "../../../assets/dimension.nbt" ))) - .expect("dimenstion asset is malformed"); + .expect("dimension asset is malformed"); self.send_packet(Respawn { dimension: Nbt(dimension), From 6fef44073fd7ab56fdb530e22861d31589eea336 Mon Sep 17 00:00:00 2001 From: MrGunflame Date: Thu, 30 Sep 2021 18:31:54 +0200 Subject: [PATCH 21/21] Update error handling --- feather/server/src/packet_handlers/health.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/feather/server/src/packet_handlers/health.rs b/feather/server/src/packet_handlers/health.rs index 2c4c4a4ce..60699b9dd 100644 --- a/feather/server/src/packet_handlers/health.rs +++ b/feather/server/src/packet_handlers/health.rs @@ -7,22 +7,22 @@ use uuid::Uuid; pub fn handle_client_status( game: &mut Game, server: &mut Server, - player_id: Entity, + player: Entity, packet: ClientStatus, ) -> SysResult { match packet { ClientStatus::PerformRespawn => { - let client_id = game.ecs.get::(player_id).unwrap(); + let client_id = game.ecs.get::(player)?; let client = server.clients.get(*client_id).unwrap(); client.respawn_player(server.options.default_gamemode); - let player = game.ecs.entity(player_id)?; - game.reset_player(player)?; + let player_entity = game.ecs.entity(player)?; + game.reset_player(player_entity)?; - let network_id = game.ecs.get::(player_id).unwrap(); - let position = game.ecs.get::(player_id).unwrap(); - let uuid = game.ecs.get::(player_id).unwrap(); + let network_id = game.ecs.get::(player)?; + let position = game.ecs.get::(player)?; + let uuid = game.ecs.get::(player)?; // Recreate the player for all clients. server.broadcast_nearby_with(*position, |client| {