GregTech icon indicating copy to clipboard operation
GregTech copied to clipboard

[Suggestion] Crafting station - mark missing items in red.

Open jk1895 opened this issue 3 years ago • 2 comments

Hello, It would be great if the crafting station would mark missing items in red. I and I'm sure a lot of others would be very grateful for that.

Thanks a lot

jk1895 avatar Aug 11 '21 19:08 jk1895

In fact, I was already working on implementing this feature in a fork of GTCE, and if enough people want it here, I can easily also bring it to GTCE itself.

bruberu avatar Aug 11 '21 19:08 bruberu

This looks like it might be quite complicated to implement. The issue is that there are three different representations of the crafting recipe items and they are not easily linked because of all the wrapping/delegation.

  • There is the "craftingGrid" which is a collection of SlotWidget wrappers to a forge ItemStackHandler that is used to display the items
  • There is an InventoryCrafting in CraftingRecipeResolver which is used for recipe searches
  • Another InventoryCrafting in CachedRecipeData which is used for caching and validation

Further:

  • The Slots actually used to display the information in ModularUIGui are delegates to the SlotWidgets, but in that code they could be any Slot implementation
  • The actual validation of the recipe is against the cached data (care needs to be taken as incorrect/unexpected handling of this data has led to a few bugs in the past)
  • The validation is currently just a yes/no with no information about which items/slots are invalid
  • The validation is done against a summary "required items" rather than identifying individual slots of the crafting grid (this is so recipes with the same item multiple times validate the total items of that type rather than multiple requests)
  • The items/status of the recipe get updated when inventory changes are detected in the Crafting Station's inventory or connected inventories

So the first issue is how to link the recipes subitems to the slot status on the screen CachedRecipeData.requiredItems -> CraftingGrid.SlotWidget(s) This will be required to set the slot status as it changes from missing to present and vice versa The solution to this is not clear to me.

  • Having the crafting grid pull status from the cached recipe seems easiest, but also inefficient (doing this every render tick). A static link is not possible as the cached data is recreated on change of recipe.
  • The opposite would mean updates are only done when things change, but it introduces a reference to the screen in the recipe handling which would make what is already quite hard to read code even worse.

NOTE: The processing that highlights slots should be clever enough to give an indication of what is missing. e.g. if you have 8 iron ingots and want to make an iron block (9 ingots), it should only hightlight the last slot, not all of them

The other issue is probably to introduce a "mixin" interface that lets a Slot choose an override background color. The slot widgets used by the Crafting Station can then provide a red color override if the slot has been flagged as missing.

warjort avatar Aug 12 '21 12:08 warjort