feather
feather copied to clipboard
Status Effect
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.
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.
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 exampleserver/src/effects/speed.rs
would defineSpeedEffect
component and systemapply_speed
which queries for entities withSpeedEffect
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.)
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.
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?