feat: 智能倍增避免对小请求产生额外包装与开销,默认阈值为 4,可在配置中调整

This commit is contained in:
C-H716 2025-09-04 02:21:15 +08:00
parent d4095e64ea
commit b717d33f8f
2 changed files with 18 additions and 8 deletions

View File

@ -11,6 +11,7 @@ public final class ModConfigs {
public static final ForgeConfigSpec.BooleanValue PROVIDER_ROUND_ROBIN_ENABLE;
public static final ForgeConfigSpec.BooleanValue PATTERN_TERMINAL_SHOW_SLOTS_DEFAULT;
public static final ForgeConfigSpec.IntValue SMART_SCALING_MAX_MULTIPLIER;
public static final ForgeConfigSpec.IntValue SMART_SCALING_MIN_BENEFIT_FACTOR;
static {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
@ -61,6 +62,13 @@ public final class ModConfigs {
"此倍数是针对单次样板产出的放大倍数上限,用于限制一次推送中按倍增缩放的规模")
.defineInRange("smartScalingMaxMultiplier", 0, 0, 1048576);
// 智能倍增最小收益因子 requestedAmount < perOperationTarget * 此因子则不启用缩放默认 4
SMART_SCALING_MIN_BENEFIT_FACTOR = builder
.comment(
"智能倍增最小收益因子(默认 4",
"当目标请求量小于 perOperationTarget * 此因子 时,智能倍增将不被启用以避免无意义包装")
.defineInRange("smartScalingMinBenefitFactor", 4, 1, 1024);
// 模式访问终端ExtendedAE 图样终端默认是否显示槽位渲染SlotsRow
// true: 默认显示可通过界面按钮临时隐藏false: 默认隐藏可通过按钮显示
PATTERN_TERMINAL_SHOW_SLOTS_DEFAULT = builder

View File

@ -1,15 +1,11 @@
package com.extendedae_plus.util;
import appeng.api.crafting.IPatternDetails.IInput;
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 com.extendedae_plus.config.ModConfigs;
import static com.extendedae_plus.util.ExtendedAELogger.LOGGER;
import com.extendedae_plus.content.ScaledProcessingPattern;
public final class PatternScaler {
private PatternScaler() {
@ -24,9 +20,6 @@ public final class PatternScaler {
return null;
}
GenericStack[] baseSparseInputs = base.getSparseInputs();
GenericStack[] baseSparseOutputs = base.getSparseOutputs();
IInput[] baseInputs = base.getInputs();
GenericStack[] baseOutputs = base.getOutputs();
// 新逻辑不再对样板进行单位化处理
@ -61,6 +54,15 @@ public final class PatternScaler {
long needed = requestedAmount / perOperationTarget + ((requestedAmount % perOperationTarget) == 0 ? 0 : 1);
multiplier = needed <= 1L ? 1L : needed;
}
// 小请求绕过若请求量小且不会带来收益则不启用缩放返回 null
try {
int minBenefit = ModConfigs.SMART_SCALING_MIN_BENEFIT_FACTOR.get();
if (minBenefit > 1 && requestedAmount > 0 && requestedAmount < perOperationTarget * (long) minBenefit) {
return null;
}
} catch (Throwable ignore) {
// 配置读取异常时保持默认行为不绕过
}
// 应用配置的最大倍数上限0 表示不限制
try {
int maxMul = ModConfigs.SMART_SCALING_MAX_MULTIPLIER.get();