Eternal Starlight

Eternal Starlight

5M Downloads

Network implementation causing unnecessary lag

someaddons opened this issue ยท 1 comments

commented

Hi, would be nice if you could improve this part of your code, its causing unnecessary lag since its searching all entities and sends packets all the time :)

Related code:

From looking at your code it seems that you're only attaching the spellcaster interface to the player, in which case you could be just listening to the Player Tick event instead, and check event.player instanceof Spellcaster.
If you need it for more entities than just players I'd recommend keeping a local list for the relevant entities, which gets filled by entity enter/leave world events (just on world enter check instanceof Spellcaster)

Also you normally should not be sending a packet each tick, instead only send it when necessary, aka when your data changed, which can be achieve by a boolean toggle e.g. in the spellData which indicates that it requires syncing.

image

commented

ok I'll fix this soon, thanks for the detailed explanation :)