-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand on entity serialization API #8492
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
Conversation
|
The issue I see is that wouldn't this allow for the serialization of entities in an invalid state and then their state will be "reset"? Not sure if that's a good thing. |
Yes, it would, and that's partially the goal. Before you'd get a Personally, I don't think this is a problem for API which does nothing by itself and is even placed in Unsafe. |
|
Well, in my opinion, if you try serializing an invalid entity I wouldn't expect it to magically be deserialized as a valid entity? |
I think it depends. My wording might've not been the best, but I'll try to explain. Upon deserialization, you'll get the same set of data as before serialization. For example, if you serialize an entity with 0 health you'll also get an entity with 0 health upon deserialization, and nothing will happen if you try to spawn it, because, well, it's "invalid". One other example of an "invalid" state is when the entity was despawned. |
59f8b18 to
6db37a1
Compare
|
Generally after looking at this, I think it might be worth hiding these "bypasses" behind some form of flag system similar to relative teleportation. E.g. if I as a plugin wants to save an entity that is a vehicle, it could actively define that by passing some I do not really want to end up with completely invalid entities being saved when all I want to do is passenger saving. |
|
Do you have anything interest in moving forward with this PR ? |
|
Yes, I do! :) As for the feedback, I guess flags might be a neat solution 🤔
My proposals are:
Because I think that not being able to save a passenger is more of a bug in this case, and it shouldn't be prevented. Vanilla does that bacause that entity is already serialized as part of its vehicle, so no need to save the passenger separately once again. I believe in our case we want to serialize the passenger specifically since we don't care about the vehicle.
Previously you'd end up with corrupted data. Should we have the inner checks and raise IllegalArgumentException? So, for example, if we have
|
6db37a1 to
49dffc5
Compare
|
Alright, rebased & introduced flags & added some javadocs. Feedback would be appreciated! For now, this PR:
|
|
I like the flags chosen 👍 player seems a bit weird, but I guess there could be some really weird point ? UnsafeValues#serialiseEntity(Entity) is now gone. I'll look at the impl of things once I make it out of the train :) |
|
Here's an example of serialized player data: https://pastebin.com/CtZFh0Gz Note: player normally falls under MISC category ( |
|
Rebased. Allowed non-persistent passengers to be serialized, but that required a little extra diff. |
0e34d8d to
db692d5
Compare
db692d5 to
f3f6245
Compare
f3f6245 to
9d86c21
Compare
54df7a2 to
f85bdb4
Compare
|
Rebased, but haven't gotten to test whether everything works yet. |
|
Will revisit once 1.21 builds are ready. |
|
Needs some testing on my end, but does look good otherwise. Will get to on monday 👍 |
Makes an entity serializable via API no matter what.
Previously you'd get an empty component (and an error later when trying to spawn the deserialized entity) in some cases:
Now there's no problem serializing & deserializing & spawning entities in those cases.
Edit: see the comment below for the new flags explanation