Api Recipe Crash?

  • well, I'm currently trying to add in a recipe for a circuit for my mod. I want it to be able to create 2 circuits in the normal circuit recipe, replacing refined iron with rubies. However, I can't seem to get the output to be more than one and the code ALWAYS errors whenever I try and use .getitem() for insulated Copper Cable. Here is my code:



    Any help whatsoever would be helpful! Also, if you wish to be an even greater help, here is the Github Repo link: https://github.com/artman41/ICE

  • Correct me if I am wrong, but I do not think that is the correct way to add a recipe. What you are doing (simplified) is this:


    GameRegistry.addRecipe(outputItemStack, 2, intputObjects); That 2 is what is causing your problems. Remove it, and add this line of code:


    ItemStack circuit = new ItemStack(Items.getItem("electronicCircuit").getItem(), 2);


    Basically, we are extracting the item from IC2's ItemStack and then creating our own itemstack with 2 items in it.



    I have not tried this code, but it should work. Let me know

  • Oh, I also just noticed you are putting your CopperCable into the crafting recipe as an ItemStack. It should be an Item. Just do CopperCable.getItem()


    I am using the experimental API, and it appears you have the CopperCable Item name incorrect. For my version (2.0.157 ex) it should be: insulatedCopperCableItem


    Here is the full code, tested this time:


    Code
    ItemStack circuit = new ItemStack(Items.getItem("electronicCircuit").getItem(), 2);
    	ItemStack CopperCable = Items.getItem("insulatedCopperCableItem");
    
    //      Creates a Electronic Circuit
            GameRegistry.addRecipe(circuit, new Object[]{
                "XXX",
                "RCR",
                "XXX",
                'C', Item.diamond, 'R', Item.redstone, 'X', CopperCable.getItem()
            });
    • Official Post

    As soon as Thunderdark makes Curcuits Metadata based, your Code wouldnt work AGKz.


    This is how you have to do it properly:


    ItemStack tStack = Items.getItem("electronicCircuit").copy(); // <-- The copy() is important!
    tStack.stackSize = 2;


    And then use the Stack.

  • I was actually thinking about doing it that way, but thought the way I did it would be a little more simple and compact. Was not aware he was going to make it metadata based, good to know.

  • there is no reason to use metadata for items, they have 32000 slots...


    as for code, Item and ItemStack is different classes, you cant typecast them directly, to evoid issues with API updates, i suggest to switch to reflections or reflection wrapper or unsafe (bad plan), since your imported API will cause issues after some time.

    • Official Post

    With 90+ mods adding thousands of items, i think metadata is really needed.
    What if BC decided to add its hundres of facades as one ID each, Forestry farm hatches, IC/GT plates ingots and blocks, and so on...

  • it OK to add facades or similar items as single item with metadata, but not really good to merge completely different items into single ID.


    also merging items into single ID source is human factor errors, personally i see this as overcomplication.