From 57b0027d21b5e9c6f8850ae839a2ebaa6dab7879 Mon Sep 17 00:00:00 2001 From: C-H716 <1536152356@qq.com> Date: Sun, 31 Aug 2025 21:38:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=B9=E6=A0=B7=E6=9D=BF=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=99=A8=E6=B7=BB=E5=8A=A0=E6=99=BA=E8=83=BD=E5=80=8D?= =?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 4 +- ...TLCoreMEPatternBufferPartMachineMixin.java | 81 +++++++++++++++++++ .../MEPatternBufferPartMachineMixin.java | 81 +++++++++++++++++++ .../resources/extendedae_plus.mixins.json | 2 + 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/GTLCoreMEPatternBufferPartMachineMixin.java create mode 100644 src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/MEPatternBufferPartMachineMixin.java diff --git a/gradle.properties b/gradle.properties index 4d63514..c19bb99 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G loom.platform = forge # Mod properties -mod_version = 1.4.0-fix +mod_version = 1.4.0-fix-gtceu maven_group = com.extendedae_plus archives_name = extendedae_plus @@ -26,7 +26,7 @@ rei_version=12.0.622 cloth_config_version=9.0.94 projecte_version=4901949 appliede_version=5364294 -gregtech_version=5369020 +gregtech_version=5753724 ldlib_version=5394816 ie_version=5224387 mixin_version=0.8.4 diff --git a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/GTLCoreMEPatternBufferPartMachineMixin.java b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/GTLCoreMEPatternBufferPartMachineMixin.java new file mode 100644 index 0000000..c82b605 --- /dev/null +++ b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/GTLCoreMEPatternBufferPartMachineMixin.java @@ -0,0 +1,81 @@ +package com.extendedae_plus.mixin.ae2.autopattern.gtceu; + +import appeng.api.crafting.IPatternDetails; +import com.extendedae_plus.content.ScaledProcessingPattern; +import com.google.common.collect.BiMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Map; +import java.util.Objects; + +@Pseudo +@Mixin(targets = "org.gtlcore.gtlcore.common.machine.multiblock.part.ae.MEPatternBufferPartMachine",remap = false) +public class GTLCoreMEPatternBufferPartMachineMixin { + + // 重定向containsKey检查 + @Redirect(method = "pushPattern(Lappeng/api/crafting/IPatternDetails;[Lappeng/api/stacks/KeyCounter;)Z", + at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;containsKey(Ljava/lang/Object;)Z")) + private boolean redirectContainsKey(BiMap detailsSlotMap, Object key) { + try { + // 如果key是ScaledProcessingPattern类型,尝试用其原始pattern进行判断 + if (key instanceof ScaledProcessingPattern scaled) { + IPatternDetails base = scaled.getOriginal(); + if (base != null) { + // 避免递归重定向,直接遍历keySet判断 + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, base)) return true; + } + } + } + // 常规判断,遍历keySet + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, key)) return true; + } + return false; + } catch (Throwable t) { + // 出现异常时,回退到常规判断 + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, key)) return true; + } + return false; + } + } + + @Redirect(method = "pushPattern(Lappeng/api/crafting/IPatternDetails;[Lappeng/api/stacks/KeyCounter;)Z", + at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;get(Ljava/lang/Object;)Ljava/lang/Object;")) + private Object redirectGet(BiMap detailsSlotMap, Object key) { + try { + // 如果是 ScaledProcessingPattern,优先尝试其原始 pattern 对应的值 + if (key instanceof ScaledProcessingPattern scaled) { + IPatternDetails base = scaled.getOriginal(); + if (base != null) { + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), base)) { + return e.getValue(); + } + } + } + } + + // 常规查找:遍历 entrySet 避免再次调用 BiMap.get 导致递归重定向 + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), key)) { + return e.getValue(); + } + } + return null; + } catch (Throwable t) { + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), key)) { + return e.getValue(); + } + } + return null; + } + } +} + + diff --git a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/MEPatternBufferPartMachineMixin.java b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/MEPatternBufferPartMachineMixin.java new file mode 100644 index 0000000..90c7ab1 --- /dev/null +++ b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/gtceu/MEPatternBufferPartMachineMixin.java @@ -0,0 +1,81 @@ +package com.extendedae_plus.mixin.ae2.autopattern.gtceu; + +import appeng.api.crafting.IPatternDetails; +import com.extendedae_plus.content.ScaledProcessingPattern; +import com.google.common.collect.BiMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Map; +import java.util.Objects; + +; + +@Mixin(targets = "com.gregtechceu.gtceu.integration.ae2.machine.MEPatternBufferPartMachine",remap = false) +public class MEPatternBufferPartMachineMixin { + + // 重定向containsKey检查 + @Redirect(method = "pushPattern(Lappeng/api/crafting/IPatternDetails;[Lappeng/api/stacks/KeyCounter;)Z", + at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;containsKey(Ljava/lang/Object;)Z")) + private boolean redirectContainsKey(BiMap detailsSlotMap, Object key) { + try { + // 如果key是ScaledProcessingPattern类型,尝试用其原始pattern进行判断 + if (key instanceof ScaledProcessingPattern scaled) { + IPatternDetails base = scaled.getOriginal(); + if (base != null) { + // 避免递归重定向,直接遍历keySet判断 + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, base)) return true; + } + } + } + // 常规判断,遍历keySet + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, key)) return true; + } + return false; + } catch (Throwable t) { + // 出现异常时,回退到常规判断 + for (IPatternDetails d : detailsSlotMap.keySet()) { + if (Objects.equals(d, key)) return true; + } + return false; + } + } + + @Redirect(method = "pushPattern(Lappeng/api/crafting/IPatternDetails;[Lappeng/api/stacks/KeyCounter;)Z", + at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;get(Ljava/lang/Object;)Ljava/lang/Object;")) + private Object redirectGet(BiMap detailsSlotMap, Object key) { + try { + // 如果是 ScaledProcessingPattern,优先尝试其原始 pattern 对应的值 + if (key instanceof ScaledProcessingPattern scaled) { + IPatternDetails base = scaled.getOriginal(); + if (base != null) { + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), base)) { + return e.getValue(); + } + } + } + } + + // 常规查找:遍历 entrySet 避免再次调用 BiMap.get 导致递归重定向 + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), key)) { + return e.getValue(); + } + } + return null; + } catch (Throwable t) { + for (Map.Entry e : detailsSlotMap.entrySet()) { + if (Objects.equals(e.getKey(), key)) { + return e.getValue(); + } + } + return null; + } + } +} + + diff --git a/src/main/resources/extendedae_plus.mixins.json b/src/main/resources/extendedae_plus.mixins.json index e001c30..9df4da8 100644 --- a/src/main/resources/extendedae_plus.mixins.json +++ b/src/main/resources/extendedae_plus.mixins.json @@ -42,6 +42,8 @@ "ae2.autopattern.CraftingTreeProcessMixin", "ae2.autopattern.PatternProviderLogicContainsRedirectMixin", "ae2.autopattern.adaptation.AdvPatternProviderLogicContainsRedirectMixin", + "ae2.autopattern.gtceu.GTLCoreMEPatternBufferPartMachineMixin", + "ae2.autopattern.gtceu.MEPatternBufferPartMachineMixin", "ae2.helpers.PatternProviderLogicAdvancedMixin", "ae2.helpers.PatternProviderLogicDoublingMixin", "ae2.menu.ContainerPatternEncodingTermMenuMixin",