Skip to content

Commit 682bb6a

Browse files
committed
dgt multiversion examplemod yeah
1 parent 4c80e16 commit 682bb6a

File tree

13 files changed

+153
-292
lines changed

13 files changed

+153
-292
lines changed

build.gradle.kts

Lines changed: 30 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,50 @@
11
@file:Suppress("UnstableApiUsage", "PropertyName")
22

3-
import org.polyfrost.gradle.util.noServerRunConfigs
4-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
3+
import dev.deftu.gradle.utils.GameSide
4+
import dev.deftu.gradle.utils.MinecraftVersion
55

6-
// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
7-
// which we use to prepare the environment.
86
plugins {
9-
kotlin("jvm")
10-
id("org.polyfrost.multi-version")
11-
id("org.polyfrost.defaults.repo")
12-
id("org.polyfrost.defaults.java")
13-
id("org.polyfrost.defaults.loom")
14-
id("com.github.johnrengelman.shadow")
15-
id("net.kyori.blossom") version "1.3.2"
16-
id("signing")
177
java
8+
kotlin("jvm")
9+
id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders.
10+
id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc.
11+
id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources.
12+
id("dev.deftu.gradle.tools.bloom") // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files.
13+
id("dev.deftu.gradle.tools.shadow") // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those!
14+
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
15+
id("dev.deftu.gradle.tools.minecraft.releases") // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth.
1816
}
1917

