添加智能缩放细分到供应器控制是否启用
This commit is contained in:
parent
002139c202
commit
8bebfbe4ac
|
|
@ -0,0 +1,6 @@
|
|||
package com.extendedae_plus.api;
|
||||
|
||||
public interface SmartDoublingAwarePattern {
|
||||
boolean eap$allowScaling();
|
||||
void eap$setAllowScaling(boolean allow);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.extendedae_plus.mixin.ae2;
|
||||
|
||||
import appeng.crafting.pattern.AEProcessingPattern;
|
||||
import com.extendedae_plus.api.SmartDoublingAwarePattern;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(value = AEProcessingPattern.class, remap = false)
|
||||
public class AEProcessingPatternMixin implements SmartDoublingAwarePattern {
|
||||
@Unique
|
||||
private boolean eap$allowScaling = true; // 默认允许缩放
|
||||
|
||||
@Override
|
||||
public boolean eap$allowScaling() {
|
||||
return eap$allowScaling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eap$setAllowScaling(boolean allow) {
|
||||
this.eap$allowScaling = allow;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,10 @@ package com.extendedae_plus.mixin.ae2;
|
|||
|
||||
import appeng.helpers.patternprovider.PatternProviderLogic;
|
||||
import com.extendedae_plus.api.SmartDoublingHolder;
|
||||
import com.extendedae_plus.api.SmartDoublingAwarePattern;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.PatternProviderLogicPatternsAccessor;
|
||||
import appeng.api.crafting.IPatternDetails;
|
||||
import appeng.crafting.pattern.AEProcessingPattern;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
|
@ -25,6 +29,18 @@ public class PatternProviderLogicDoublingMixin implements SmartDoublingHolder {
|
|||
@Override
|
||||
public void eap$setSmartDoubling(boolean value) {
|
||||
this.eap$smartDoubling = value;
|
||||
// 立即将开关状态应用到当前 Provider 的样板上,避免等待下一次 updatePatterns
|
||||
try {
|
||||
var list = ((PatternProviderLogicPatternsAccessor) this).eap$patterns();
|
||||
for (IPatternDetails details : list) {
|
||||
if (details instanceof AEProcessingPattern proc && proc instanceof SmartDoublingAwarePattern aware) {
|
||||
aware.eap$setAllowScaling(value);
|
||||
}
|
||||
}
|
||||
// 触发一次刷新,让网络及时拿到最新状态(也会触发 ICraftingProvider.requestUpdate(mainNode))
|
||||
((PatternProviderLogic) (Object) this).updatePatterns();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "writeToNBT", at = @At("TAIL"), remap = false)
|
||||
|
|
@ -38,4 +54,18 @@ public class PatternProviderLogicDoublingMixin implements SmartDoublingHolder {
|
|||
this.eap$smartDoubling = tag.getBoolean(EPP_SMART_DOUBLING_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "updatePatterns", at = @At("TAIL"), remap = false)
|
||||
private void eap$applySmartDoublingToPatterns(CallbackInfo ci) {
|
||||
try {
|
||||
var list = ((PatternProviderLogicPatternsAccessor) this).eap$patterns();
|
||||
boolean allow = this.eap$smartDoubling;
|
||||
for (IPatternDetails details : list) {
|
||||
if (details instanceof AEProcessingPattern proc && proc instanceof SmartDoublingAwarePattern aware) {
|
||||
aware.eap$setAllowScaling(allow);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.extendedae_plus.mixin.ae2.accessor;
|
||||
|
||||
import appeng.api.crafting.IPatternDetails;
|
||||
import appeng.helpers.patternprovider.PatternProviderLogic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = PatternProviderLogic.class, remap = false)
|
||||
public interface PatternProviderLogicPatternsAccessor {
|
||||
@Accessor("patterns")
|
||||
List<IPatternDetails> eap$patterns();
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ import appeng.crafting.inv.CraftingSimulationState;
|
|||
import appeng.crafting.pattern.AEProcessingPattern;
|
||||
import com.extendedae_plus.util.PatternScaler;
|
||||
import com.extendedae_plus.util.RequestedAmountHolder;
|
||||
import com.extendedae_plus.api.SmartDoublingAwarePattern;
|
||||
import com.extendedae_plus.content.ScaledProcessingPattern;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
|
@ -34,13 +36,33 @@ public abstract class CraftingTreeProcessMixin {
|
|||
)
|
||||
private static IPatternDetails extendedae_plus$replaceDetailsAtHead(IPatternDetails original, ICraftingService cc, CraftingCalculation job, IPatternDetails details, CraftingTreeNode craftingTreeNode) {
|
||||
try {
|
||||
// 若传入的 details 已经是缩放样板,且原始样板不允许缩放,则直接解包为原始样板
|
||||
if (details instanceof ScaledProcessingPattern sp) {
|
||||
var proc0 = sp.getOriginal();
|
||||
if (proc0 instanceof SmartDoublingAwarePattern aware0 && !aware0.eap$allowScaling()) {
|
||||
LOGGER.info("[extendedae_plus] 传入已缩放样板但已禁用,解包为原始样板并跳过缩放: requested={}", RequestedAmountHolder.get());
|
||||
return proc0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(details instanceof AEProcessingPattern proc)) return original;
|
||||
|
||||
// 若样板标记为不允许缩放,则直接跳过
|
||||
if (proc instanceof SmartDoublingAwarePattern aware && !aware.eap$allowScaling()) {
|
||||
LOGGER.info("[extendedae_plus] 智能翻倍已禁用,跳过缩放: pattern={} target={} requested={}", proc, craftingTreeNode, RequestedAmountHolder.get());
|
||||
return original;
|
||||
}
|
||||
|
||||
CraftingTreeNodeAccessor parentAcc = (CraftingTreeNodeAccessor) craftingTreeNode;
|
||||
AEKey parentTarget = parentAcc.extendedae_plus$getWhat();
|
||||
long requested = RequestedAmountHolder.get();
|
||||
// 使用当前线程栈顶的值进行缩放,不在此处清理;构造完成后应该由调用方的 pop 恢复状态
|
||||
return PatternScaler.scale(proc, parentTarget, requested);
|
||||
LOGGER.info("[extendedae_plus] 执行缩放: allowScaling={} target={} requested={}",
|
||||
(proc instanceof SmartDoublingAwarePattern aware2 ? aware2.eap$allowScaling() : null),
|
||||
parentTarget,
|
||||
requested);
|
||||
var scaled = PatternScaler.scale(proc, parentTarget, requested);
|
||||
return scaled != null ? scaled : original;
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("构建倍增样板出错", e);
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import appeng.api.stacks.AEKey;
|
|||
import appeng.api.stacks.GenericStack;
|
||||
import appeng.crafting.pattern.AEProcessingPattern;
|
||||
import com.extendedae_plus.content.ScaledProcessingPattern;
|
||||
import com.extendedae_plus.api.SmartDoublingAwarePattern;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -18,6 +19,12 @@ public final class PatternScaler {
|
|||
if (base == null) throw new IllegalArgumentException("base");
|
||||
if (target == null) throw new IllegalArgumentException("target");
|
||||
|
||||
// 双保险:若样板标记为不允许缩放,直接放弃缩放(返回 null 表示调用方应保持原样板)
|
||||
if (base instanceof SmartDoublingAwarePattern aware && !aware.eap$allowScaling()) {
|
||||
LOGGER.info("[extendedae_plus] PatternScaler: 智能翻倍禁用,跳过缩放 target={} requested={}", target, requestedAmount);
|
||||
return null;
|
||||
}
|
||||
|
||||
GenericStack[] baseSparseInputs = base.getSparseInputs();
|
||||
GenericStack[] baseSparseOutputs = base.getSparseOutputs();
|
||||
IInput[] baseInputs = base.getInputs();
|
||||
|
|
|
|||
|
|
@ -34,10 +34,12 @@
|
|||
"ae2.PatternProviderMenuAdvancedMixin",
|
||||
"ae2.PatternProviderLogicDoublingMixin",
|
||||
"ae2.PatternProviderMenuDoublingMixin",
|
||||
"ae2.AEProcessingPatternMixin",
|
||||
"ae2.accessor.MEStorageMenuAccessor",
|
||||
"ae2.accessor.PatternEncodingTermMenuAccessor",
|
||||
"ae2.accessor.PatternProviderLogicAccessor",
|
||||
"ae2.accessor.PatternProviderLogicPatternInputsAccessor",
|
||||
"ae2.accessor.PatternProviderLogicPatternsAccessor",
|
||||
"ae2.accessor.PatternProviderMenuAdvancedAccessor",
|
||||
"ae2WTlib.ContainerUWirelessExPatternTerminalMixin",
|
||||
"autopattern.CraftingCalculationAccessor",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user