分离ADV的适配mixin到单独mixin&mixinPlugin中增加判断是否加载该mixin
This commit is contained in:
parent
444f682ca0
commit
b9da8a4524
|
|
@ -0,0 +1,9 @@
|
|||
package com.extendedae_plus.compat;
|
||||
|
||||
import appeng.api.networking.IManagedGridNode;
|
||||
|
||||
public interface PatternProviderLogicVirtualCompatBridge {
|
||||
boolean eap$compatIsVirtualCraftingEnabled();
|
||||
|
||||
IManagedGridNode eap$compatGetMainNode();
|
||||
}
|
||||
|
|
@ -8,36 +8,44 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
public class ExtendedAEPlusMixinPlugin implements IMixinConfigPlugin {
|
||||
private static boolean isJeiPresent() {
|
||||
try {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Class.forName("mezz.jei.api.IModPlugin", false, cl);
|
||||
return true;
|
||||
} catch (Throwable ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static boolean isClassPresent(String className) {
|
||||
try {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Class.forName(className, false, cl);
|
||||
return true;
|
||||
} catch (Throwable ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) { }
|
||||
private static boolean isJeiPresent() {
|
||||
return isClassPresent("mezz.jei.api.IModPlugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() { return null; }
|
||||
private static boolean isAdvancedAePresent() {
|
||||
return isClassPresent("net.pedroksl.advanced_ae.AdvancedAE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if (!isJeiPresent()) {
|
||||
// Disable all JEI package mixins and any mixins that reference JEI-only helpers
|
||||
if (mixinClassName.startsWith("com.extendedae_plus.mixin.jei")) return false;
|
||||
if (mixinClassName.equals("com.extendedae_plus.mixin.ae2.menu.CraftConfirmMenuGoBackMixin")) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) { }
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { }
|
||||
@Override
|
||||
public String getRefMapperConfig() { return null; }
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if (!isJeiPresent()) {
|
||||
// Disable all JEI package mixins and any mixins that reference JEI-only helpers
|
||||
if (mixinClassName.startsWith("com.extendedae_plus.mixin.jei")) return false;
|
||||
if (mixinClassName.equals("com.extendedae_plus.mixin.ae2.menu.CraftConfirmMenuGoBackMixin")) return false;
|
||||
}
|
||||
if (!isAdvancedAePresent()) {
|
||||
if (mixinClassName.equals("com.extendedae_plus.mixin.advancedae.compat.PatternProviderLogicVirtualCompletionMixin")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public List<String> getMixins() { return null; }
|
||||
|
||||
@Override
|
||||
|
|
@ -45,4 +53,7 @@ public class ExtendedAEPlusMixinPlugin implements IMixinConfigPlugin {
|
|||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { }
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.extendedae_plus.mixin.advancedae.compat;
|
||||
|
||||
import appeng.api.crafting.IPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.crafting.ICraftingService;
|
||||
import appeng.api.stacks.KeyCounter;
|
||||
import appeng.helpers.patternprovider.PatternProviderLogic;
|
||||
import com.extendedae_plus.compat.PatternProviderLogicVirtualCompatBridge;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvCraftingCPULogicAccessor;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvExecutingCraftingJobAccessor;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvExecutingCraftingJobTaskProgressAccessor;
|
||||
import net.pedroksl.advanced_ae.common.cluster.AdvCraftingCPU;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* AdvancedAE 版本的虚拟完成兼容逻辑。
|
||||
*/
|
||||
@Mixin(value = PatternProviderLogic.class, priority = 850, remap = false)
|
||||
public abstract class PatternProviderLogicVirtualCompletionMixin {
|
||||
|
||||
@Inject(method = "pushPattern", at = @At("RETURN"))
|
||||
private void eap$advancedaeVirtualCompletion(IPatternDetails patternDetails, KeyCounter[] inputHolder,
|
||||
CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!cir.getReturnValueZ()) {
|
||||
return;
|
||||
}
|
||||
if (!(this instanceof PatternProviderLogicVirtualCompatBridge bridge)) {
|
||||
return;
|
||||
}
|
||||
if (!bridge.eap$compatIsVirtualCraftingEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var mainNode = bridge.eap$compatGetMainNode();
|
||||
if (mainNode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var node = mainNode.getNode();
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var grid = node.getGrid();
|
||||
if (grid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ICraftingService craftingService = grid.getCraftingService();
|
||||
if (craftingService == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ICraftingCPU cpu : craftingService.getCpus()) {
|
||||
if (!cpu.isBusy()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cpu instanceof AdvCraftingCPU advCpu) {
|
||||
var logic = advCpu.craftingLogic;
|
||||
if (logic instanceof AdvCraftingCPULogicAccessor advLogicAccessor) {
|
||||
var job = advLogicAccessor.eap$getAdvJob();
|
||||
if (job != null && job instanceof AdvExecutingCraftingJobAccessor advJobAccessor) {
|
||||
var tasks = advJobAccessor.eap$getAdvTasks();
|
||||
var progress = tasks.get(patternDetails);
|
||||
if (progress == null && patternDetails != null) {
|
||||
var patternDefinition = patternDetails.getDefinition();
|
||||
for (var entry : tasks.entrySet()) {
|
||||
var taskPattern = entry.getKey();
|
||||
if (taskPattern == patternDetails) {
|
||||
progress = entry.getValue();
|
||||
break;
|
||||
}
|
||||
if (taskPattern != null && patternDefinition != null) {
|
||||
var taskDefinition = taskPattern.getDefinition();
|
||||
if (taskDefinition != null && taskDefinition.equals(patternDefinition)) {
|
||||
progress = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (progress instanceof AdvExecutingCraftingJobTaskProgressAccessor advProgressAccessor) {
|
||||
if (advProgressAccessor.eap$getAdvValue() <= 1) {
|
||||
advCpu.cancelJob();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,9 +15,7 @@ import appeng.me.cluster.implementations.CraftingCPUCluster;
|
|||
import com.extendedae_plus.ae.items.ChannelCardItem;
|
||||
import com.extendedae_plus.bridge.CompatUpgradeProvider;
|
||||
import com.extendedae_plus.bridge.InterfaceWirelessLinkBridge;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvCraftingCPULogicAccessor;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvExecutingCraftingJobAccessor;
|
||||
import com.extendedae_plus.mixin.advancedae.accessor.AdvExecutingCraftingJobTaskProgressAccessor;
|
||||
import com.extendedae_plus.compat.PatternProviderLogicVirtualCompatBridge;
|
||||
import com.extendedae_plus.compat.UpgradeSlotCompat;
|
||||
import com.extendedae_plus.init.ModItems;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.CraftingCpuLogicAccessor;
|
||||
|
|
@ -29,7 +27,6 @@ import com.extendedae_plus.wireless.endpoint.GenericNodeEndpointImpl;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.pedroksl.advanced_ae.common.cluster.AdvCraftingCPU;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
|
@ -48,7 +45,7 @@ import java.util.List;
|
|||
* - 建立到无线主站的网格连接。
|
||||
*/
|
||||
@Mixin(value = PatternProviderLogic.class, priority = 900, remap = false)
|
||||
public abstract class PatternProviderLogicCompatMixin implements CompatUpgradeProvider, InterfaceWirelessLinkBridge {
|
||||
public abstract class PatternProviderLogicCompatMixin implements CompatUpgradeProvider, InterfaceWirelessLinkBridge, PatternProviderLogicVirtualCompatBridge {
|
||||
|
||||
@Unique
|
||||
private IUpgradeInventory eap$compatUpgrades = UpgradeInventories.empty();
|
||||
|
|
@ -536,43 +533,19 @@ public abstract class PatternProviderLogicCompatMixin implements CompatUpgradePr
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (cpu instanceof AdvCraftingCPU advCpu) {
|
||||
var logic = advCpu.craftingLogic;
|
||||
if (logic instanceof AdvCraftingCPULogicAccessor advLogicAccessor) {
|
||||
var job = advLogicAccessor.eap$getAdvJob();
|
||||
if (job != null && job instanceof AdvExecutingCraftingJobAccessor advJobAccessor) {
|
||||
var tasks = advJobAccessor.eap$getAdvTasks();
|
||||
var progress = tasks.get(patternDetails);
|
||||
if (progress == null && patternDetails != null) {
|
||||
var patternDefinition = patternDetails.getDefinition();
|
||||
for (var entry : tasks.entrySet()) {
|
||||
var taskPattern = entry.getKey();
|
||||
if (taskPattern == patternDetails) {
|
||||
progress = entry.getValue();
|
||||
break;
|
||||
}
|
||||
if (taskPattern != null && patternDefinition != null) {
|
||||
var taskDefinition = taskPattern.getDefinition();
|
||||
if (taskDefinition != null && taskDefinition.equals(patternDefinition)) {
|
||||
progress = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (progress instanceof AdvExecutingCraftingJobTaskProgressAccessor advProgressAccessor) {
|
||||
if (advProgressAccessor.eap$getAdvValue() <= 1) {
|
||||
advCpu.cancelJob();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eap$compatIsVirtualCraftingEnabled() {
|
||||
return this.eap$compatVirtualCraftingEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IManagedGridNode eap$compatGetMainNode() {
|
||||
return this.mainNode;
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void eap$compatSyncVirtualCraftingState() {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
"advancedae.accessor.AdvExecutingCraftingJobTaskProgressAccessor",
|
||||
"advancedae.helpers.AdvPatternProviderLogicAdvancedMixin",
|
||||
"advancedae.helpers.AdvPatternProviderLogicDoublingMixin",
|
||||
"advancedae.compat.PatternProviderLogicVirtualCompletionMixin",
|
||||
"advancedae.menu.AdvPatternProviderMenuAdvancedMixin",
|
||||
"ae2.AEProcessingPatternMixin",
|
||||
"ae2.CraftingCalculationMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user