IC² API and IC² Addon Creation. (The Code Part)

    • Official Post

    This is the Thread about the IC2 API and IC2 Addons. If you have a Question about the API or the Dev Environment, you can post it here. If you look for the License Stuff then go here


    API shipping


    If you make an IC2 Addon where IC2 is always installed, you do not need to ship this API inside your Mod, since it is already contained in IC2 itself. So when you compile your Mod do not zip/jar up the IC2 API itself, because then your old IC2 API can accidentally override the IC2 API of IC2 itself what causes crashes.


    If IC2 is not always installed (optional) you can use FML's @Optional annotation to strip missing interfaces at load-time. If you also don't call IC2 code without checking if IC2 is available first, the API isn't even required if IC2 is not installed. Calls to missing classes should only crash when the call actually happens, unreachable calls, e.g. due to a false if clause, don't.


    Summary: There's no need to ship the API ever.


    IDE / Eclipse / Dev environment


    Start with a normal Forge workspace using the Forge src zip, extracting it, running gradle(w) setupDecomWorkspace and gradle(w) eclipse and importing it into Eclipse.
    If you want to you can create a separate project for IC2 or just add IC2 to Forge's project. Add the IC2 dev jar as a library to the build path. You can get it from http://jenkins.ic2.player.to/job/IC2_experimental/, the file name is "industrialcraft-x-x.x.xxx-experimental-dev.jar" (should be the second one). It also needs to be copied to your eclipse working (run) directory's mods-Folder.


    A Documentation of the API: http://ic2api.player.to/ic2api/html/annotated.html


    build.gradle


    A maven compatible repository for the api an dev jars is available at http://maven.ic2.player.to.
    Add the following to your build.gradle to use it, adjusting the version number as needed:



    1.8.9:


    Note that the repositories block is different/outside the existing "buildscript { repositories {} }" block. Ordering matters in build.gradle.
    If you use IC2 core functionality, which isn't recommended, you have to replace api with dev at the end of dependencies - compile. Alternatively, you can use forged "deobfCompile" with the normal jar file instead of the dev one. This will make sure, that it will work no matter if you use different mappings than we use.

  • I've got a question. I use

    Quote

    ElectricItem.manager.discharge(this.dischargeSlot.get(),20,1, false,false);


    to discharge battery in discharge slot. In GUI everything looks fine, but when i extract battery from slot, it returns to full charge. What i forgot to add to code?

  • Code
    repositories {
    	maven {
    		name = "ic2"
    		url = "http://maven.ic2.player.to/"
    	}
    }
    dependencies {
    	compile 'net.industrial-craft:industrialcraft-2:2.1.470-experimental:api'
    }


    It seems, that it won't work with my version of gradle.



    Any guess?

  • I have minecraft and forge set up in eclipse and have downloaded the dev version of ic2e. How do i add the IC2 dev jar as a library to the build path, where is the eclipse working (run) directory's mods-Folder(or what is it called), and is the maven repository required?

  • You don't need a special folder to ic2 dev. Place it anywhere you want. Run eclipse with your project, right-click your project root folder, select properties->Java build path-> Libraries-> Add external Jar and select ic2-dev to add.
    How to modify build.gradle file is written right in first message in this thread. Just don't repeat my mistake.

  • getTransferLimit is confusing me. I see what it's for, but I have no idea what to put as an value. What does the Advanced RE-Battery and Energy Crystal use as their value?

    Help the Official FTB Wiki reach a billion pages! [I had to keep changing it so there ^^]

    Someone should fix the gravel texture in the background. It's been years now, come on people.

  • About IC2 recipe manager. I tried to add this recipe:

    Code
    Recipes.advRecipes.addRecipe(new ItemStack(IHLMod.chargerEjectorItem,1), new Object[] { "PGP", "GCG", "GLG", Character.valueOf('P'), IC2Items.getItem("platelapi"), Character.valueOf('G'), new ItemStack(Blocks.glass,1), Character.valueOf('C'), IC2Items.getItem("glassFiberCableItem"), Character.valueOf('L'), IC2Items.getItem("lapotronCrystal")});



    No result. Nonetheless, this code is working:

    Code
    Recipes.advRecipes.addRecipe(new ItemStack(IHLMod.chargerEjectorItem,1), new Object[] { "PGP", "GCG", "G G", Character.valueOf('P'), IC2Items.getItem("platelapi"), Character.valueOf('G'), new ItemStack(Blocks.glass,1), Character.valueOf('C'), IC2Items.getItem("glassFiberCableItem")});


    It seems, that item damage is important as recipe input, although normal IC2 recipes are working with any charge level.
    How i can use items with any charge level as recipe input?

  • GregoriusT, thank you!


    Code
    ItemStack crystal = IC2Items.getItem("lapotronCrystal").copy();
    crystal.setItemDamage(OreDictionary.WILDCARD_VALUE);
    Recipes.advRecipes.addRecipe(new ItemStack(IHLMod.chargerEjectorItem,1), new Object[] { "PGP", "GCG", "GLG", Character.valueOf('P'), IC2Items.getItem("platelapi"), Character.valueOf('G'), new ItemStack(Blocks.glass,1), Character.valueOf('C'), IC2Items.getItem("glassFiberCableItem"), Character.valueOf('L'), crystal});


    Now it is working.


    P.S.:
    Khem... it was supposed to be a thread about IC2 API and addon development. I don't mind, if irrelevant questions will be erased from that thread, or moved to another section.

    • Official Post

    it was supposed to be a thread about IC2 API and addon development. I don't mind, if irrelevant questions will be erased from that thread, or moved to another section.


    Someone else might have the same problem, so it makes sense if most of the answers are in the same place.

    145 Mods isn't too many. 9 types of copper and 8 types of tin aren't too many. 3 types of coffee though?

    I know that you believe that you understood what you think I said, but I am not sure you realise that what you read was not what I meant.


    ---- Minecraft Crash Report ----
    // I just don't know what went wrong :(


    I see this too much.