ExtendedAE_Plus/src/main/java/com/extendedae_plus/mixin/MixinConditions.java

113 lines
4.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.extendedae_plus.mixin;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Set;
/**
* Mixin条件加载插件
* 用于根据模组存在情况动态加载不同的Mixin
*/
public class MixinConditions implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
// 初始化时调用
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
// 对于升级相关的Mixin检查appflux是否存在
if (mixinClassName.contains("PatternProviderMenuUpgradesMixin") ||
mixinClassName.contains("PatternProviderLogicUpgradesMixin") ||
mixinClassName.contains("PatternProviderLogicHostUpgradesMixin")) {
try {
// 检查ModList是否已初始化
if (net.minecraftforge.fml.ModList.get() == null) {
System.out.println("[ExtendedAE_Plus] ModList未初始化默认应用升级Mixin: " + mixinClassName);
return true; // 修改策略:未初始化时默认应用,运行时再检查
}
boolean appfluxExists = net.minecraftforge.fml.ModList.get().isLoaded("appflux");
boolean shouldApply = !appfluxExists;
System.out.println("[ExtendedAE_Plus] 升级Mixin检查: " + mixinClassName +
", appflux存在: " + appfluxExists +
", 应用Mixin: " + shouldApply);
return shouldApply;
} catch (Exception e) {
System.out.println("[ExtendedAE_Plus] ModList检查失败默认应用升级Mixin: " + mixinClassName);
return true; // 修改策略:出错时默认应用,运行时再检查
}
}
// 对于appflux相关的Mixin总是加载但在运行时检查条件
if (mixinClassName.contains("AppfluxPatternProviderLogicMixin")) {
System.out.println("[ExtendedAE_Plus] 总是加载appflux Mixin运行时检查条件: " + mixinClassName);
return true; // 总是加载在Mixin内部进行运行时检查
}
// 对于InterfaceLogicUpgradesMixin总是加载但在运行时检查条件
if (mixinClassName.contains("InterfaceLogicUpgradesMixin")) {
System.out.println("[ExtendedAE_Plus] 总是加载Interface升级Mixin运行时检查条件: " + mixinClassName);
return true; // 总是加载在Mixin内部进行运行时检查
}
// 对于CraftingCPUClusterMixin检查MAE2是否存在
if (mixinClassName.contains("CraftingCPUClusterMixin")) {
try {
// 检查ModList是否已初始化
if (net.minecraftforge.fml.ModList.get() == null) {
System.out.println("[ExtendedAE_Plus] ModList未初始化默认应用CraftingCPU Mixin: " + mixinClassName);
return true; // 未初始化时默认应用
}
boolean mae2Exists = net.minecraftforge.fml.ModList.get().isLoaded("mae2");
boolean shouldApply = !mae2Exists;
System.out.println("[ExtendedAE_Plus] CraftingCPU Mixin检查: " + mixinClassName +
", MAE2存在: " + mae2Exists +
", 应用Mixin: " + shouldApply);
return shouldApply;
} catch (Exception e) {
System.out.println("[ExtendedAE_Plus] ModList检查失败默认跳过CraftingCPU Mixin: " + mixinClassName);
return false; // 出错时默认跳过,避免冲突
}
}
// 其他Mixin正常应用
System.out.println("[ExtendedAE_Plus] 加载Mixin: " + mixinClassName);
return true;
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
// 接受目标类
}
@Override
public List<String> getMixins() {
return null;
}
@Override
public void preApply(String targetClassName, org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
// 应用前调用
}
@Override
public void postApply(String targetClassName, org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
// 应用后调用
}
}