Skip to content

Commit

Permalink
fix combineWith and patch fg2 resource loading to use multiple folders
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Mar 6, 2024
1 parent eb71759 commit 0522ae0
Show file tree
Hide file tree
Showing 8 changed files with 706 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
}
val project = path.substringBeforeLast(":")
val name = path.substringAfterLast(":")
combineWith(this.project.project(path), this.project.project(path).sourceSets.getByName(name))
combineWith(this.project.project(project), this.project.project(project).sourceSets.getByName(name))
};

/**
Expand Down Expand Up @@ -320,5 +320,5 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
val localCache by lazy { project.unimined.getLocalCache(sourceSet) }

@get:ApiStatus.Internal
abstract val combinedWithList: MutableList<Pair<Project, SourceSet>>
abstract val combinedWithList: MutableSet<Pair<Project, SourceSet>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class FinalizeOnRead<T>(value: T) : ReadWriteProperty<Any?, T> {
if (finalized) {
throw IllegalStateException("Cannot set finalized property")
}
if (value is ReadWriteProperty<*, *>) {
(value as ReadWriteProperty<Any?, T>).setValue(thisRef, property, value)
if (this.value is ReadWriteProperty<*, *>) {
(this.value as ReadWriteProperty<Any?, T>).setValue(thisRef, property, value)
} else {
this.value = value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MinecraftProvider(project: Project, sourceSet: SourceSet) : MinecraftConfi
private val patcherActions = ArrayDeque<() -> Unit>()
private var lateActionsRunning by FinalizeOnWrite(false)

override val combinedWithList = mutableListOf<Pair<Project, SourceSet>>()
override val combinedWithList = mutableSetOf<Pair<Project, SourceSet>>()

var applied: Boolean by FinalizeOnWrite(false)
private set
Expand Down Expand Up @@ -116,12 +116,14 @@ class MinecraftProvider(project: Project, sourceSet: SourceSet) : MinecraftConfi
}

override fun combineWith(project: Project, sourceSet: SourceSet) {
combinedWithList.add(project to sourceSet)
if (project.uniminedMaybe != null && project.unimined.minecrafts.contains(sourceSet)) {
from(project, sourceSet)
project.logger.lifecycle("[Unimined/Minecraft ${project.path}:${this.sourceSet.name}] Combining with ${project.path}:${sourceSet.name}")
if (combinedWithList.add(project to sourceSet)) {
if (project.uniminedMaybe != null && project.unimined.minecrafts.contains(sourceSet)) {
from(project, sourceSet)
}
this.sourceSet.compileClasspath += sourceSet.output
this.sourceSet.runtimeClasspath += sourceSet.output
}
this.sourceSet.compileClasspath += sourceSet.output
this.sourceSet.runtimeClasspath += sourceSet.output
// remove unimined deps
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ abstract class AbstractMinecraftTransformer protected constructor(
throw IllegalArgumentException("All combined minecraft configs must be on the same version, found ${provider.sourceSet} on ${provider.version} and ${sourceSet} on ${minecraftConfig.version}")
}
}

// squash all combinedWith
val map = mutableMapOf<Pair<Project, SourceSet>, Set<Pair<Project, SourceSet>>>()
val resolveQueue = minecraftConfigs.keys.toMutableSet()
while (resolveQueue.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ abstract class ForgeLikeMinecraftTransformer(
for ((proj, sourceSet) in groups.keys.toSet()) {
if (proj.uniminedMaybe?.minecrafts?.map?.get(sourceSet)?.mcPatcher !is ForgeLikePatcher<*>) {
// merge with current
proj.logger.warn("[Unimined/ForgeLike] Non-forge ${(proj to sourceSet).toPath()} found in fabric classpath groups, merging with current (${(project to provider.sourceSet).toPath()}), this should've been manually specified with `combineWith`")
proj.logger.warn("[Unimined/ForgeLike] Non-forge ${(proj to sourceSet).toPath()} found in forge classpath groups, merging with current (${(project to provider.sourceSet).toPath()}), this should've been manually specified with `combineWith`")
groups[this.project to this.provider.sourceSet]!! += groups[proj to sourceSet]!!
groups.remove(proj to sourceSet)
}
}
project.logger.info("[Unimined/FabricLike] Classpath groups: ${groups.map { it.key.toPath() + " -> " + it.value.joinToString(", ") { it.toPath() } }.joinToString("\n ")}")
project.logger.info("[Unimined/ForgeLike] Classpath groups: ${groups.map { it.key.toPath() + " -> " + it.value.joinToString(", ") { it.toPath() } }.joinToString("\n ")}")
groups.map { entry -> entry.value.flatMap { listOf(it.second.output.resourcesDir) + it.second.output.classesDirs }.joinToString(File.pathSeparator) { "${entry.key.toPath().replace(":", "_")}%%${it!!.absolutePath}" } }.joinToString(File.pathSeparator)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import xyz.wagyourtail.unimined.api.unimined
import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.ForgeLikeMinecraftTransformer
import xyz.wagyourtail.unimined.internal.minecraft.patch.jarmod.JarModMinecraftTransformer
import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2Coremods
import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2ResourceLoading
import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2ResourceLoading.fixResourceLoading
import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger
import xyz.wagyourtail.unimined.util.*
import xyz.wagyourtail.unimined.util.deleteRecursively
Expand Down Expand Up @@ -61,6 +63,7 @@ class FG2MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr

override val transform = (listOf<(FileSystem) -> Unit>(
FixFG2Coremods::fixCoremods,
FixFG2ResourceLoading::fixResourceLoading,
) + super.transform).toMutableList()

override fun apply() {
Expand Down Expand Up @@ -142,6 +145,7 @@ class FG2MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr
config.jvmArgs += "-Dfml.ignoreInvalidMinecraftCertificates=true"
config.jvmArgs += "-Dfml.deobfuscatedEnvironment=true"
config.jvmArgs += "-Dnet.minecraftforge.gradle.GradleStart.srg.srg-mcp=${parent.srgToMCPAsSRG}"
config.env["MOD_CLASSES"] = parent.groups
}

override fun applyServerRunTransform(config: RunConfig) {
Expand Down Expand Up @@ -171,6 +175,7 @@ class FG2MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr
config.jvmArgs += "-Dfml.ignoreInvalidMinecraftCertificates=true"
config.jvmArgs += "-Dfml.deobfuscatedEnvironment=true"
config.jvmArgs += "-Dnet.minecraftforge.gradle.GradleStart.srg.srg-mcp=${parent.srgToMCPAsSRG}"
config.env["MOD_CLASSES"] = parent.groups
}

override fun afterRemap(baseMinecraft: MinecraftJar): MinecraftJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.Mcp
import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.McpExecutor
import xyz.wagyourtail.unimined.internal.minecraft.patch.jarmod.JarModMinecraftTransformer
import xyz.wagyourtail.unimined.internal.minecraft.resolver.AssetsDownloader
import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2Coremods
import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2ResourceLoading
import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger
import xyz.wagyourtail.unimined.util.*
import java.io.File
Expand Down Expand Up @@ -70,6 +72,11 @@ class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr
override val merger: ClassMerger
get() = throw UnsupportedOperationException("FG3+ does not support merging with unofficial merger.")

override val transform: MutableList<(FileSystem) -> Unit> = (
if (parent.provider.version == "1.12.2") { listOf(FixFG2ResourceLoading::fixResourceLoading) } else { emptyList() } +
super.transform
).toMutableList()


@ApiStatus.Internal
val clientExtra = project.configurations.maybeCreate("clientExtra".withSourceSet(provider.sourceSet)).also {
Expand Down Expand Up @@ -449,6 +456,7 @@ class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr
config.args += listOf("--tweakClass",
parent.tweakClassClient ?: "net.minecraftforge.fml.common.launcher.FMLTweaker"
)
config.env += mapOf("MOD_CLASSES" to parent.groups)
} else {
project.logger.info("[FG3] Using new client run config")
val args = get("args")?.asJsonArray?.map { it.asString } ?: listOf()
Expand Down Expand Up @@ -484,6 +492,7 @@ class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecraftTr
config.args += listOf("--tweakClass",
parent.tweakClassClient ?: "net.minecraftforge.fml.common.launcher.FMLTweaker"
)
config.env += mapOf("MOD_CLASSES" to parent.groups)
} else {
project.logger.info("[FG3] Using new server run config")
val args = get("args")?.asJsonArray?.map { it.asString } ?: listOf()
Expand Down
Loading

0 comments on commit 0522ae0

Please sign in to comment.