-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synced data attachments #335
Comments
Use cases I seen where people’s used SyncedEntityData (that actually needed client sync and wasn’t just an error on misuse of wrong tool) was to set server controlled data on entity that would change looks or render something on the entity on client side. So entity spawns on server, data is set, then entity spawns on client side and gets data set from the server. If this can be done on client entity spawn packet, that would be best so entity doesn’t spawn with default looks while waiting for separate packet from server for the synced data. |
I am going to speak to Chunk data, since that's what I primarily use. I use chunk data for location-specific things like protection zones, block placement history, etc. I have been syncing this data for things like rendering protection borders in the world and overlays when looking at blocks you placed. That said, I don't necessarily need everything I store in a chunk on the client. Therefore, I would favor a manual and selective syncing method to minimize network traffic to only when i change things and need it on the client. |
More entity use cases I am seeing by modders:
Manual sync probably would be fine. Most of these are sync once or so. Though stuff like variants needs to have data set initially for the mob and auto synced when the spawn packet is sent to client |
So my use case for this would be having a simple way to add some data which is relevant to the client and is needed as soon as an entity spawn. |
it would also be nice to be able to define to which client an attachment should sync to. attachments needed for data hud stuff only has to be send to the player the attachment is attached to. |
My use case is I'm saving a typed resource to the player. The capability is attached on entity creation and cloned/persisted on death (deliberately lossless at the time of writing). Think 2x HashMap<SomeEnum, Long>, one for the capacities of each type of resource being stored, and another for the amount the player is holding. Q1 Should syncing happen automatically, or should modders notify the system that they want their data attachment to be synced?: I can't think of a reason I wouldn't want this synced back to client automatically. Q2 Should it be possible to send incremental updates as well? (If only part of the data changes, only send that part): My networking setup consists of syncing the smallest unit of work possible for changes to these values, so a packet would consist of: SomeEnum and a long, sync to client player to let them know either their capacity or their amount has changed (two different packets). Ideally I'd keep my network impact as low as humanly possible, so I'd prefer the option to sync only a specific change - to wit this is probably an argument in favor of manual syncs, or complicates thing. Q3 Does the data need to arrive at the same time as vanilla's data? (Potentially problematic for vanilla clients): In my case, the data could sync separately from the vanilla data. I could deal with a delay; I'd consider it my responsibility to defer any handling until I could guarantee the data was synced. Q4 Do we need a graceful fallback for vanilla clients?: I may not understand the question; I think this is N/A for my use case. Mine isn't going to be a capability my mod can allow a player to not have. This would be a throw for me I think? Worth noting at the time of writing, I only need to sync this data to the client player the stats belong to and not other nearby players. TL;DR: I'm very weakly opinionated that the automatic sync feels like it would be really nice/sugar. Having said that, my networking setup was not cumbersome and is some very low-friction netcode. I reckon newcomers to the system aren't going to be totally repelled (this was my first capability and I was not repelled). I think syncing manually is not an unreasonable expectation, but automatic sure sounds nice. |
To answer that one. To give a bit of insight how IC2C for example does it. This system effectively works similar to the Entity sync system, but doesn't rely on wrappers for everything you want to sync. It is more flexible, does support custom data types without actually having to register anything. Only downside, it heavily relies on reflection. |
I'd say sync should definitely be opt-in - there might be, say, data on another player that you'd rather not expose to an untrusted client to prevent cheating or whatnot. Beyond that, yeah, incremental would be good - but let's not assume anything about the structure of the data folks have! I'd say the best way to implement this would simply be a separate method you override for writing data to sync, so you can control exactly what goes to the client - maybe with some context added to help make incremental syncing possible? I'm not entirely sure, mostly spitballing here - I've got a use case for incremental syncing in one of my own mods but frankly I'm not sure I'd use such a system in neoforge, I might just stick with my existing system for manually syncing stuff only when I think it's relevant. Whatever we do, let's not use any weirdness with annotations for this, please - we don't want a repeat of the nonsense that is the config system. Let modders declare the structure of their own data, and which bits need to be synced or not, instead of having that be something you try to imply. |
Read this again but more carefully. I didn't say I can't think of a reason anyone wouldn't want automatic syncing. I said >I<, specifically, for my use case. |
That is totally fine @MercuriusXeno , i just pointed these things out because they get missed by a lot of people ^^" |
I believe the DataAttachment API only needs to have a StreamCodec and send updates when changes occur. I think Java's expressiveness is insufficient to clearly convey incremental data synchronization without writing a lot of boilerplate code. Both Codec and StreamCodec still require a lot of boilerplate code, but I believe using the vanilla rules helps achieve consistency in usage. Or similar to Config, where each entry is separated and internally encoded numerically. This way, incremental synchronization can be achieved, and using a builder would not cause the same discomfort for user as using Codec. |
As long as custom syncing logic is somewhat easy to implement (that is, especially on the "recieved data from server" end to do stuff with existing data instead of tossing it out and replacing it with newly deserialized stuff), incremental updates are not too hard to do -- heck, I've got a system that does incremental updates with StreamCodecs. I don't think neo needs to provide a dedicated system for this as the few folks who want it probably have their own ways they want to do it -- so long as the appropriate hooks for syncing are present it should be all fine. I do not believe using a system like config stuff does is a good idea here. It seems, frankly, rather terrible to work with. |
I hope to have an easy-to-use API where users only need to define their data structures, and then neo handles everything internally like magic. Users can implement broader customizations on their own. In my experience, most data in mod development can actually be represented as a tree composed of records, which is very similar to a config. At the same time, I don't think there's any way to cover all possible cases. Based on this, I believe that a structure representation system similar to config is very useful. |
This change would help out greatly for my modded flag system (#1322), as I currently have to sync the flag changes to clients manually as and when they change. I would however need some way to tell the attachment type to notify ALL clients, not just clients within the level assoicated with my data attachment. This is due to me storing the data in the overworlds level data but flags being server wide data. |
Now that the cap rework is out, I would like to add a system for opt-in automated syncing of block entity, chunk, and entity data attachments from the server to the client. For this, I need the input of modders that would use such a system. To help us implement this, please comment here by explaining your use case, and try to answer the following questions if possible.
Thanks!
Yes this is literally a "request for comments".
The text was updated successfully, but these errors were encountered: