In this repository you will find information and instructions on how you can code a Minecraft mod in Groovy.
I am not sure if this is actually the way to do this - all I know is it works and it's currently passing
my somewhat shitty tests. Use at your own risk!
-
Apply the 'groovy' plugin.
apply plugin: 'groovy
-
Add shading configurations.
configurations { shade compile.extendsFrom shade }
-
Add groovy to the dependencies.
dependencies { shade 'org.codehaus.groovy:groovy-all:x.x.x' }
You should obviously change the
x.x.x
to an actual version number like2.4.4
-
Add this jar config
jar { configurations.shade.each { dep -> from(project.zipTree(dep)){ exclude 'META-INF', 'META-INF/**' } } }
-
Last block of code we'll add to our
build.gradle
file issourceSets { main { groovy { srcDirs = ['src/main/groovy'] } } }
-
Re-run your gradle tasks and open your IDE
-
Create two source directories for both java and groovy. E.g.
Root \- src/main/java \- src/main/groovy
If they aren't already, mark them as source directories.
-
Create a package in the
java
source dir.yourname.dev
-
New File-> Java Class -> Give it a valid name. I chose
OpenMe.java
- and leave the class completely empty. The reason for this is ForgeGradle will not be able to build your project if it can't find any java classes insrc/main/java
, I do not know enough about the whole building process to go into details. -
Create a package in the
groovy
source dir.com.yourname.modid
. -
New File-> Groovy Class -> Give it a valid name. I chose my mod name. E.g.
GroovyModExample.groovy
-
Annotate the class with the usual @Mod annotation and go on from here. Look in this repository for working examples.
Look for the build.gradle script in this repository if you want to see the final outcome.
Any class or method where you're referencing Mojang code/deobfuscated code you HAVE to annotate with @CompileStatic. Here are some links where you can read more about the @CompileStatic annotation