Skip to content
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

Expand on entity serialization API #11807

Merged
merged 3 commits into from
Dec 26, 2024
Merged

Conversation

SoSeDiK
Copy link
Contributor

@SoSeDiK SoSeDiK commented Dec 24, 2024

Original: #8492.


Improves upon entity serialization API.

  • IllegalArgumentException will now be thrown if something goes wrong instead of silently failing and producing invalid data (documented in javadocs).
  • Allows optionally serializing passengers and spawning entities with passengers on them.
  • Adds a few flags to control behavior in places where serialization would normally fail.
Added serialization flags
  • FORCE - serializing entities that wouldn't normally be serialized.
    • This covers non-persistent (Entity#isPersistent) and invalid (Entity#isValid; i.e. dead, despawned) entities.
  • MISC - serializing misc non-saveable entities (lightning bolt, leash, fishing bobber).
  • PASSENGERS - if present, the serialized data will include serialized passengers as well.
    • All passed flags apply to passengers too, i.e. you'd also need to pass FORCE if some passenger is currently non-serializable.
  • PLAYER - if anyone for whatever reason wants to save/look at serialized player's data.
    • Special case since vanilla always skips entity with Player's id, so deserializing such data will lead to IllegalArgumentException.
  • Also touches virtual entities (entity snapshots) and Entity#getAsString to not fail in cases described above (unlike serialization, I see no good reason to fail e.g. just because the entity is marked as non-persistent).

Things to consider:

  1. There seems to be no way of checking whether the misc entity is non-saveable. Should something like EntityType#isSaveable be exposed in a separate PR?

@SoSeDiK SoSeDiK requested a review from a team as a code owner December 24, 2024 09:07
@kennytv kennytv added the type: feature Request for a new Feature. label Dec 24, 2024
@lynxplay lynxplay merged commit aac246a into PaperMC:main Dec 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new Feature.
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

4 participants