How to use basic machine recipe API through reflection?

  • Hello,


    I'm trying to add Macerator recipes through reflection, so that I don't have to include parts of the ever-changing IC2 API in my mod, which is not an IC2 dependency.


    However, the weird way that IMachineRecipeManager is set up is making this difficult. That "V" variable thingy means that I'm getting NullPointerExceptions upon trying to getMethod("addRecipe", ItemStack.class, ItemStack.class). And I don't know how else to do this.


    How do I fix this? Is it even possible anymore? Do I absolutely have to include that part of the API in my download and directly reference it? It's not terrible if I do, because the classes I'd be including are so small that any change would be likely to break it anyway, but I want to keep it as clean from external code as possible.

    • Official Post

    No you dont have to include it at all. Just make yourself a function called "addMaceratorRecipe(ItemStack input, ItemStack Output)". inside that Function you put first a Block of:
    try {} catch(Throwable e) {}
    Inside that Block you write all the code, which relies on the IC² API and you are free. Also V isnt a variable. It's a Generic Datatype. Similar to ArrayList<String> for example to make sure only Strings get stored in the ArrayList.

  • This is what I ended up doing, after reading the readme for the Thermal Expansion API (which I was using for pulverizer recipes too). I was under the impression that it would blow up on me from the very beginning if I imported a file which could not be found, but apparently that's just for recompiling, not for running. I double-checked PowerCrystal's NetherOres source code, and he does exactly that, importing the API inside a try/catch block and then not including the API files, with no problems.


    Thank you for the response confirming it again for me!