Crafting recipe based on the input

Place to get help with not working mods / modding interface.
Gotbread
Inserter
Inserter
Posts: 30
Joined: Wed Mar 11, 2015 11:14 pm
Contact:

Crafting recipe based on the input

Post by Gotbread »

Hello!

I got a mod idea: a more complex chemical crafting system, based on the input temperature of the fluids.
For example, one could have a crude oil cracking process, taking in oil and water. At 50°C, the output could be 80%/10%/10% (heavy oil, light oil, gas)
but at 250°C crude oil temperature, the output could be 50%/25%/25%. Just as an example.

This could open up some interesting gameplay, based on the heating and cooling of fluids, much like many real world chemical processes.

But how can i implement such a feature?

Some ideas i came up with:

1) Use the existing crafting system. The player selects e.g. "Oil Processing" as the recipe, but the chemical plant internally selects "Oil Processing 175°C", from a list of player invisible recipes. This is based on the input fluid box temperature, and would need to be checked every few frames. If the temperature changed, a different recipe would be selected, e.g. "Oil Processing 225°C".

Challenges:
- how would i display a different recipe to the user from the internal one? Given the complexity, if i have 5 temperature points for fluid 1, and 5 for fluid 2, that would mean 25 permutations of temperature combinations. As such, the user should only see 1 recipe, and not worry about the entire list. How do i do that?
- when to change the recipe? Is there a callback i can use whenever a product is completed? Or check on every Nth tick? My concern is that if i change the recipe at a random time in the crafting cycle, the process would loose the fluid ingredients, creating a very lossy process.

2) Create my own crafting system. I experimented with showing my own GUI (not easy) which looks similar to the chemical plant one, with a progress bar, and fake the same look. Then i create the crafting logic by manually operating the fluid boxes.

Challenges:
- very tedious to create the same GUI feeling
- very performance intensive to always check every few ticks.

I tend towards option 1, but how would i implement that without loosing production progress and ingredients?
eugenekay
Filter Inserter
Filter Inserter
Posts: 825
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: Crafting recipe based on the input

Post by eugenekay »

Good News! The FluidIngredientPrototype already supports a minimum_temperature and maximum_temperature setting; this is not used in Vanilla. You can take a look at the Pyanodons Petroleum Handling mod which has many complicated recipes that do take advantage of this mechanism.

Good luck maintaining your sanity!
Gotbread
Inserter
Inserter
Posts: 30
Joined: Wed Mar 11, 2015 11:14 pm
Contact:

Re: Crafting recipe based on the input

Post by Gotbread »

Thanks, will take a look!

But that would not be automatic, right? Lets say i have 1 fluid which needs <50°C and another that needs >=50°C. The user then still would have to manually change the recipe? Just the crafting would not happen if the fluid has the wrong temperature?
eugenekay
Filter Inserter
Filter Inserter
Posts: 825
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: Crafting recipe based on the input

Post by eugenekay »

Correct; the Recipe selection is still Manual. If the fluid is the wrong temperature the Machine just sits idle.

Implementing automatic switching to pick the “right” recipe (even if less efficient) is an interesting idea, but you would need to do a good bit of Scripting:
  • For each machine with a “OilCracking###” recipe, check to see if it is Working
  • If it is not working, use LuaEntity::get_fluid() to see what Fluid is present and the Temperature it is at
  • Call LuaEntity::set_recipe() on the machine
Item ingredients will be moved to the Trash slot; Fluid ingredients are pushed back to the Fluid network if possible (or just voided).

Presumably you would want to set the various OilCracking### sub-recipes for each temperature to have the “hidden” flag to keep the recipe selection GUI simple.

Good Luck! Interesting mod idea you have here.
Post Reply

Return to “Modding help”