feat: 添加对高级ae的高级处理样板倍增支持
This commit is contained in:
parent
a6c6691f6f
commit
4c407e412b
|
|
@ -15,7 +15,7 @@ import java.util.Objects;
|
||||||
* 缩放后的处理样板,结构完全模拟 AEProcessingPattern。
|
* 缩放后的处理样板,结构完全模拟 AEProcessingPattern。
|
||||||
* 保持 sparse/condensed/inputs 的一致性,同时保存原始样板。
|
* 保持 sparse/condensed/inputs 的一致性,同时保存原始样板。
|
||||||
*/
|
*/
|
||||||
public final class ScaledProcessingPattern implements IPatternDetails {
|
public class ScaledProcessingPattern implements IPatternDetails {
|
||||||
|
|
||||||
// 最小化实例字段:只保留原始样板引用、定义和倍数
|
// 最小化实例字段:只保留原始样板引用、定义和倍数
|
||||||
private final AEProcessingPattern original; // 原始样板引用
|
private final AEProcessingPattern original; // 原始样板引用
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.extendedae_plus.ae.api.crafting;
|
||||||
|
|
||||||
|
import appeng.api.stacks.AEItemKey;
|
||||||
|
import appeng.api.stacks.AEKey;
|
||||||
|
import appeng.api.stacks.GenericStack;
|
||||||
|
import appeng.api.stacks.KeyCounter;
|
||||||
|
import appeng.crafting.pattern.AEProcessingPattern;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.pedroksl.advanced_ae.common.patterns.AdvPatternDetails;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advanced AE 扩展版,额外实现 AdvPatternDetails 接口。
|
||||||
|
* 仅在 Advanced AE 加载时使用。
|
||||||
|
*/
|
||||||
|
public final class ScaledProcessingPatternAdv extends ScaledProcessingPattern implements AdvPatternDetails {
|
||||||
|
|
||||||
|
private final AdvPatternDetails adv;
|
||||||
|
|
||||||
|
public ScaledProcessingPatternAdv(AEProcessingPattern original, AEItemKey definition, long multiplier) {
|
||||||
|
super(original, definition, multiplier);
|
||||||
|
this.adv = (AdvPatternDetails) original;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean directionalInputsSet() {
|
||||||
|
return adv.directionalInputsSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<AEKey, Direction> getDirectionMap() {
|
||||||
|
return adv.getDirectionMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction getDirectionSideForInputKey(AEKey key) {
|
||||||
|
return adv.getDirectionSideForInputKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushInputsToExternalInventory(KeyCounter[] inputHolder, PatternInputSink inputSink) {
|
||||||
|
// 使用 lazy 计算的 sparseInputs 与 inputs 来驱动;当两者长度一致时直接委托
|
||||||
|
GenericStack[] sInputs = getSparseInputs();
|
||||||
|
IInput[] ins = getInputs();
|
||||||
|
if (sInputs.length == ins.length) {
|
||||||
|
super.pushInputsToExternalInventory(inputHolder, inputSink);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyCounter allInputs = new KeyCounter();
|
||||||
|
for (KeyCounter counter : inputHolder) {
|
||||||
|
allInputs.addAll(counter);
|
||||||
|
}
|
||||||
|
for (GenericStack sparseInput : sInputs) {
|
||||||
|
if (sparseInput != null) {
|
||||||
|
AEKey key = sparseInput.what();
|
||||||
|
long amount = sparseInput.amount();
|
||||||
|
long available = allInputs.get(key);
|
||||||
|
if (available < amount) {
|
||||||
|
throw new RuntimeException("Expected at least %d of %s when pushing scaled pattern, but only %d available"
|
||||||
|
.formatted(amount, key, available));
|
||||||
|
}
|
||||||
|
inputSink.pushInput(key, amount);
|
||||||
|
allInputs.remove(key, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,20 +36,24 @@ public abstract class CraftingTreeProcessMixin {
|
||||||
argsOnly = true,
|
argsOnly = true,
|
||||||
remap = false
|
remap = false
|
||||||
)
|
)
|
||||||
private static IPatternDetails eap$replaceDetailsAtHead(IPatternDetails original, ICraftingService cc, CraftingCalculation job, IPatternDetails details, CraftingTreeNode craftingTreeNode) {
|
private static IPatternDetails eap$replaceDetailsAtHead(IPatternDetails original,
|
||||||
|
ICraftingService cc,
|
||||||
|
CraftingCalculation job,
|
||||||
|
IPatternDetails details,
|
||||||
|
CraftingTreeNode craftingTreeNode) {
|
||||||
try {
|
try {
|
||||||
// 若传入的 details 已经是缩放样板,且原始样板不允许缩放,则直接解包为原始样板
|
// 若传入的 details 已经是缩放样板,且原始样板不允许缩放,则直接解包为原始样板
|
||||||
if (details instanceof ScaledProcessingPattern sp) {
|
if (details instanceof ScaledProcessingPattern sp) {
|
||||||
var proc0 = sp.getOriginal();
|
var originalPattern = sp.getOriginal();
|
||||||
if (proc0 instanceof ISmartDoublingAwarePattern aware0 && !aware0.eap$allowScaling()) {
|
if (originalPattern instanceof ISmartDoublingAwarePattern scalingAwarePattern && !scalingAwarePattern.eap$allowScaling()) {
|
||||||
return proc0;
|
return originalPattern;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(details instanceof AEProcessingPattern proc)) return original;
|
if (!(details instanceof AEProcessingPattern processingPattern)) return original;
|
||||||
|
|
||||||
// 若样板标记为不允许缩放,则直接跳过
|
// 若样板标记为不允许缩放,则直接跳过
|
||||||
if (proc instanceof ISmartDoublingAwarePattern aware && !aware.eap$allowScaling()) {
|
if (processingPattern instanceof ISmartDoublingAwarePattern aware && !aware.eap$allowScaling()) {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +93,7 @@ public abstract class CraftingTreeProcessMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用每-provider 的分配量来缩放样板
|
// 使用每-provider 的分配量来缩放样板
|
||||||
var scaled = PatternScaler.scale(proc, parentTarget, perProvider);
|
var scaled = PatternScaler.scale(processingPattern, parentTarget, perProvider);
|
||||||
return scaled != null ? scaled : original;
|
return scaled != null ? scaled : original;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
EAP$LOGGER.warn("构建倍增样板出错", e);
|
EAP$LOGGER.warn("构建倍增样板出错", e);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@ import appeng.api.stacks.AEKey;
|
||||||
import appeng.api.stacks.GenericStack;
|
import appeng.api.stacks.GenericStack;
|
||||||
import appeng.crafting.pattern.AEProcessingPattern;
|
import appeng.crafting.pattern.AEProcessingPattern;
|
||||||
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
||||||
|
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPatternAdv;
|
||||||
import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern;
|
import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern;
|
||||||
import com.extendedae_plus.config.ModConfig;
|
import com.extendedae_plus.config.ModConfig;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
|
||||||
public final class PatternScaler {
|
public final class PatternScaler {
|
||||||
private PatternScaler() {
|
private PatternScaler() {
|
||||||
|
|
@ -72,7 +74,19 @@ public final class PatternScaler {
|
||||||
} catch (Throwable ignore) {
|
} catch (Throwable ignore) {
|
||||||
// 配置读取异常时不施加上限
|
// 配置读取异常时不施加上限
|
||||||
}
|
}
|
||||||
|
if (ModList.get().isLoaded("advanced_ae")) {
|
||||||
|
// 如果加载了 Advanced AE 且 base 实现了 AdvPatternDetails,返回兼容版
|
||||||
|
try {
|
||||||
|
// 软依赖,不直接 import advIface
|
||||||
|
Class<?> advIface = Class.forName("net.pedroksl.advanced_ae.common.patterns.AdvPatternDetails");
|
||||||
|
if (advIface.isInstance(base)) {
|
||||||
|
// 直接 new ScaledProcessingPatternAdv,父类字段会正常初始化
|
||||||
|
return new ScaledProcessingPatternAdv(base, base.getDefinition(), multiplier);
|
||||||
|
}
|
||||||
|
} catch (Throwable ignore) {
|
||||||
|
// 如果 Advanced AE 不存在或反射失败,就忽略,继续走普通逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
// 仅使用 multiplier 构建轻量化 ScaledProcessingPattern(具体视图按需计算)
|
// 仅使用 multiplier 构建轻量化 ScaledProcessingPattern(具体视图按需计算)
|
||||||
return new ScaledProcessingPattern(base, base.getDefinition(), multiplier);
|
return new ScaledProcessingPattern(base, base.getDefinition(), multiplier);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user