Refined Storage

Refined Storage

77M Downloads

OpenComputers API for Recipe Callbacks

AJMansfield opened this issue ยท 5 comments

commented

Currently certain crafting processes are difficult or impossible to do directly with Refined Storage's auto-crafting system. In order to make the auto-crafting system more versatile, it would make sense to add a way to register some type of recipe callback in the OpenComputers API, so that the autocrafting can leverage more advanced equipment control procedures. That way, complicated/custom crafting procedures can be handled by an OpenComputers script.

My specific use case is to automate Tinker's Construct Smeltery operations, to allow automated alloying, casting, and re-melting, but a system like this could also easily be used for controlling a breeder reactor in ExtremeReactors, or even to control automatic farms and only harvest when the resources are needed.

commented

You can already start tasks with a redstone signal.

Either way, an OC driver is already coming to the next RS version:

https://refinedstorage.raoulvdberge.com/wiki/opencomputers-api

commented

I am aware of the API that is being added. The API does not have a callback mechanism.

commented

I misinterpreted your request.

Under what circumstances should this callback be called? When the task finishes?

commented

What I mean is this:

  • The script calls some function of the API with a table containing a callback function, the recipe information, and possibly timing information or an availability-checking callback depending on how it's implemented.

  • When the recipe specified is needed, the callback is called with the number of items requested and any other pertinent details. The callback runs, doing whatever it needs to do to fulfill the recipe, and then returns (possibly also reporting the actual process yield if needed).

There's probably a few ways this could be enhanced, e.g. adding different queuing/concurrency options so that (if appropriate) successive requests could be combined together, and adding a way for the crafting script to report partial progress, but I'm sure you're far more familiar with the best way to handle that.

There may be ways to accomplish this using redstone signals to trigger the OpenComputers stuff, but it's not really a very elegant mechanism. The current simplest way I've been able to figure out to do it is to create a dummy pattern to make the recipe available, then trigger the lua script with a redstone signal when it's requested, then poll getTasks and search through it to find the correct one, extract the details of the task, do the crafting, and then cancel the task.
There's also no way to report partial progress, no easy way to deal with having the task cancelled mid-run by the user, and no clean way to handle probabilistic processes like farming, where the yields aren't fixed or guaranteed.

commented

No, I don't think OC code can be responsible for autocrafting logic.