I am creating this issue as a tracking issue for craft actions as this topic turns out to be a little more complicated.
Why so complicated
Just as blocks, different items can share the same ID. Simple example would be ores and dyes but that gets more complicated with some mods. In order to support items from many mods, we need to be able to distinguish between these items even when they share the same ID.
While blocks can be handled easily using block traits, such a way does not exist for ItemStacks.
In theory, we can access the required information using instances of Key from the Keys class. However, this does only work with Keys already known or at least programmatically registered to Sponge. Therefore, this is not an option for us.
The current idea
The current idea looks like this and is similar to the for traited blocks:
Retrieve the corresponding action with the item ID
Check, whether or not we need to further distinguish
No -> Return the base reward
Yes -> Continue
Serialize the ItemStackSnapshot in order to get raw access to the properties
Compare pre-defined values from the configuration against the available data
Choose reward associated to the match
A quick inspection with dyes suggests full serialization not to be required as ItemStackSnapshot#toContainer() appears to provide Maped access to the properties.
I am creating this issue as a tracking issue for
craft
actions as this topic turns out to be a little more complicated.Why so complicated
Just as blocks, different items can share the same ID. Simple example would be ores and dyes but that gets more complicated with some mods. In order to support items from many mods, we need to be able to distinguish between these items even when they share the same ID.
While blocks can be handled easily using block traits, such a way does not exist for
ItemStack
s.In theory, we can access the required information using instances of
Key
from theKeys
class. However, this does only work withKey
s already known or at least programmatically registered to Sponge. Therefore, this is not an option for us.The current idea
The current idea looks like this and is similar to the for traited blocks:
ItemStackSnapshot
in order to get raw access to the propertiesA quick inspection with dyes suggests full serialization not to be required as
ItemStackSnapshot#toContainer()
appears to provideMap
ed access to the properties.An inspection command for admins will also be needed for this as it will allow us to show the serialized data to them. I am currently testing with implementations on: https://github.com/MarkL4YG/TotalEconomy/tree/t/jobaction-crafting
References
Q&A on Sponges Discord: https://gist.github.com/MarkL4YG/8b11b79ff38a6ca0c3fb55e211926ca7 Sponge docs on data serialization: https://docs.spongepowered.org/stable/en/plugin/data/serialization.html Relates to: #244