Code Monkey home page Code Monkey logo

forgelin's Introduction

Kotlin Adapter for Minecraft Forge

Kotlin support for Minecraft Forge 1.8-11.14.1.1371 or above

Build Status

Using the Adapter

The basic workflow for using the Adapter in your project is;

  1. Either shade (and repack) the adapter jar or manually copy the adapter + helpers you want into your project
  2. Shade (via a Gradle plugin or with ForgeGradle trickery) the version of Kotlin you want
  3. Hack away

Buildscript Preparation

These instructions are for FG 2.1+.

We require the Kotlin and Forge plugins to be enabled in build.gradle:

buildscript {
	[...]
	dependencies {
		[...]
		classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.1"
	}
	[...]
}

repositories {
	[...]
	// For Kotlin lang adapter
	maven {
		name 'Tethys'
		url 'http://tethys.drakon.io/maven'
	}
}

apply plugin: 'kotlin'
apply plugin: 'net.minecraftforge.gradle.forge'
[...]

Repackaging

This technique requires tinkering with your build.gradle file.

As a second warning: Doing this wrong could break other Kotlin-based mods!

Now the warnings are out the way, we're going to use a technique called shading combined with repacking. Built jars of the adapter do not come with Kotlin installations. This means your mod must include its own, repackaged version.

First, we need to add a new configuration:

configurations {
    shade
    compile.extendsFrom shade
}

Then on the lines where you would normally define compile in the main dependencies block for Kotlin, replace compile with shade - below is an example dependency block (for Kotlin 1.0.1.) If you need the kotlin-reflect library, add that in the same way (but be aware this'll add >1MB to your jar size!)

dependencies {
	shade 'org.jetbrains.kotlin:kotlin-stdlib:1.0.1'
	shade 'io.drakon.forge:kotlin-adapter:1.0.1+1.8.9'
}

Next, tell Gradle what to do with this new shade configuration inside the jar {} block:

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

Finally, ask ForgeGradle to add some extra rules for reobfuscation, to avoid namespace issues with other Kotlin versions that may be on the classpath:

reobf {
    jar {
	    // Kotlin+Adapter shading
	    extraLines += [ "PK: kotlin your/package/here/repack/kotlin" ]
	    extraLines += [ "PK: org/jetbrains/annotations your/package/here/repack/annotations" ]
	    extraLines += [ "PK: io/drakon/forge/kotlin your/package/here/repack/adapter" ]
	}
}

The destination package (your/package/here/repack for this example) can be any package you think won't clash, either with your code or anybody else's packages. As in the example, package paths use forward slash (/) in PK lines.

Your @Mod implementation must be an object. There is no reason to make it a class and the adapter will not work if you do so.

Licenses

The Kotlin Adapter is licensed under the ISC License (see LICENSE), which is just a modernised version of the MIT License.

Kotlin is property of Jetbrains. Look at their site for licensing bumf.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.