feat: 对样板供应器添加智能倍增支持

This commit is contained in:
C-H716 2025-08-31 21:38:33 +08:00
parent 247081939f
commit 57b0027d21
4 changed files with 166 additions and 2 deletions

View File

@ -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

View File

@ -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<IPatternDetails, ?> 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<IPatternDetails, ?> detailsSlotMap, Object key) {
try {
// 如果是 ScaledProcessingPattern优先尝试其原始 pattern 对应的值
if (key instanceof ScaledProcessingPattern scaled) {
IPatternDetails base = scaled.getOriginal();
if (base != null) {
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), base)) {
return e.getValue();
}
}
}
}
// 常规查找遍历 entrySet 避免再次调用 BiMap.get 导致递归重定向
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), key)) {
return e.getValue();
}
}
return null;
} catch (Throwable t) {
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), key)) {
return e.getValue();
}
}
return null;
}
}
}

View File

@ -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<IPatternDetails, ?> 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<IPatternDetails, ?> detailsSlotMap, Object key) {
try {
// 如果是 ScaledProcessingPattern优先尝试其原始 pattern 对应的值
if (key instanceof ScaledProcessingPattern scaled) {
IPatternDetails base = scaled.getOriginal();
if (base != null) {
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), base)) {
return e.getValue();
}
}
}
}
// 常规查找遍历 entrySet 避免再次调用 BiMap.get 导致递归重定向
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), key)) {
return e.getValue();
}
}
return null;
} catch (Throwable t) {
for (Map.Entry<IPatternDetails, ?> e : detailsSlotMap.entrySet()) {
if (Objects.equals(e.getKey(), key)) {
return e.getValue();
}
}
return null;
}
}
}

View File

@ -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",