AppliedEnergistics / Applied-Energistics-2

A Minecraft Mod about Matter, Energy and using them to conquer the world..
https://appliedenergistics.github.io/
Other
1.43k stars 656 forks source link

Create common GUI and optimized code for Crafting Card #8219

Open riking opened 3 days ago

riking commented 3 days ago

Describe the feature

Create an embeddable class for all parts (Export Bus, Level Emitter, Interface, addons) that can automatically start and own a crafting job, and an associated management GUI.

It maintains a state machine with some states having additional information saved to NBT data. The state machine has 8 states, which I've numbered as if a comparator could inspect them:

  1. Satisfied Item quantity is known to be satisfied. Transitions to Idling when notified by the parent part. Level Emitter: A storage monitor is set on the item quantity and notifies when storage levels drop. Interface: A monitor is maintained for the stocked inventory slots. Export Bus: A periodic check for whether the target inventory can accept more items is performed.
  2. Idling Part is newly created, settings were recently changed, or network was rebooted. Transitions to either Satisfied or Calculating.
  3. Calculating A crafting simulation is in progress and this part is waiting for the results. If the crafting simulation is gone (server reboot), this transitions to Idling. This can transition to Crafting, Ingredients Wait, No CPUs, or Error.
  4. Crafting A crafting job is owned by this part with a crafting CPU assigned. When the assigned Crafting CPU receives finished products, they are delivered directly to this part rather than exported to storage. Items are provided to the parent part as they arrive, or stored in this subpart. Transitions to Exporting or Error. If the part is broken, items can spill in this state. Stored NBT Data: Matter-energy inventory. CraftingLink.
  5. Ingredients Wait: This is a performance-boosting error state, and one of the primary reasons to implement this rework. The crafting simulation reported that ingredients were missing. This part owns a storage monitor for a single critical chain of the missing items. Transitions to Calculating when the monitor notifies this part, or Idling after a long timeout (maybe 30 seconds?). Stored NBT Data: List of ItemStack along one critical chain that the craft was missing.
  6. No Crafting CPUs available: This is an error state. The crafting simulation reported that no crafting CPUs of the correct size were available. This part owns an integer with the byte count needed for the craft. Transitions to Calculating when a periodic check indicates that a crafting CPU of the indicated byte size is available, or Idling after a long timeout. Stored NBT Data: Bytes needed.
  7. Other Error: This is an error state. Any other error, such as: The crafting CPU was deconstructed, by a player or otherwise. Items disappeared from storage between the simulation and the start of the crafting job. Requested item has no direct pattern to make it. Transitions to Idling after a medium length timeout (maybe 1 second?).
  8. Exporting The crafting job has finished, and all items have been delivered to this part. Excess items that the parent part could not immediately use are exported to storage. Transitions to Satisfied (TODO: or Idling?). If the part is broken, items can spill in this state. Stored NBT Data: Matter-energy inventory.

The current state should be made available to the parent part for display in a GUI or otherwise (vanilla comparators?).

Reasons why it should be considered

This should obsolete the need for blocks and addons like the ME Requester that automatically request crafting jobs in a more efficient manner, with backoffs and high batch sizes.

Additional details

https://www.curseforge.com/minecraft/mc-mods/merequester

https://github.com/GTNewHorizons/AE2FluidCraft-Rework/blob/master/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java

riking commented 3 days ago

See also #7841 #8194 #7414

6438 - optionally could be part of the GUI, but I do agree with "just use acceleration card to set the crafting batch size". Stocking interface + Storage bus is the correct option at vanilla AE2 scale to cause multi-stack crafting batch sizes.

7414 - The redstone pulse should be the transition from Satisfied to Idling.