feather icon indicating copy to clipboard operation
feather copied to clipboard

Health and Death

Open caelunshun opened this issue 3 years ago • 6 comments

Reimplement health and death. This feature existed before #307 but was lost in the rewrite. You can refer to the old directory for how it was previously implemented.

In short, we want:

  • A Health component containing an entity's health and its max health, with methods to deal damage and regenerate.
  • A system that queries for all entities with Health components and removes the entities if health == 0. For players, we instead want to respawn them, which is trickier. It involves sending the ChangeGameState packet and waiting for the client to send ClientStatus. The hard part here is that the player should not be visible to the game while they are in the respawn menu. I'm not sure what the best way to implement this is.
  • To test health, implement fall damage. This entails a system that checks the Position and OnGround components each tick and computes how far an entity has fallen.

caelunshun avatar Mar 02 '21 00:03 caelunshun

I'm probably not experienced enough to actually do it, but I'll take a stab at it. Why does the UpdateHealth packet send the client info about food saturation if stuff like that is handled server-side, at least from my understanding? Also, you said there should be a method to deal damage and regenerate, but would it make more sense to have a set_health() function that is used by a system that updates health? Also, after how many ticks will 1 HP regenerate, and how is that related to food/food saturation? Is there a singular regeneration rate or can they vary?

Sorry I sound very noobish!

Edit: Okay, I got an answer to the latter half of my question, here and here respectively. Should the Health component also contain hunger/saturation and regeneration, or should they be separate (Health, Hunger, and then Saturation, Regeneration as status effects)?

kirawi avatar Mar 04 '21 04:03 kirawi

Why does the UpdateHealth packet send the client info about food saturation if stuff like that is handled server-side, at least from my understanding?

I believe is used on the client to display the vibrating hunger bites when the player is losing saturation. If we don't have food implemented yet, we can just use a default value for hunger/saturation.

you said there should be a method to deal damage and regenerate, but would it make more sense to have a set_health() function that is used by a system that updates health

There will be many systems that deal damage—combat, fall damage, etc. We want to encapsulate the damage calculation, e.g. to ensure we don't get integer underflow.

Should the Health component also contain hunger/saturation and regeneration, or should they be separate (Health, Hunger, and Saturation, Regeneration as status effects)?

Hunger should probably be separate from health, though we don't have to separate saturation from hunger, since they're intertwined. So we can go with Health and Hunger components, the latter of which contains both hunger and saturation.

Sorry I sound very noobish!

No worries, these are all good questions!

caelunshun avatar Mar 04 '21 04:03 caelunshun

if a Living Entity is initialized with a given amount of health that health isn't just going to disappear on its own, something has to damage it, why loop through every Living Entity every tick and check it's health instead of just check if the health is <= 0.0f immediately after it's damaged by a damage source?

z-targz avatar Mar 27 '21 06:03 z-targz

Short answer: Because feather uses a data-oriented architecture with its ECS and not an object-oriented architecture like vanilla minecraft

Schuwi avatar Mar 27 '21 13:03 Schuwi

Small update: I have been very busy and will likely be busy for a while as I'm now in my senior year of high school, and because of other projects that have caught my attention. I still intend to fulfill my obligation to this issue, but it may take a few months to get around to it. If anyone else is interested, please feel free to tackle this issue. Though my previous PR was closed, it was quite close to completion.

I plan to split up this PR into two separate PRs for the sake of time:

  • [ ] Implementing the components, their methods, and exposing them to systems.
  • [ ] Implementing the functionality required to communicate between the server and other clients about the health of entities in the world. This was where I was at with #394. It's complicated as it needs to touch quite a few aspects of the API.

kirawi avatar Jul 13 '21 17:07 kirawi

Short answer: Because feather uses a data-oriented architecture with its ECS and not an object-oriented architecture like vanilla minecraft

How would one infer the death cause in that case?

TypicalDarkness avatar Aug 05 '21 04:08 TypicalDarkness