makamys / MCLib

Shadeable library containing code for use in multiple Minecraft mods (1.7.10)
The Unlicense
0 stars 3 forks source link

MCLib

This is a library that can be shaded into Minecraft mods.

What's inside?

Shared modules

When multiple mods with MCLib embedded are present, calls to shared modules from all mods are redirected to whichever mod has the newest version of the given module.

Helper classes

Usage

Adding the dependency

Releases are published on JitPack. To use this library in your mod, add this to your buildscript:

repositories {
    maven { url 'https://jitpack.io' }
}

minecraft {
    srgExtra "PK: makamys/mclib <YOUR/MOD/PACKAGE>/repackage/makamys/mclib"
}

dependencies {
    shade('com.github.makamys:MCLib:<VERSION>'){
        exclude group: "codechicken"
    }
}

In place of <VERSION>, use a release number (e.g. 0.3.4).

A commit hash can also be used, but doing this in production is discouraged as it may make MCLib unable to correctly select the highest version of the library.

Shade configuration

The above snippet assumes there is a shade configuration in your build script. If there isn't, you can use the below one as an example (the configurations block has to go before the dependencies block). For additional explanation on what this does, see ForgeGradle's shading tutorial.

configurations {
    shade
    compile.extendsFrom shade
}

jar {
    configurations.shade.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}

Using the library

The library first has to be initialized by calling MCLib.init() in the mod construction phase. You can do this like this in your mod class:

@EventHandler
public void onConstruction(FMLConstructionEvent event) {
    MCLib.init();
}

Static helper classes like SloppyDepLoader can be used by simply calling their static methods.

Shared modules like UpdateCheck require special setup via their respective *API classes (e.g. UpdateCheckAPI). See the example test files above to see how to use them.

Check the wiki for more documentation.

If you want to see some examples of the library in action, see Satchels and Et Futurum Requiem.

Contributing

The library has some test packages containing test mods that test its features. These packages are excluded from builds normally. To enable them, add -Ptest_<library name> to your Gradle command. See project.gradle for the available flags.

License

See LICENSE.md.