diff --git a/build.gradle.kts b/build.gradle.kts index 7338143..229d1cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,11 @@ plugins { - id("xyz.deftu.gradle.multiversion-root") +// `kotlin-dsl` + id("xyz.deftu.gradle.preprocess-root") version "0.4.1" + id("xyz.wagyourtail.unimined") version "1.0.6-SNAPSHOT" apply false +} + +repositories { + mavenCentral() } preprocess { @@ -28,4 +34,16 @@ preprocess { fabric11701.link(fabric11605) fabric11605.link(forge11605) fabric11605.link(fabric11601) + +// subprojects { +// apply(plugin = "java") +// if (name == "1.20.1-fabric") { +// sourceSets.main { +// java { +// srcDir("$rootDir/src/main/java") +// } +// } +// } +// } } + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fc..db9a6b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 54c12b5..3ac2afd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,9 +4,11 @@ pluginManagement { maven("https://maven.fabricmc.net") maven("https://maven.architectury.dev/") maven("https://maven.minecraftforge.net") + maven("https://maven.neoforged.net/releases") maven("https://repo.essential.gg/repository/maven-public") maven("https://maven.jab125.dev/") - + maven("https://maven.wagyourtail.xyz/snapshots") + maven("https://maven.wagyourtail.xyz/releases") gradlePluginPortal() mavenCentral() } @@ -37,6 +39,7 @@ listOf( include(":$version") project(":$version").apply { projectDir = file("versions/$version") + projectDir.mkdirs() buildFileName = "../../version.gradle.kts" } } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinJoinMultiplayerScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinJoinMultiplayerScreen.java index 2bcad48..3e67ecd 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinJoinMultiplayerScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinJoinMultiplayerScreen.java @@ -31,7 +31,7 @@ protected MixinJoinMultiplayerScreen(Component component) { super(component); } - @Inject(method = "init", at = @At("TAIL")) + @Inject(method = "init*", at = @At("TAIL")) private void tabs(CallbackInfo ci) { if (!WorldHost.CONFIG.isEnableFriends()) return; @@ -51,7 +51,7 @@ private void tabs(CallbackInfo ci) { )); } - @ModifyConstant(method = "init", constant = @Constant(intValue = 32)) + @ModifyConstant(method = "init*", constant = @Constant(intValue = 32)) private int makeTopBigger(int constant) { return WorldHost.CONFIG.isEnableFriends() ? 60 : constant; } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java index b15af99..6d1ff35 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java @@ -28,18 +28,18 @@ protected MixinSelectWorldScreen(Component component) { super(component); } - @ModifyConstant(method = "init", constant = @Constant(stringValue = "selectWorld.select")) + @ModifyConstant(method = "init*", constant = @Constant(stringValue = "selectWorld.select")) private String changePlayButtonText(String constant) { return WorldHost.CONFIG.isShareButton() ? "world-host.play_world" : constant; } - @ModifyConstant(method = "init", constant = @Constant(intValue = 150, ordinal = 0)) + @ModifyConstant(method = "init*", constant = @Constant(intValue = 150, ordinal = 0)) private int shrinkPlayButton(int constant) { return WorldHost.CONFIG.isShareButton() ? 100 : constant; } @Inject( - method = "init", + method = "init*", at = @At( value = "INVOKE", //#if MC > 1.16.5 @@ -70,17 +70,17 @@ private void addShareWorldButton(CallbackInfo ci) { ); } - @ModifyConstant(method = "init", constant = @Constant(intValue = 4, ordinal = 0)) + @ModifyConstant(method = "init*", constant = @Constant(intValue = 4, ordinal = 0)) private int moveCreateButton(int constant) { return WorldHost.CONFIG.isShareButton() ? 54 : constant; } - @ModifyConstant(method = "init", constant = @Constant(intValue = 150, ordinal = 1)) + @ModifyConstant(method = "init*", constant = @Constant(intValue = 150, ordinal = 1)) private int shrinkCreateButton(int constant) { return WorldHost.CONFIG.isShareButton() ? 100 : constant; } - @ModifyConstant(method = "init", constant = @Constant(stringValue = "selectWorld.create")) + @ModifyConstant(method = "init*", constant = @Constant(stringValue = "selectWorld.create")) private String changeCreateButtonText(String constant) { return WorldHost.CONFIG.isShareButton() ? "world-host.create_world" : constant; } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java index 9dc1538..a7b783f 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java @@ -15,12 +15,12 @@ @Mixin(ShareToLanScreen.class) public class MixinShareToLanScreen { - @ModifyConstant(method = "", constant = @Constant(stringValue = "lanServer.title")) + @ModifyConstant(method = "*", constant = @Constant(stringValue = "lanServer.title")) private static String changeLabelI1(String constant) { return WorldHost.CONFIG.isEnableFriends() ? "world-host.open_world" : "world-host.open_world_no_friends"; } - @ModifyConstant(method = "init", constant = @Constant(stringValue = "lanServer.start")) + @ModifyConstant(method = "init*", constant = @Constant(stringValue = "lanServer.start")) private String changeLabelI2(String constant) { return WorldHost.CONFIG.isEnableFriends() ? "world-host.open_world" : "world-host.open_world_no_friends"; } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/modmenu/MixinModMenuEventHandler.java b/src/main/java/io/github/gaming32/worldhost/mixin/modmenu/MixinModMenuEventHandler.java index 442570d..02f4c2b 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/modmenu/MixinModMenuEventHandler.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/modmenu/MixinModMenuEventHandler.java @@ -1,10 +1,9 @@ +//#if FABRIC && MC > 1.16.1 package io.github.gaming32.worldhost.mixin.modmenu; -import org.spongepowered.asm.mixin.Mixin; - -//#if FABRIC && MC > 1.16.1 import com.terraformersmc.modmenu.event.ModMenuEventHandler; import io.github.gaming32.worldhost.gui.widget.OnlineStatusButton; +import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -33,11 +32,4 @@ private static void dontShiftOnlineStatus(LayoutElement widget, boolean shiftUp, //$$ } //#endif } -//#else -//$$ // Fallback so that there is *some* mixin class to load -//$$ import net.minecraft.client.Minecraft; -//$$ -//$$ @Mixin(Minecraft.class) -//$$ public class MixinModMenuEventHandler { -//$$ } //#endif diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 4397950..c3068b6 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -4,22 +4,22 @@ issueTrackerURL = "https://github.com/Gaming32/world-host/issues" license = "MIT" [[mods]] -modId = "${mod_id.replace('-', '_')}" -version = "$mod_version" -displayName = "$mod_name" +modId = "world_host" +version = "$version" +displayName = "World Host" displayURL = "https://modrinth.com/mod/world-host" logoFile = "icon.png" authors = "Gaming32" description = "Host your singleplayer worlds without having to run a server or setup port forwarding! In the future, we also plan to support Bedrock Edition clients through the use of Geyser." -[[dependencies.$mod_id]] +[[dependencies.world_host]] modId = "forge" mandatory = true versionRange = "[32,)" ordering = "NONE" side = "BOTH" -[[dependencies.$mod_id]] +[[dependencies.world_host]] modId = "minecraft" mandatory = true versionRange = "$mc_version" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f2c2a04..0dfd36b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,8 +1,8 @@ { "schemaVersion": 1, - "id": "$mod_id", - "name": "$mod_name", - "version": "$mod_version", + "id": "world-host", + "name": "World Host", + "version": "$version", "description": "Host your singleplayer worlds without having to run a server or setup port forwarding! In the future, we also plan to support Bedrock Edition clients through the use of Geyser.", "authors": [ "Gaming32" @@ -28,13 +28,23 @@ ], "depends": { "fabricloader": "*", - "minecraft": "${mc_version == '1.19.4' ? '>=1.19.4 <1.20' : mc_version == '1.20.1' ? '>=1.20- <1.20.2' : mc_version}", + //#if MC == 1.19.4 + //?? "minecraft": ">=1.19.4 <1.20", + //#elseif MC == 1.20.1 + //?? "minecraft": ">=1.20- <1.20.2", + //#else + "minecraft": "$mc_version", + //#endif "fabric-resource-loader-v0": "*" }, "breaks": { - ${mc_version == '1.19.4' ? '"modmenu": "<6.2.0"' : ''} + //#if MC == 1.19.4 + "modmenu": "<6.2.0" + //#endif }, "suggests": { - ${mc_version == '1.20.1' ? '"world-host-bedrock": ">=0.4.2"' : ''} + //#if MC == 1.20.1 && 0 + "world-host-bedrock": ">=0.4.2" + //#endif } } \ No newline at end of file diff --git a/src/main/resources/world-host.mixins.json b/src/main/resources/world-host.mixins.json index 2b7a2d9..ac8c4f0 100644 --- a/src/main/resources/world-host.mixins.json +++ b/src/main/resources/world-host.mixins.json @@ -6,8 +6,7 @@ "mixins": [ "MixinCommands", "MixinPublishCommand", - "ServerConnectionListenerAccessor", - "modmenu.MixinModMenuEventHandler" + "ServerConnectionListenerAccessor" ], "client": [ "MinecraftAccessor", @@ -25,8 +24,12 @@ "MixinWorldSelectionList_WorldListEntry", "PlainTextButtonAccessor", "ServerStatusPingerAccessor" + //#if FABRIC && MC > 1.16.1 + , "modmenu.MixinModMenuEventHandler" + //#endif ], "injectors": { "defaultRequire": 1 - } + }, + "refmap": "world-host.mixins.refmap.json" } \ No newline at end of file diff --git a/version.gradle.kts b/version.gradle.kts index 317e5cb..bc78404 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -1,3 +1,7 @@ +import groovy.lang.GroovyObjectSupport +import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider +import xyz.wagyourtail.unimined.util.sourceSets + import net.lenni0451.classtransform.TransformerManager import net.lenni0451.classtransform.utils.ASMUtils import net.lenni0451.classtransform.utils.tree.BasicClassProvider @@ -5,6 +9,10 @@ import net.lenni0451.classtransform.utils.tree.IClassProvider import net.raphimc.javadowngrader.JavaDowngrader import net.raphimc.javadowngrader.runtime.RuntimeRoot import org.jetbrains.kotlin.incremental.isClassFile +import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig +import xyz.wagyourtail.unimined.api.task.ExportMappingsTask +import xyz.wagyourtail.unimined.internal.mapping.MappingsProvider +import xyz.wagyourtail.unimined.internal.mapping.task.ExportMappingsTaskImpl import java.nio.ByteBuffer import java.nio.file.* import java.nio.file.Path @@ -14,16 +22,125 @@ import kotlin.streams.asSequence plugins { java `maven-publish` - id("xyz.deftu.gradle.multiversion") - id("xyz.deftu.gradle.tools") - id("xyz.deftu.gradle.tools.blossom") - id("xyz.deftu.gradle.tools.minecraft.loom") - id("xyz.deftu.gradle.tools.minecraft.releases") - id("xyz.deftu.gradle.tools.shadow") - id("io.github.juuxel.loom-quiltflower") version "1.8.0" + id("xyz.deftu.gradle.preprocess") + id("xyz.wagyourtail.unimined") + id("com.github.johnrengelman.shadow") version "8.1.1" +} + + +fun Any.setGroovyProperty(name: String, value: Any) = withGroovyBuilder { metaClass }.setProperty(this, name, value) +fun Any.getGroovyProperty(name: String): Any = withGroovyBuilder { metaClass }.getProperty(this, name)!! + + +val vers = project.properties["mod.version"] as String +val mcVersionString by extra(name.substringBefore("-")) +val loaderName by extra(name.substringAfter("-")) + +// major.minor.?patch +// to MMmmPP +val mcVersion by extra(mcVersionString.split(".").map { it.toInt() } + .let { + it[0] * 1_00_00 + it[1] * 1_00 + (if (it.size == 2 || it[2] == 0) 0 else it[2]) + }) + +println("MC_VERSION: $mcVersionString $mcVersion") +version = "${vers}+${mcVersionString}-${loaderName}" + +repositories { + mavenCentral() +} + +lateinit var minecraft: MinecraftConfig +unimined.minecraft { + version(mcVersionString) + side("client") + + mappings { + intermediary() + searge() + mojmap() + when { + mcVersion >= 1_19_03 -> "1.19.3:2023.03.12" + mcVersion >= 1_19_00 -> "1.19.2:2022.11.27" + mcVersion >= 1_18_00 -> "1.18.2:2022.11.06" + mcVersion >= 1_17_00 -> "1.17.1:2021.12.12" + mcVersion >= 1_16_00 -> "1.16.5:2022.03.06" + else -> null + }?.let { + parchment(it.substringBefore(":"), it.substringAfter(":")) + } + + stub.withMappings("searge", listOf("mojmap")) { + if (mcVersion <= 1_19_00) { + c("net/minecraft/client/gui/chat/NarratorChatListener", "net/minecraft/client/GameNarrator") + } + if (mcVersion < 1_17_00) { + c("net/minecraft/client/multiplayer/ServerAddress", "net/minecraft/client/multiplayer/resolver/ServerAddress") + } + } + } + + if (loaderName == "fabric") { + fabric { + loader("0.14.22") + } + } else { + forge { + loader(when(mcVersion) { + 1_20_01 -> "47.1.3" + 1_19_04 -> "45.1.0" + 1_19_02 -> "43.2.0" + 1_18_02 -> "40.2.0" + 1_17_01 -> "37.1.1" + 1_16_05 -> "36.2.34" + else -> throw IllegalArgumentException("unknown forge version for $mcVersionString") + }) + mixinConfig("world-host.mixins.json") + } + } + + minecraft = this } -version = "${modData.version}+${mcData.versionStr}-${mcData.loader.name}" +// jank hax to pretend to be arch-loom +class LoomGradleExtension : GroovyObjectSupport() { + var mappingConfiguration: Any? = null +} + +val loom = LoomGradleExtension() +extensions.add("loom", loom) +val mappingsConfig = object { + var tinyMappings: Path? = null + var tinyMappingsWithSrg: Path? = null +} +loom.setGroovyProperty("mappingConfiguration", mappingsConfig) +val tinyMappings: File = file("${projectDir}/build/tmp/tinyMappings.tiny").also { file -> + val export = ExportMappingsTaskImpl.ExportImpl(minecraft.mappings as MappingsProvider).apply { + location = file + type = ExportMappingsTask.MappingExportTypes.TINY_V2 + setSourceNamespace("official") + setTargetNamespaces(listOf("intermediary", "mojmap")) + renameNs[minecraft.mappings.getNamespace("mojmap")] = "named" + } + export.validate() + export.exportFunc((minecraft.mappings as MappingsProvider).mappingTree) +} +mappingsConfig.setGroovyProperty("tinyMappings", tinyMappings.toPath()) +if (loaderName == "forge") { + val tinyMappingsWithSrg: File = file("${projectDir}/build/tmp/tinyMappingsWithSrg.tiny").also { file -> + val export = ExportMappingsTaskImpl.ExportImpl(minecraft.mappings as MappingsProvider).apply { + location = file + type = ExportMappingsTask.MappingExportTypes.TINY_V2 + setSourceNamespace("official") + setTargetNamespaces(listOf("intermediary", "searge", "mojmap")) + renameNs[minecraft.mappings.getNamespace("mojmap")] = "named" + renameNs[minecraft.mappings.getNamespace("searge")] = "srg" + } + export.validate() + export.exportFunc((minecraft.mappings as MappingsProvider).mappingTree) + } + mappingsConfig.setGroovyProperty("tinyMappingsWithSrg", tinyMappingsWithSrg.toPath()) +} buildscript { repositories { @@ -37,10 +154,7 @@ buildscript { } repositories { - maven { - name = "ParchmentMC" - url = uri("https://maven.parchmentmc.org") - } + maven("https://maven.quiltmc.org/repository/release/") maven("https://maven.terraformersmc.com/releases") @@ -53,41 +167,48 @@ repositories { maven("https://jitpack.io") } -val bundle: Configuration by configurations.creating { - configurations.getByName(if (mcData.isFabric) "include" else "shade").extendsFrom(this) +println("loaderName: $loaderName") +println("mcVersion: $mcVersion") + +val shade by configurations.creating + +val modCompileOnly: Configuration by configurations.creating { + configurations.getByName("compileOnly").extendsFrom(this) +} + +val modRuntimeOnly: Configuration by configurations.creating { + configurations.getByName("runtimeOnly").extendsFrom(this) +} + +minecraft.apply { + mods.remap(modCompileOnly) + mods.remap(modRuntimeOnly) } dependencies { + fun bundle(dependency: Any) { + if (loaderName == "fabric") { + "include"(dependency) + } else { + "shade"(dependency) + } + } + fun bundleImplementation(dependency: Any) { implementation(dependency) bundle(dependency) } - @Suppress("UnstableApiUsage") - mappings(loom.layered { - officialMojangMappings() - when { - mcData.version >= 1_19_03 -> "1.19.3:2023.03.12" - mcData.version >= 1_19_00 -> "1.19.2:2022.11.27" - mcData.version >= 1_18_00 -> "1.18.2:2022.11.06" - mcData.version >= 1_17_00 -> "1.17.1:2021.12.12" - mcData.version >= 1_16_00 -> "1.16.5:2022.03.06" - else -> null - }?.let { - parchment("org.parchmentmc.data:parchment-$it@zip") - } - }) - bundleImplementation("org.quiltmc.qup:json:0.2.0") -// includeImplementation("com.github.LlamaLad7.MixinExtras:mixinextras-${mcData.loader.name}:0.2.0-beta.6") + //TODO: bump to unimined 1.1.0+ to use these, also enable the processor in unimined's mixin config settings +// includeImplementation("com.github.LlamaLad7.MixinExtras:mixinextras-${mcData.loader.name}:0.2.0-beta.6")h // if (mcData.isForge) { // implementation("com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0-beta.6") // } -// annotationProcessor("com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0-beta.6") - if (mcData.isFabric) { - when (mcData.version) { + if (loaderName == "fabric") { + when (mcVersion) { 1_20_01 -> "7.0.1" 1_19_04 -> "6.2.3" 1_19_02 -> "4.2.0-beta.2" @@ -96,17 +217,17 @@ dependencies { 1_16_05 -> "1.16.23" else -> null }?.let { - modImplementation("com.terraformersmc:modmenu:$it") + "modImplementation"("com.terraformersmc:modmenu:$it") } - if (mcData.version == 1_16_01) { - modImplementation("io.github.prospector:modmenu:1.14.5+build.30") + if (mcVersion == 1_16_01) { + "modImplementation"("io.github.prospector:modmenu:1.14.5+build.30") } } - modRuntimeOnly("me.djtheredstoner:DevAuth-${if (mcData.isFabric) "fabric" else "forge-latest"}:1.1.2") +// modRuntimeOnly("me.djtheredstoner:DevAuth-${if (mcData.isFabric) "fabric" else "forge-latest"}:1.1.2") - if (mcData.isFabric) { - when (mcData.version) { + if (loaderName == "fabric") { + when (mcVersion) { 1_20_01 -> "0.83.0+1.20.1" 1_19_04 -> "0.80.0+1.19.4" 1_19_02 -> "0.76.0+1.19.2" @@ -116,19 +237,19 @@ dependencies { else -> null }?.let { fabricApi.module("fabric-resource-loader-v0", it) } ?.let { - modImplementation(it) + "modImplementation"(it) bundle(it) } } - if (mcData.isFabric && mcData.version >= 1_18_02) { + if (loaderName == "fabric" && mcVersion >= 1_18_02) { modCompileOnly("dev.isxander:main-menu-credits:1.1.2") } - if (mcData.isFabric) { + if (loaderName == "fabric") { when { - mcData.version >= 1_20_00 -> "2.7.6" - mcData.version >= 1_19_04 -> "2.7.5" + mcVersion >= 1_20_00 -> "2.7.6" + mcVersion >= 1_19_04 -> "2.7.5" else -> null }?.let { modCompileOnly("de.florianmichael:viafabricplus:$it") { @@ -142,63 +263,95 @@ java { withSourcesJar() } -loom { - if (mcData.isForge) { - forge { - mixinConfig("world-host.mixins.json") - } - } - - @Suppress("UnstableApiUsage") - mixin.defaultRefmapName.set("world-host.mixins.refmap.json") -} - preprocess { + vars.putAll(mapOf( + "FORGE" to 0, + "FABRIC" to 0, + )) + vars.putAll(mapOf( + loaderName.uppercase() to 1, + "MC" to mcVersion + )) + patternAnnotation.set("io.github.gaming32.worldhost.versions.Pattern") + keywords.value(keywords.get()) + keywords.put(".json", keywords.get().getValue(".json").copy(eval = "//??")) } +// TODO: fix +// +//toolkitReleases { +// modrinth { +// projectId.set("world-host") +// } +// rootProject.file("changelogs/${modData.version}.md").let { +// if (it.exists()) { +// changelogFile.set(it) +// } +// } +// describeFabricWithQuilt.set(true) +// useSourcesJar.set(true) +// if (mcData.isFabric) { +// if (mcVersion == 1_19_04) { +// gameVersions.add("23w13a_or_b") +// } else if (mcVersion == 1_20_01) { +// gameVersions.add("1.20") +// } +// } +//} -toolkitReleases { - modrinth { - projectId.set("world-host") - } - rootProject.file("changelogs/${modData.version}.md").let { - if (it.exists()) { - changelogFile.set(it) - } - } - describeFabricWithQuilt.set(true) - useSourcesJar.set(true) - if (mcData.isFabric) { - if (mcData.version == 1_19_04) { - gameVersions.add("23w13a_or_b") - } else if (mcData.version == 1_20_01) { - gameVersions.add("1.20") - } - } +tasks.shadowJar { + configurations = listOf(shade) } tasks.processResources { filesMatching("pack.mcmeta") { expand("pack_format" to when { - mcData.version >= 1_20_00 -> 15 - mcData.version >= 1_19_04 -> 13 - mcData.version >= 1_19_03 -> 12 - mcData.version >= 1_19_00 -> 9 - mcData.version >= 1_18_00 -> 8 - mcData.version >= 1_17_00 -> 7 - mcData.version >= 1_16_02 -> 6 - mcData.version >= 1_15_00 -> 5 - mcData.version >= 1_13_00 -> 4 - mcData.version >= 1_11_00 -> 3 - mcData.version >= 1_09_00 -> 2 - mcData.version >= 1_06_01 -> 1 + mcVersion >= 1_20_00 -> 15 + mcVersion >= 1_19_04 -> 13 + mcVersion >= 1_19_03 -> 12 + mcVersion >= 1_19_00 -> 9 + mcVersion >= 1_18_00 -> 8 + mcVersion >= 1_17_00 -> 7 + mcVersion >= 1_16_02 -> 6 + mcVersion >= 1_15_00 -> 5 + mcVersion >= 1_13_00 -> 4 + mcVersion >= 1_11_00 -> 3 + mcVersion >= 1_09_00 -> 2 + mcVersion >= 1_06_01 -> 1 else -> return@filesMatching }) } + filesMatching("fabric.mod.json") { + filter { + if (it.trim().startsWith("//")) "" else it + } + } + + filesMatching(listOf( + "mcmod.info", + "fabric.mod.json", + "quilt.mod.json", + "META-INF/mods.toml", + "mixins.*.json", + "*.mixins.json" + )) { + expand(mapOf( + "version" to project.version, + "mc_version" to mcVersionString, + "java_version" to "JAVA_${mcJavaVersion.majorVersion}" + )) + } + + if (loaderName == "fabric") { + exclude("pack.mcmeta", "META-INF/mods.toml") + } else { + exclude("fabric.mod.json") + } + doLast { - val resources = "$buildDir/resources/main" - if (mcData.isForge) { + val resources = "${layout.buildDirectory.get()}/resources/main" + if (loaderName == "forge") { copy { from(file("$resources/assets/world-host/icon.png")) into(resources) @@ -210,7 +363,9 @@ tasks.processResources { } } -if (mcData.javaVersion < java.sourceCompatibility) { +val mcJavaVersion = (minecraft as MinecraftProvider).minecraftData.metadata.javaVersion + +if (mcJavaVersion < java.sourceCompatibility) { // These ClassProviders are from // https://github.com/RaphiMC/JavaDowngrader/tree/main/Standalone/src/main/java/net/raphimc/javadowngrader/standalone/transform abstract class AbstractClassProvider(val parent: IClassProvider? = null) : IClassProvider { @@ -282,8 +437,8 @@ if (mcData.javaVersion < java.sourceCompatibility) { override fun close() = path.forEach { (it as? AutoCloseable)?.close() } } - val targetClassVersion = mcData.javaVersion.ordinal + 45 - println("Classes need downgrading to Java ${mcData.javaVersion} ($targetClassVersion)") + val targetClassVersion = mcJavaVersion.ordinal + 45 + println("Classes need downgrading to Java $mcJavaVersion ($targetClassVersion)") tasks.register("downgradeClasses") { dependsOn("classes") @@ -349,5 +504,5 @@ if (mcData.javaVersion < java.sourceCompatibility) { } } - tasks.fatJar.get().dependsOn += "downgradeClasses" + tasks.shadowJar.get().dependsOn += "downgradeClasses" }