AkashiiKun / MoreAxolotlVariantsAPI-Common

Axolotl Variants Extender API!
Other
3 stars 4 forks source link

[1.20.1] Mixin injecting SynchedEntityData into entities not owned by MoreAxolotlVariantsAPI is dangerous #11

Open TelepathicGrunt opened 1 year ago

TelepathicGrunt commented 1 year ago

Entity Data Accessors should only be ever set by the creator of the entity. Never added to by other mods.

The reason for this is because Entity Data Accessors are order dependent so if multiple mods tries to add these entity data accessors to mobs and on client, they run in a different order than the server did (because mod load order is not guaranteed), the client will get forcibly disconnected from server when the entity spawns.

Instead, this mixin part needs to be removed and migrated properly to a Forge Capability because capabilities were designed specifically for this use case of attaching data to arbitrary entities. It is safer for mods as the vanilla system is designed specifically only for vanilla and unsafe for mods. Then you would use your own packet to send the data to client when needed.

https://github.com/AkashiiKun/MoreAxolotlVariantsAPI-Common/blob/195bd0430a392d343aa42a4e1ad5b91b66d4e572/Common/src/main/java/io/github/akashiikun/mavapi/v1/mixin/AxolotlEntityMixin.java#L50-L61

This is especially a problem in large modpacks where many mods are doing this. Example is TNPLimitless 7 where there's many mods injecting SynchedEntityData onto entities and are getting out of order due to mod load order. Which is causes a lot of reports of people getting disconnected from server due to: image

AkashiiKun commented 9 months ago

Is there any way to not use forge's capabilities? I want the API to be as standalone as possible (in terms of being mod loader API independent)

TelepathicGrunt commented 9 months ago

You can mixin add normal fields, not dataslots/synced data stuff. Then mixin into the entity’s save and read nbt methods to persist the field’s values. And if you need it on client side, send packet from server to client on client entity join and when data changes to make sure client gets same values.

see supplementaries for how they send packet when entity is spawned on client side https://github.com/MehVahdJukaar/Supplementaries/issues/851#issuecomment-1832959877

Basically send packet to server from client, server gets data and sends it back in another packet