Item data components framework #2760
Open
+305
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on DenizenScript/Denizen-Core#116.
The idea is a system that builds around Paper's data component API (so that we don't have to use the sketchy ItemMeta support for components), and manages things like the component properties, the different component states (removed, set, unset), the
MaterialTagandItemTagvariants of component tags, etc.This adds
DataComponentAdapters that take both a Denizen type and an API type, andtoDenizen/toPapermethods to be implemented.Beyond that, it manages storing the Denizen propery name -> item component mapping (when they don't match), registering both the
ItemTagproperty and theMaterialTag, and registering tags likeItemTag.is_overridden.It also has utility methods like
setIfValid(for setting elements from a map into a Paper builder class, which is going to be extremely common in these), andgetComponentTypefor getting a component type by name or by Denizen property name.It has a
Propertysub-class that's a generic implementation of an item property using thetoDenizen/toPapermethods fromDataComponentAdapter.Also adds an
ItemRemovedproperty that controls the item properties explicitly removed from the item.Its setter is an addition-only setter (similarly to how NBT properties used to work, for example) - this works well for being a property, but might be a little confusing for script usage as you'd actually un-remove a component by unsetting it with the direct mechanism (e.g.
adjust removed:food: remove it,adjust foodunset it)? although the alternative would be manually clearing the components patch - idk, lmk what do you think.ItemHelperImpl(1.21)#getRawComponentsPatchnow excludes removed components whenexcludeHandledistrue.I implemented a
FoodAdapterfor thefoodcomponent (both for testing and as an example).This has a bunch of meta docs stuff - I tried writing a general explanation & examples for item components in
DataComponentAdapter, and also adapters likeFoodAdpaterhave a weird thing where they have both aMaterialTagmeta and a property meta with the same return types - could potentially be a more integrated approach, but this is probably fine for now.For registering adapters, I added a separate
ComponentAdaptersRegistrythat's called inPaperModule, as things were starting to get a little cramped in there - lmk if you'd prefer just having it all inPaperModulethough.I also added a separate package for component adapters as there wasn't really anywhere good to put them,
com.denizenscript.denizen.paper.datacomponents.