FabricModelPredicateProviderRegistry only accepts ClampedItemPropertyFunctions
quat1024 opened this issue ยท 2 comments
(Mojmap.)
Open up your editor and pull up the class ItemProperties
. You will see:
- two
Map<ResourceLocation, ItemPropertyFunction>
storages,GENERIC_PROPERTIES
andPROPERTIES
- two helper methods that register things to this storage,
registerGeneric
andregister
, that both take ClampedItemPropertyFunction as a parameter.
(For context: ClampedItemPropertyFunction is a helper interface that extends ItemPropertyFunction, overriding its call
method with one that delegates to a new unclampedCall
method, then clamps the result to 0..1. It's important to note that ClampedItemPropertyFunction is a helper interface only. It's just an implementation detail. Everything in Minecraft that uses item property functions, and the backing storage for item property functions, uses the more generic ItemPropertyFunction interface instead.)
Anyway. Given this setup, there are two ways to design something like FabricModelPredicateProviderRegistry
:
- Accept ItemPropertyFunctions, and write them directly into the backing storages (GENERIC_PROPERTIES and PROPERTIES)
- Accept ClampedItemPropertyFunctions, and call the register functions that take clamped functions.
FabricModelPredicateProviderRegistry took the second approach, which limits its scope to ClampedItemPropertyFunctions
only.
I want to register an item property function that outputs numbers greater than 1, so... this is a problem!
The obvious workaround of manually overriding ClampedItemPropertyFunction
with a call
that delegates straight through without doing any clamping works, but if I wanted to spend my time fighting my modding API, I wouldn't be writing Fabric mods ;)
For comparison, Forge's ItemProperties
patch simply changes the method signature of register
to not take Clamped
functions, and that's pretty much all it has to do. It would be easy Fabric-side to accessor and write to the backing storages directly instead of calling the helper functions.
ItemPropertyFunction
is deprecated in vanilla, so not sure if we should be using it. ๐ค