MinecraftForge icon indicating copy to clipboard operation
MinecraftForge copied to clipboard

Recipe API

Open planetguy32 opened this issue 12 years ago • 13 comments

More and more mods are adding new ways of acquiring items. Would it be possible to have a common API in Forge to allow modders to create "recipe handlers" that other mods can access with neither messy, mod-and-version-specific reflection or mod API dependencies? Being able to add recipes would come in handy for mod integration (no more dependency) and Minetweaker (no more per-mod code), and being able to read recipes automatically would be helpful for NEI and transmutation mods.

planetguy32 avatar Sep 09 '14 18:09 planetguy32

A few months ago i did an attempt creating such system. Where it might look simple to do, it is not. One of the major problems being people creating lots of different recipe types. 4x4 crafting tables, pneumaticraft pressurechamber, thaumcraft infusion, pulverizers, compressors, and so forth... The biggest problem with this is how can i let a RecipeType identify what to do. One of the things i had in mind to solve this is to have some kind of Map with string to ItemStack. Using this you would be able to give items keys, for example with a TE induction smelter input1: <itemstack>, input2: <itemstack>, and have a simple array of output ItemStacks. Having such object for each recipe in the game (be it smelting, pulverizing, whatever) would not be a big problem. What would be is a potential performance issue searching through that list every time something like NEI tries to lookup a recipe.

Does anybody have a better idea on this?

jeffreykog avatar Sep 10 '14 06:09 jeffreykog

One thing I would do is instead of a string, item stack map do a recipe type plus input, input fluid, and output, input\output with a string map to handle what type of recipe it is.

for example,

Static Type = FluidCatalyst Static ModDomain = appliedenergistics2 input = {ChargedCertus:1, Redstone:1, NetherQuartz:1} inputfluid = {Water:1000} output = {FluixCrystal:2} outputfluid = {}

We could add some static flags so mods can say don't bother with this type as a whole ex(fluids vs items)

public static final hasfluidinput = true;

And any other flags required

so the iteration for a fluid look usage becomes

FindFluidUsage(FluidName){
List<Recipe> matches = new List<Recipe>();
foreach (Recipe recipe: registry.recipes){
      if(recipe.hasFluidInput){
            foreach (Fluid fluid: recipe.GetInputFluids()){
                if (fluid.name = FluidName) matches.add(recipe);
            }
      }
}
}

Another option if your looking for performance (in NEI) is to, on client start creating a thread that will separate the clients current recipe list into each set of recipe types designated by the modID and recipe (currently we could use a full class name -> mod:type map)

LinkedHashMap<String, LinkedHashMap<String, List>>

And implement an multi-threaded paged search routine so NEI doesn't just Brute force the recipe list before showing the user some results

This would allow for linear searches where if users want they can configure NEI to Scan the entire list as they view the recipes or stop as soon as the next available page is populated and only continue if they advance the screen.

As someone that has recently been working on large data paging I believe this is doable

Tarig0 avatar Sep 11 '14 02:09 Tarig0

IRecipe and RecipeSorter already exist...unless i missed the point you are trying to make.

GotoLink avatar Sep 11 '14 16:09 GotoLink

@GotoLink those are for normal (crafting-table) recipes only. This is to make tools like NEI either by having a common interface for all machines.

diesieben07 avatar Sep 11 '14 17:09 diesieben07

It seems unlikely anything very productive could come from this-what if the recipe requires power? What if the recipe requires being in the sun? What if the recipe requires reseach? Or vis? You would basically either need a list of generic objects which just list out the requirements, in which case it would be very hard to code anything to actually use it, or limit it to basically just looking at what kind of recipes currently exist and writing a wrapper just for them

soundlogic2236 avatar Sep 11 '14 17:09 soundlogic2236

Hmm lets take vis as an input

This will extend the current recipe class with a new field for vis add the itemstacks and vis for input and itemstack ouput.

if not handled we would notice that the type "Fusion" is not recognized and just list the input items and output items. edit: with the type name displayed up top (possibly localized)

This would not be a perfect implementation but should be fine for generic support and give players an idea of whats required.

Tarig0 avatar Sep 11 '14 18:09 Tarig0

@diesieben07 IRecipe is not limited to crafting tables. Its only limitation is an ItemStack for output...which is not really much of a limitation, since you can store the additional required data into the NBTTagCompound (thus load multiple ItemStack and FluidStack.. or anything that can be loaded from NBT, really). So basically the Recipe API is already here. Sure it is a bummer the vanilla furnace doesn't use it, but why modders wouldn't in their machines or whatever ?

GotoLink avatar Sep 11 '14 22:09 GotoLink

IRecipe is based on InventoryCrafting. Which is used by the crafting grids.

diesieben07 avatar Sep 11 '14 22:09 diesieben07

InventoryCrafting is a basic implementation of IInventory that can be used as-is by any Container. And nothing in it is declared final anyway so you can replace anything you don't care about. Think outside the box ;)

GotoLink avatar Sep 11 '14 23:09 GotoLink

...

diesieben07 avatar Sep 12 '14 00:09 diesieben07

Maybe a lot more generalized method.. Generalized interface for any type of amount(Items, Fluids, Energy, vis, elements, etc.) would be greatly appreciated.

For some mod can add recipe which has no item output

Abastro avatar Nov 05 '14 05:11 Abastro

This issue has been automatically marked as stale because it has not had activity in a long time, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

stale[bot] avatar Dec 27 '17 21:12 stale[bot]

This issue has been automatically closed because it has not had activity in a long time. Please feel free to reopen it or create a new issue.

stale[bot] avatar Jan 11 '18 01:01 stale[bot]