How to require multiple items to be inputted for one output

  • I want to make it so the compressor recipe requires 9 of itemX to make one of itemY. How would I code it to do that?


    Sorry if this is the wrong section, I didn't see one labeled 'addon creation help'.


    Maybe use ItemStacks?


    (not a modder, so not really sure)

    • Official Post

    There are some threads that have some information about addon making, i just dont know if they have the piece of infornation you want.
    Nevertheless IC2 has an example of 9 -> 1 recipe (energy crystal), you could take a look on its code maybe?
    If I'm not helpful enough, soon or later Greg may post here what you're looking for.

  • Please, don't respond unless you actually know, although I appreciate your willingness to help.


    Code
    yourInputStack.stackSize = 9;


    is what you need.
    Don't forget to .copy() your itemstack before setting stackSize on it (annoying mutability rules in java...).

  • Let's make a recipe to make 1 Diamond out of 9 Dirt in the compressor.


    Code
    Recipes.compressor.addRecipe(new RecipeInputItemStack(new ItemStack(Block.Dirt, 9)), null, new ItemStack(Item.Diamond, 1));


    What we did was creating an RecipeInputItemStack (something requested by the IC² API), which can just be a normal ItemStack. The ItemStack is constructed with the Block (Block.Dirt) and the StackSize 9.
    After the RecipeInputItemStack follows a NBTTagCompound parameter, which will be null in most cases (You won't really use it and if you do, not too often I think). The Output is another ItemStack, this time constructed with an Item.Diamond and the StackSize 1.
    You should also remember to give the ItemStacks the correct metadata, for example if you want to use Red Wool in a Recipe (it'd be another parameter in the ItemStack constructor, just look at its implementation in your dev environment to learn more)