ericgrandt / TotalEconomy

All in one economy plugin for Minecraft.
https://ericgrandt.github.io/TotalEconomy/
MIT License
32 stars 33 forks source link

[Tracking] Support for craft-actions #341

Closed MarkL4YG closed 9 months ago

MarkL4YG commented 5 years ago

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:

  1. Retrieve the corresponding action with the item ID
  2. Check, whether or not we need to further distinguish
    • No -> Return the base reward
    • Yes -> Continue
  3. Serialize the ItemStackSnapshot in order to get raw access to the properties
  4. Compare pre-defined values from the configuration against the available data
  5. 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. image

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