-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Mixin-caused product env Crashing
- Loading branch information
Showing
3 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@file:Suppress("EnumEntryName") | ||
|
||
package cn.taskeren.op.mixin_plugin | ||
|
||
import java.nio.file.Path | ||
import kotlin.io.path.extension | ||
import kotlin.io.path.nameWithoutExtension | ||
|
||
enum class OP_Mixin(vararg targetModArg: OP_TargetMod, classNameArg: String? = null) { | ||
|
||
Insurance_BaseMetaTileEntity(OP_TargetMod.GregTech), | ||
CrashProof_ModularGui_Mixin(OP_TargetMod.ModularUi), | ||
|
||
; | ||
|
||
val className = "${classNameArg ?: name}_Mixin" | ||
val targetMod = targetModArg.toList() | ||
|
||
init { | ||
require(targetModArg.isNotEmpty()) { "Mixin must be targeting to at least 1 mod!" } | ||
} | ||
|
||
fun shouldLoad(loadedMods: Collection<OP_TargetMod>): Boolean { | ||
return loadedMods.containsAll(targetMod) | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @see gregtech.mixin.TargetedMod | ||
* @see com.kuba6000.mobsinfo.mixin.TargetedMod | ||
* @see com.gtnewhorizons.modularui.mixinplugin.TargetedMod | ||
*/ | ||
enum class OP_TargetMod(jarNamePrefixArg: String? = null, val shouldLoadInDev: Boolean = true) { | ||
|
||
GregTech, | ||
ModularUi | ||
|
||
; | ||
|
||
val jarNamePrefix = (jarNamePrefixArg ?: name).lowercase() | ||
|
||
fun isMatchingJar(path: Path): Boolean { | ||
return path.extension == "jar" && path.nameWithoutExtension.lowercase().startsWith(jarNamePrefix) | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/kotlin/cn/taskeren/op/mixin_plugin/OP_MixinPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cn.taskeren.op.mixin_plugin | ||
|
||
import com.gtnewhorizon.gtnhmixins.MinecraftURLClassPath | ||
import net.minecraft.launchwrapper.Launch | ||
import org.apache.logging.log4j.LogManager | ||
import org.spongepowered.asm.lib.tree.ClassNode | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo | ||
import java.io.File | ||
import kotlin.io.path.listDirectoryEntries | ||
|
||
class OP_MixinPlugin : IMixinConfigPlugin { | ||
|
||
companion object { | ||
val LOGGER = LogManager.getLogger() | ||
|
||
val MODS_DIRECTORY_PATH = File(Launch.minecraftHome, "mods/").toPath() | ||
|
||
fun findJarOf(mod: OP_TargetMod): File? { | ||
return MODS_DIRECTORY_PATH.listDirectoryEntries().firstOrNull { mod.isMatchingJar(it) }?.toFile() | ||
} | ||
|
||
fun loadJarOf(mod: OP_TargetMod): Boolean { | ||
try { | ||
val foundJar = findJarOf(mod) | ||
if(foundJar == null) { | ||
LOGGER.error("Unable to find required jar of $mod") | ||
return false | ||
} | ||
|
||
LOGGER.info("Attempt to add jar $foundJar to classloader") | ||
MinecraftURLClassPath.addJar(foundJar) | ||
return true | ||
} catch(e: Exception) { | ||
LOGGER.error("Error occurred while loading jar $mod", e) | ||
return false | ||
} | ||
} | ||
} | ||
|
||
override fun onLoad(mixinPackage: String?) { | ||
OP_MixinConfig.init() | ||
} | ||
|
||
override fun getMixins(): List<String> { | ||
val isDev = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean | ||
|
||
val loadedMods = OP_TargetMod.entries.filter { isDev && it.shouldLoadInDev || loadJarOf(it) } | ||
|
||
OP_TargetMod.entries.forEach { | ||
if(loadedMods.contains(it)) { | ||
LOGGER.info("Found ${it.name}, integrating") | ||
} else { | ||
LOGGER.info("Unable to find ${it.name}, integrating skipped") | ||
} | ||
} | ||
|
||
return OP_Mixin.entries.filter { it.shouldLoad(loadedMods) }.map { it.className } | ||
} | ||
|
||
override fun getRefMapperConfig(): String? { | ||
return null | ||
} | ||
|
||
override fun shouldApplyMixin(targetClassName: String?, mixinClassName: String?): Boolean { | ||
return true | ||
} | ||
|
||
override fun acceptTargets( | ||
myTargets: Set<String?>?, | ||
otherTargets: Set<String?>?, | ||
) { | ||
} | ||
|
||
override fun preApply( | ||
s: String?, | ||
classNode: ClassNode?, | ||
s1: String?, | ||
iMixinInfo: IMixinInfo?, | ||
) { | ||
} | ||
|
||
override fun postApply( | ||
s: String?, | ||
classNode: ClassNode?, | ||
s1: String?, | ||
iMixinInfo: IMixinInfo?, | ||
) { | ||
} | ||
} | ||
|
||
private object OP_MixinConfig { | ||
|
||
fun init() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
{ | ||
"required": true, | ||
"package": "cn.taskeren.op.mixin", | ||
"plugin": "cn.taskeren.op.mixin_plugin.OP_MixinPlugin", | ||
"mixins": [ | ||
"Insurance_BaseMetaTileEntity_Mixin" | ||
], | ||
"client": [ | ||
"CrashProof_ModularGui_Mixin" | ||
] | ||
} |