Skip to content

Commit 08637fe

Browse files
committed
Full rewrite, V1 port and Legacy Fabric port
1 parent 67d4976 commit 08637fe

25 files changed

+567
-463
lines changed

build.gradle.kts

Lines changed: 36 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,59 @@
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
54

6-
// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
7-
// which we use to prepare the environment.
85
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.1"
16-
id("signing")
176
java
7+
kotlin("jvm")
8+
id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders.
9+
id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc.
10+
id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources.
11+
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.
12+
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!
13+
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
14+
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.
1815
}
1916

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-
// Sets up the variables for when we preprocess to other Minecraft versions.
27-
preprocess {
28-
vars.put("MODERN", if (project.platform.mcMinor >= 16) 1 else 0)
29-
}
30-
31-
// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`.
32-
blossom {
33-
replaceToken("@VER@", mod_version)
34-
replaceToken("@NAME@", mod_name)
35-
replaceToken("@ID@", mod_id)
36-
}
37-
38-
// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver!
39-
version = mod_version
40-
// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
41-
// e.g. com.github.<your username> or com.<your domain>
42-
group = "org.polyfrost"
17+
toolkitLoomHelper {
18+
useOneConfig {
19+
version = "1.0.0-alpha.55"
20+
loaderVersion = "1.1.0-alpha.35"
4321

44-
// Sets the name of the output jar (the one you put in your mods folder and send to other people)
45-
// It outputs all versions of the mod into the `build` directory.
46-
base {
47-
archivesName.set("$mod_archives_name-$platform")
48-
}
22+
usePolyMixin = true
23+
polyMixinVersion = "0.8.4+build.2"
4924

50-
// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
51-
loom {
52-
// Removes the server configs from IntelliJ IDEA, leaving only client runs.
53-
// If you're developing a server-side mod, you can remove this line.
54-
noServerRunConfigs()
25+
applyLoaderTweaker = true
5526

56-
// Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org)
57-
if (project.platform.isLegacyForge) {
58-
runConfigs {
59-
"client" {
60-
programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker")
61-
property("mixin.debug.export", "true")
62-
}
27+
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
28+
+module
6329
}
6430
}
65-
// Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
66-
if (project.platform.isForge) {
67-
forge {
68-
mixinConfig("mixins.${mod_id}.json")
69-
}
70-
}
71-
// Configures the name of the mixin "refmap" using an experimental loom api.
72-
mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json")
73-
}
31+
useDevAuth("1.2.1")
32+
useMixinExtras("0.4.1")
7433

75-
// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately.
76-
val shade: Configuration by configurations.creating {
77-
configurations.implementation.get().extendsFrom(this)
78-
}
34+
// Turns off the server-side run configs, as we're building a client-sided mod.
35+
disableRunConfigs(GameSide.SERVER)
7936

80-
// Configures the output directory for when building from the `src/resources` directory.
81-
sourceSets {
82-
main {
83-
output.setResourcesDir(java.classesDirectory)
37+
// Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes.
38+
if (!mcData.isNeoForge) {
39+
useMixinRefMap(modData.id)
8440
}
85-
}
86-
87-
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
88-
repositories {
89-
maven("https://repo.polyfrost.org/releases")
90-
}
91-
92-
// Configures the libraries/dependencies for your mod.
93-
dependencies {
94-
// Adds the OneConfig library, so we can develop with it.
95-
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.1-alpha+")
96-
97-
modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.1.2")
9841

99-
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
100-
if (platform.isLegacyForge) {
101-
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
102-
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+")
42+
if (mcData.isForge) {
43+
// Configures the Mixin tweaker if we are building for Forge.
44+
useForgeMixin(modData.id)
10345
}
10446
}
10547

106-
tasks {
107-
// Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces
108-
// the mod id, name and version with the ones in `gradle.properties`
109-
processResources {
110-
inputs.property("id", mod_id)
111-
inputs.property("name", mod_name)
112-
val java = if (project.platform.mcMinor >= 18) {
113-
17 // If we are playing on version 1.18, set the java version to 17
114-
} else {
115-
// Else if we are playing on version 1.17, use java 16.
116-
if (project.platform.mcMinor == 17)
117-
16
118-
else
119-
8 // For all previous versions, we **need** java 8 (for Forge support).
120-
}
121-
val compatLevel = "JAVA_${java}"
122-
inputs.property("java", java)
123-
inputs.property("java_level", compatLevel)
124-
inputs.property("version", mod_version)
125-
inputs.property("mcVersionStr", project.platform.mcVersionStr)
126-
filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) {
127-
expand(
128-
mapOf(
129-
"id" to mod_id,
130-
"name" to mod_name,
131-
"java" to java,
132-
"java_level" to compatLevel,
133-
"version" to mod_version,
134-
"mcVersionStr" to project.platform.mcVersionStr
135-
)
136-
)
137-
}
138-
filesMatching("fabric.mod.json") {
139-
expand(
140-
mapOf(
141-
"id" to mod_id,
142-
"name" to mod_name,
143-
"java" to java,
144-
"java_level" to compatLevel,
145-
"version" to mod_version,
146-
"mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x"
147-
)
148-
)
149-
}
150-
}
151-
152-
// Configures the resources to include if we are building for forge or fabric.
153-
withType(Jar::class.java) {
154-
if (project.platform.isFabric) {
155-
exclude("mcmod.info", "mods.toml")
48+
dependencies {
49+
// Add (Legacy) Fabric API as dependencies (these are both optional but are particularly useful).
50+
if (mcData.isFabric) {
51+
if (mcData.isLegacyFabric) {
52+
// 1.8.9 - 1.13
53+
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}")
15654
} else {
157-
exclude("fabric.mod.json")
158-
if (project.platform.isLegacyForge) {
159-
exclude("mods.toml")
160-
} else {
161-
exclude("mcmod.info")
162-
}
163-
}
164-
}
165-
166-
// Configures our shadow/shade configuration, so we can
167-
// include some dependencies within our mod jar file.
168-
named<ShadowJar>("shadowJar") {
169-
archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix.
170-
configurations = listOf(shade)
171-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
172-
}
173-
174-
remapJar {
175-
inputFile.set(shadowJar.get().archiveFile)
176-
archiveClassifier.set("")
177-
}
178-
179-
jar {
180-
// Sets the jar manifest attributes.
181-
if (platform.isLegacyForge) {
182-
manifest.attributes += mapOf(
183-
"ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine.
184-
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so.
185-
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
186-
"MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here.
187-
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
188-
)
55+
// 1.16.5+
56+
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}")
18957
}
190-
dependsOn(shadowJar)
191-
archiveClassifier.set("")
192-
enabled = false
19358
}
19459
}

gradle.properties

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
mod_name = PolyWeather
2-
mod_id = polyweather
3-
mod_version = 1.0.0
4-
mod_archives_name=PolyWeather
5-
61
# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
72
polyfrost.defaults.loom=1
83
org.gradle.daemon=true
94
org.gradle.parallel=true
105
org.gradle.configureoncommand=true
116
org.gradle.parallel.threads=4
12-
org.gradle.jvmargs=-Xmx2G
7+
org.gradle.jvmargs=-Xmx2G
8+
9+
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT.
10+
11+
# Sets the name of your mod.
12+
mod.name=PolyWeather
13+
# Sets the ID of your mod that mod loaders use to recognize it.
14+
mod.id=polyweather
15+
# Sets the version of your mod. Make sure to update this when you make changes according to the SemVer specification.
16+
mod.version=1.0.0
17+
# Sets the Maven group ID of your mod. This is effectively unused but is good practice to set regardless.
18+
mod.group=org.polyfrost
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

root.gradle.kts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
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 "7.1.2" 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")
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.12.2-fabric"(11202, "yarn") {
14+
"1.12.2-forge"(11202, "srg") {
15+
"1.8.9-forge"(10809, "srg") {
16+
"1.8.9-fabric"(10809, "yarn")
17+
}
18+
}
1019
}
20+
21+
strictExtraMappings.set(true)
1122
}

settings.gradle.kts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
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.2.9" // 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.18.1")
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` FILE 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"
43+
"1.8.9-forge",
44+
"1.8.9-fabric",
45+
"1.12.2-fabric",
46+
"1.12.2-forge",
2547
).forEach { version ->
2648
include(":$version")
2749
project(":$version").apply {

src/main/java/org/polyfrost/polyweather/mixin/EntityRendererMixin.java renamed to src/main/java/org/polyfrost/polyweather/mixin/Mixin_EntityRenderer_ForceRainAndSnowParticles.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package org.polyfrost.polyweather.mixin;
22

33
import net.minecraft.client.renderer.EntityRenderer;
4-
import org.polyfrost.polyweather.PolyWeather;
5-
import org.polyfrost.polyweather.config.ModConfig;
4+
import org.polyfrost.polyweather.client.PolyWeatherClient;
5+
import org.polyfrost.polyweather.client.PolyWeatherConfig;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.At;
88
import org.spongepowered.asm.mixin.injection.Inject;
99
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1010

1111
@Mixin(EntityRenderer.class)
12-
public class EntityRendererMixin {
12+
public class Mixin_EntityRenderer_ForceRainAndSnowParticles {
1313

1414
@Inject(method = "addRainParticles", at = @At("HEAD"), cancellable = true)
1515
private void addRainParticles(CallbackInfo ci) {
16-
if (ModConfig.INSTANCE.enabled && (!PolyWeather.INSTANCE.isRaining() || PolyWeather.INSTANCE.isSnowing())) {
16+
if (PolyWeatherConfig.INSTANCE.enabled && (!PolyWeatherClient.isRaining() || PolyWeatherClient.isSnowing())) {
1717
ci.cancel();
1818
}
1919
}

0 commit comments

Comments
 (0)