Skip to content

Add type to represent unimplemented data component types#12222

Merged
Owen1212055 merged 1 commit into
PaperMC:mainfrom
TonytheMacaroni:unimplemented-data-types
Mar 8, 2025
Merged

Add type to represent unimplemented data component types#12222
Owen1212055 merged 1 commit into
PaperMC:mainfrom
TonytheMacaroni:unimplemented-data-types

Conversation

@TonytheMacaroni
Copy link
Copy Markdown
Contributor

@TonytheMacaroni TonytheMacaroni commented Mar 3, 2025

Adds an Unimplemented type for data component types that have yet to receive an API implementation. This replaces using DataComponentType.NonValued for such cases. Using DataComponentType.NonValued here causes issues as you're able to get instances of unimplemented data component types using methods like Registry#get and ItemStack#getDataTypes.

Tested with ItemStack#hasData, ItemStack#resetData, and ItemStack#unsetData.

Not a big fan of using raw types for the converters, but unsure of a better way to do it.

@TonytheMacaroni TonytheMacaroni requested a review from a team as a code owner March 3, 2025 18:45
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Mar 3, 2025
@ShaneBeee
Copy link
Copy Markdown
Contributor

Call me crazy, but do you think it might be a good idea to add the unimplemented types to DataComponentTypes?
With a note saying they're currently not supported by the API?
This could cut down on people asking "Where is X component, I saw it on McWiki?"

ex:

/**
* Not Currently Implemented
*/
@Deprecated (or some other annotation)
static final DataComponentType.Unimplemented CUSTOM_DATA;

@TonytheMacaroni
Copy link
Copy Markdown
Contributor Author

That was originally something I wanted to do (although just using DataComponentType as the field's type, instead of a new API interface), but changing the types of fields breaks compatibility unconditionally.

I guess data components are already generally marked as 'unstable', but I don't think it's worth it to add the fields anyway.

@Owen1212055
Copy link
Copy Markdown
Member

Backward compatibility with the fields is never guaranteed, FYI.

However this is defo a tricky part of the API, so most likely more feedback will need to be collected here.

@lynxplay
Copy link
Copy Markdown
Contributor

lynxplay commented Mar 4, 2025

I'd rather not expose un-implemented types to the API fields.

Having something actively exposed that does not work seem pretty unintuitive for people.
"Thing not existing" seems a lot more clear that it just isn't API exposed.
I am happy with the unimplemented part.

@GliczDev
Copy link
Copy Markdown
Contributor

GliczDev commented Mar 4, 2025

I think something like isUnimplemented() or isSupported() exposed in the API would be nice to detect if the component is supported after getting it from registry or something

@TonytheMacaroni
Copy link
Copy Markdown
Contributor Author

Not sure if that'd be particularly useful, especially since most of the time you'd have something like:

DataComponentType type = ...;
switch (type) {
    case DataComponentType.Valued<?> valued -> ...;
    case DataComponentType.NonValued nonValued -> ...;
    case DataComponentType unimplemented -> ...;
}

@github-project-automation github-project-automation Bot moved this from Awaiting review to Awaiting final testing in Paper PR Queue Mar 5, 2025
@Owen1212055 Owen1212055 merged commit 2526fe0 into PaperMC:main Mar 8, 2025
@github-project-automation github-project-automation Bot moved this from Awaiting final testing to Merged in Paper PR Queue Mar 8, 2025
@TonytheMacaroni TonytheMacaroni deleted the unimplemented-data-types branch August 17, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

6 participants