feather icon indicating copy to clipboard operation
feather copied to clipboard

Status Effect

Open Defman opened this issue 4 years ago • 4 comments

Support for Minecraft status effects as documented at the wiki.

  • Add a component for all living entities that stores all active status effects ie. a component containing Vec<StatusEffect>.
  • A system that applies the effect of the status effect on the entity.

Defman avatar Mar 06 '20 20:03 Defman

I suggest that each status effect be its own component, e.g. a Regeneration component, a Speed component, etc. to better conform with the ECS architecture. Systems to apply the effects could then be more modular, with for example an apply_speed system which queries for only entities with a Speed component.

caelunshun avatar Mar 20 '20 23:03 caelunshun

A few further notes on how I think this could best be implemented:

  • Probably have an effects module with each effect implemented in a separate submodule, so for example server/src/effects/speed.rs would define SpeedEffect component and system apply_speed which queries for entities with SpeedEffect and does whatever is necessary.
  • A second thought on what I wrote above: when sending over the network, we'll need access to a list of effects an entity has, so we'll still have to store e.g. a Vec<SerializableStatusEffect> component. However, the technique I described above where each effect has its own component should still be used in tandem. (SerializableStatusEffect could probably just be an enum, and it should only be used when sending the status effect packet, not for any other game logic.)

caelunshun avatar Mar 21 '20 01:03 caelunshun

As far as I can tell, very little needs to be done by the server for status effects. When the effect is initially added to the entity, an EntityEffect packet is sent. From there, all the server needs to do is keep track of the time remaining on the effect, and send again when the effect has expired. Later on, it'll also need to send on dimension changes.

Redrield avatar Mar 21 '20 01:03 Redrield

For effects like regeneration, fire resistance, and poison, it's going to be actively iterating over entities with those effects. (At least at some point—this probably won't be implemented now.) But do as you see fit. Maybe the separate components aren't necessary for all status effects—they could just be done for those which require the server to do more?

caelunshun avatar Mar 21 '20 01:03 caelunshun