Skip to content

Setting up PanelStudio

lukflug edited this page Jun 10, 2023 · 6 revisions

This page describes how to correctly modify your build.gradle file for your Minecraft mod, so that it correctly links to PanelStudio and is able to use PanelStudio classes and interfaces. See the build.gradle files in the example mods for a complete example.

Including PanelStudio as Gradle dependency

First Gradle needs to know where to pull the dependencies from, so you need to add PanelStudio's maven repository to the repositories list (the one outside of buildscript). Make sure it is listed after the Forge repository. In addition, you need to actually add dependencies:

// [...]

repositories {
	// other repositories here
	maven {
		name = "lukflug"
		url = "https://lukflug.github.io/maven/"
	}
}

// [...]

dependencies {
	// other dependencies here
	// make sure to replace the version number by the newest version
	implementation "com.lukflug:panelstudio:0.2.4" // you may want to replace "implementation" by "shadow" (see next section)
	// replace mc12 by mc8-fabric, mc8-forge, mc12, mc16-fabric, mc16-forge, mc17 depending on the Minecraft version you are using
	implementation "com.lukflug:panelstudio-mc12:0.2.4" // you may want to replace "implementation" by "shadow" (see next section)
}

// [...]

Producing a JAR file

For Gradle to actually produce a jar file that you can distribute as a Minecraft mod, you may need to include the libraries you use in that jar. There are multiple ways to do it, but it is typically done using the shadow Gradle plugin. In particular, you want to include PanelStudio in your jar. This can be done by adding a new configuration (shadow here, but may be called anything else):

// [...]

configurations {
	// [...]
	shadow
	implementation.extendsFrom shadow
}

// [...]

dependencies {
	// other dependencies here
	// make sure to replace the version number by the newest version
	shadow "com.lukflug:panelstudio:0.2.4"
	// replace mc12 by mc8-fabric, mc8-forge, mc12, mc16-fabric, mc16-forge, mc17 depending on the Minecraft version you are using
	shadow "com.lukflug:panelstudio-mc12:0.2.4"
}

// [...]

shadowJar {
	classifier = "dev" // FABRIC ONLY
	classifier = "" // FORGE ONLY
	configurations = [project.configurations.shadow]
	// it is recommended to relocated the PanelStudio package for compatibility with past and future versions
	relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_1"
}

// [...]

You will need to add some extra stuff (so that the jar is reobfuscated correctly) depending on what Minecraft Gradle plugin you use:

// ForgeGradle 2.x
reobf {
	shadowJar{
		mappingType = "SEARGE"
		classpath = sourceSets.main.compileClasspath
	}
}

// ForgeGradle 3.x and newer
reobf {
	shadowJar{}
}

// Fabric-Loom 0.7.x
remapJar.dependsOn(shadowJar)

// Fabric-Loom 0.12.x
remapJar {
	dependsOn shadowJar
	inputFile = shadowJar.archiveFile
}

In the example mod I had a weird issue with Minecraft Forge 1.16.5 on ForgeGradle 5.1, where I had to work around it, by adding an extra configuration to extract the PanelStudio-MC jar along with the other classes of the mod (analogous workarounds probably work on other Minecraft versions, though hopefully they are not necessary):

// [...]

configurations {
	// [...]
	compileClasspath.extendsFrom extract
	shadow
	implementation.extendsFrom shadow
}

// [...]

dependencies {
	// other dependencies here
	// make sure to replace the version number by the newest version
	shadow "com.lukflug:panelstudio:0.2.4"
	extract "com.lukflug:panelstudio-mc16-forge:0.2.4"
}

task extract (type:Copy) {
	from({zipTree(configurations.extract.singleFile)}) {exclude "META-INF/"}
	into "$buildDir/classes/java/main"
}

// [...]

compileJava.finalizedBy("extract")

shadowJar {
	classifier = ""
	configurations = [project.configurations.shadow]
	relocate "com.lukflug.panelstudio","com.lukflug.panelstudio_0_2_4"
}

reobf {
	shadowJar{}
}

You may already be using shadowJar in other ways, so you may want to adapt the above recipes, in order to make it more compatible with your existing build.gradle file. After you are finished, you should be able to reload Gradle in your IDE of choice, and be able to use PanelStudio classes without any compile time error.

Conclusion

If everything works and you are properly able to use PanelStudio methods and classes, and it compiles and runs correctly in your development environment and the Minecraft launcher, congratulations! You have finished the hardest part.

Clone this wiki locally