20-
// Gets the mod name, version and id from the `gradle.properties` file.
21-
val mod_name: String by project
22-
val mod_version: String by project
23-
val mod_id: String by project
24-
val mod_archives_name: String by project
25-
26-
// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`.
27-
blossom {
28-
replaceToken("@VER@", mod_version)
29-
replaceToken("@NAME@", mod_name)
30-
replaceToken("@ID@", mod_id)
31-
}
32-
33-
// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver!
34-
version = mod_version
35-
// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
36-
// e.g. com.github.<your username> or com.<your domain>
37-
group = "org.polyfrost"
38-
39-
// Sets the name of the output jar (the one you put in your mods folder and send to other people)
40-
// It outputs all versions of the mod into the `versions/{mcVersion}/build` directory.
41-
base {
42-
archivesName.set("$mod_archives_name-$platform")
43-
}
44-
45-
// Configures Polyfrost Loom, our plugin fork to easily set up the programming environment.
46-
loom {
47-
// Removes the server configs from IntelliJ IDEA, leaving only client runs.
48-
noServerRunConfigs()
49-
50-
// Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org)
51-
if (project.platform.isLegacyForge) {
52-
runConfigs {
53-
"client" {
54-
programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker")
55-
property("mixin.debug.export", "true") // Outputs all mixin changes to `versions/{mcVersion}/run/.mixin.out/class`
56-
}
57-
}
58-
}
59-
// Configures the mixins if we are building for forge
60-
if (project.platform.isForge) {
61-
forge {
62-
mixinConfig("mixins.${mod_id}.json")
63-
}
64-
}
65-
// Configures the name of the mixin "refmap"
66-
mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json")
67-
}
68-
69-
// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately.
70-
val shade: Configuration by configurations.creating {
71-
configurations.implementation.get().extendsFrom(this)
72-
}
73-
val modShade: Configuration by configurations.creating {
74-
configurations.modImplementation.get().extendsFrom(this)
75-
}
76-
77-
// Configures the output directory for when building from the `src/resources` directory.
78-
sourceSets {
79-
main {
80-
output.setResourcesDir(java.classesDirectory)
81-
}
82-
}
83-
84-
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
85-
repositories {
86-
maven("https://repo.polyfrost.org/releases")
87-
}
18+
toolkitLoomHelper {
19+
useOneConfig {
20+
version = "1.0.0-alpha.47"
21+
loaderVersion = "1.1.0-alpha.34"
8822

89-
// Configures the libraries/dependencies for your mod.
90-
dependencies {
91-
// Adds the OneConfig library, so we can develop with it.
92-
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+")
23+
usePolyMixin = true
24+
polyMixinVersion = "0.8.4+build.2"
9325

94-
// Adds DevAuth, which we can use to log in to Minecraft in development.
95-
modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0")
26+
applyLoaderTweaker = true
9627

97-
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier, as well as mixin 0.7.11
98-
if (platform.isLegacyForge) {
99-
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
100-
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17")
101-
}
102-
}
103-
104-
tasks {
105-
// Processes the `src/resources/mcmod.info`, `fabric.mod.json`, or `mixins.${mod_id}.json` and replaces
106-
// the mod id, name and version with the ones in `gradle.properties`
107-
processResources {
108-
inputs.property("id", mod_id)
109-
inputs.property("name", mod_name)
110-
val java = if (project.platform.mcMinor >= 18) {
111-
17 // If we are playing on version 1.18, set the java version to 17
112-
} else {
113-
// Else if we are playing on version 1.17, use java 16.
114-
if (project.platform.mcMinor == 17)
115-
16
116-
else
117-
8 // For all previous versions, we **need** java 8 (for Forge support).
118-
}
119-
val compatLevel = "JAVA_${java}"
120-
inputs.property("java", java)
121-
inputs.property("java_level", compatLevel)
122-
inputs.property("version", mod_version)
123-
inputs.property("mcVersionStr", project.platform.mcVersionStr)
124-
filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) {
125-
expand(
126-
mapOf(
127-
"id" to mod_id,
128-
"name" to mod_name,
129-
"java" to java,
130-
"java_level" to compatLevel,
131-
"version" to mod_version,
132-
"mcVersionStr" to project.platform.mcVersionStr
133-
)
134-
)
135-
}
136-
filesMatching("fabric.mod.json") {
137-
expand(
138-
mapOf(
139-
"id" to mod_id,
140-
"name" to mod_name,
141-
"java" to java,
142-
"java_level" to compatLevel,
143-
"version" to mod_version,
144-
"mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x"
145-
)
146-
)
28+
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
29+
+module
14730
}
14831
}
14932

150-
// Configures the resources to include if we are building for forge or fabric.
151-
withType(Jar::class.java) {
152-
if (project.platform.isFabric) {
153-
exclude("mcmod.info", "mods.toml")
154-
} else {
155-
exclude("fabric.mod.json")
156-
if (project.platform.isLegacyForge) {
157-
exclude("mods.toml")
158-
} else {
159-
exclude("mcmod.info")
160-
}
161-
}
162-
}
33+
// Turns off the server-side run configs, as we're building a client-sided mod.
34+
disableRunConfigs(GameSide.SERVER)
16335

164-
// Configures our shadow/shade configuration, so we can
165-
// include some dependencies within our mod jar file.
166-
named<ShadowJar>("shadowJar") {
167-
archiveClassifier.set("dev")
168-
configurations = listOf(shade, modShade)
169-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
36+
// Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes.
37+
if (!mcData.isNeoForge) {
38+
useMixinRefMap(modData.id)
17039
}
17140

172-
remapJar {
173-
inputFile.set(shadowJar.get().archiveFile)
174-
archiveClassifier.set("")
41+
if (mcData.isForge) {
42+
// Configures the Mixin tweaker if we are building for Forge.
43+
useForgeMixin(modData.id)
17544
}
17645

177-
jar {
178-
// Sets the jar manifest attributes.
179-
if (platform.isLegacyForge) {
180-
manifest.attributes += mapOf(
181-
"ModSide" to "CLIENT", // We aren't developing a server-side mod
182-
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so.
183-
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
184-
"MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here.
185-
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
186-
)
187-
}
188-
dependsOn(shadowJar)
189-
archiveClassifier.set("")
190-
enabled = false
46+
// Sets up the KotlinForForge library for Forge 1.16.5+ and NeoForge.
47+
if (mcData.isForgeLike && mcData.version >= MinecraftVersion.VERSION_1_16_5) {
48+
useKotlinForForge()
19149
}
19250
}

gradle.properties

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.
2-
3-
# Sets the name of your mod.
4-
mod_name=ExampleMod
5-
# Sets the id of your mod that mod loaders use to recognize it.
6-
mod_id=examplemod
7-
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
8-
mod_version=1.0.0
9-
# Sets the name of the jar file that you put in your 'mods' folder.
10-
mod_archives_name=ExampleMod
11-
121
# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
13-
polyfrost.defaults.loom=3
142
org.gradle.daemon=true
153
org.gradle.parallel=true
164
org.gradle.configureoncommand=true
175
org.gradle.parallel.threads=4
18-
org.gradle.jvmargs=-Xmx2G
6+
org.gradle.jvmargs=-Xmx2G
7+
8+
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT.
9+
10+
# Sets the name of your mod.
11+
mod.name=ExampleMod
12+
# Sets the ID of your mod that mod loaders use to recognize it.
13+
mod.id=examplemod
14+
# Sets the version of your mod. Make sure to update this when you make changes according to the SemVer specification.
15+
mod.version=1.0.0
16+
# Sets the Maven group ID of your mod. This is effectively unused but is good practice to set regardless.
17+
mod.group=com.example

root.gradle.kts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
plugins {
2-
kotlin("jvm") version "1.9.10" apply false
3-
id("org.polyfrost.multi-version.root")
4-
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
2+
id("dev.deftu.gradle.multiversion-root")
53
}
64

75
preprocess {
8-
"1.12.2-forge"(11202, "srg") {
9-
"1.8.9-forge"(10809, "srg")
10-
}
11-
}
6+
// Adding new versions/loaders can be done like so:
7+
// For each version, we add a new wrapper around the last from highest to lowest.
8+
// Each mod loader needs to link up to the previous version's mod loader so that the mappings can be processed from the previous version.
9+
// "1.12.2-forge"(11202, "srg") {
10+
// "1.8.9-forge"(10809, "srg")
11+
// }
12+
13+
"1.8.9-forge"(10809, "srg")
14+
}

settings.gradle.kts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
11
@file:Suppress("PropertyName")
22

3+
import groovy.lang.MissingPropertyException
4+
35
pluginManagement {
46
repositories {
7+
// Releases
8+
maven("https://maven.deftu.dev/releases")
9+
maven("https://maven.fabricmc.net")
10+
maven("https://maven.architectury.dev/")
11+
maven("https://maven.minecraftforge.net")
12+
maven("https://repo.essential.gg/repository/maven-public")
13+
maven("https://server.bbkr.space/artifactory/libs-release/")
14+
maven("https://jitpack.io/")
15+
16+
// Snapshots
17+
maven("https://maven.deftu.dev/snapshots")
18+
mavenLocal()
19+
20+
// Default
521
gradlePluginPortal()
622
mavenCentral()
7-
maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit
823
}
24+
925
plugins {
10-
val pgtVersion = "0.6.5" // Sets the default versions for Polyfrost Gradle Toolkit
11-
id("org.polyfrost.multi-version.root") version pgtVersion
26+
kotlin("jvm") version("2.0.0")
27+
id("dev.deftu.gradle.multiversion-root") version("2.17.0")
1228
}
1329
}
1430

15-
val mod_name: String by settings
31+
val projectName: String = extra["mod.name"]?.toString()
32+
?: throw MissingPropertyException("mod.name has not been set.")
1633

1734
// Configures the root project Gradle name based on the value in `gradle.properties`
18-
rootProject.name = mod_name
35+
rootProject.name = projectName
1936
rootProject.buildFileName = "root.gradle.kts"
2037

2138
// Adds all of our build target versions to the classpath if we need to add version-specific code.
39+
// Update this list if you want to remove/add a version and/or mod loader.
40+
// The format is: version-modloader (f.ex: 1.8.9-forge, 1.17.1-fabric, etc)
41+
// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` AND `build.gradle.kts` FILES WITH THE NEW VERSION(S).
2242
listOf(
23-
"1.8.9-forge", // Update this if you want to remove/add a version, along with `build.gradle.kts` and `root.gradle.kts`.
24-
//"1.12.2-forge" // uncomment if you want 1.12.2 support in your mod
43+
"1.8.9-forge",
44+
// ...
2545
).forEach { version ->
2646
include(":$version")
2747
project(":$version").apply {
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
package org.polyfrost.example;
22

33
import org.polyfrost.example.command.ExampleCommand;
4-
import org.polyfrost.example.config.TestConfig;
5-
import cc.polyfrost.oneconfig.events.event.InitializationEvent;
4+
import org.polyfrost.example.config.ExampleConfig;
65
import net.minecraftforge.fml.common.Mod;
7-
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
86
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
7+
import org.polyfrost.oneconfig.api.commands.v1.CommandManager;
98

109
/**
11-
* The entrypoint of the Example Mod that initializes it.
10+
* The entrypoint of the Example Mod which initializes it.
11+
* This is what is run when the game is started and typically how your mod will set up its functionality.
1212
*
1313
* @see Mod
14-
* @see InitializationEvent
1514
*/
16-
@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION)
15+
@Mod(modid = ExampleMod.ID, name = ExampleMod.NAME, version = ExampleMod.VERSION)
1716
public class ExampleMod {
1817

19-
// Sets the variables from `gradle.properties`. See the `blossom` config in `build.gradle.kts`.
20-
public static final String MODID = "@ID@";
21-
public static final String NAME = "@NAME@";
22-
public static final String VERSION = "@VER@";
23-
@Mod.Instance(MODID)
18+
// Sets the variables from `gradle.properties`. Depends on the `bloom` DGT plugin.
19+
public static final String ID = "@MOD_ID@";
20+
public static final String NAME = "@MOD_NAME@";
21+
public static final String VERSION = "@MOD_VERSION@";
22+
23+
@Mod.Instance(ID)
2424
public static ExampleMod INSTANCE; // Adds the instance of the mod, so we can access other variables.
25-
public static TestConfig config;
25+
26+
private static ExampleConfig config;
2627

2728
// Register the config and commands.
2829
@Mod.EventHandler
2930
public void onInit(FMLInitializationEvent event) {
30-
config = new TestConfig();
31-
CommandManager.INSTANCE.registerCommand(new ExampleCommand());
31+
config = new ExampleConfig();
32+
CommandManager.registerCommand(new ExampleCommand());
3233
}
34+
35+
public static ExampleConfig getConfig() {
36+
return config;
37+
}
38+
3339
}

src/main/java/org/polyfrost/example/command/ExampleCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @see Main
1313
* @see ExampleMod
1414
*/
15-
@Command(value = ExampleMod.MODID, description = "Access the " + ExampleMod.NAME + " GUI.")
15+
@Command(value = ExampleMod.ID, description = "Access the " + ExampleMod.NAME + " GUI.")
1616
public class ExampleCommand {
1717
@Main
1818
private void handle() {

0 commit comments

Comments
 (0)