移除旧版本倍增
This commit is contained in:
parent
43361b2023
commit
af0d9e25dc
|
|
@ -1,12 +0,0 @@
|
|||
package com.extendedae_plus.mixin.ae2.autopattern;
|
||||
|
||||
import appeng.api.stacks.AEKey;
|
||||
import appeng.crafting.CraftingTreeNode;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(CraftingTreeNode.class)
|
||||
public interface CraftingTreeNodeAccessor {
|
||||
@Accessor(value = "what", remap = false)
|
||||
AEKey eap$getWhat();
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.extendedae_plus.mixin.ae2.autopattern;
|
||||
|
||||
import appeng.api.stacks.KeyCounter;
|
||||
import appeng.crafting.CraftingTreeNode;
|
||||
import appeng.crafting.inv.CraftingSimulationState;
|
||||
import com.extendedae_plus.util.smartDoubling.RequestedAmountHolder;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(value = CraftingTreeNode.class, remap = false)
|
||||
public class CraftingTreeNodeMixin {
|
||||
@Inject(method = "request(Lappeng/crafting/inv/CraftingSimulationState;JLappeng/api/stacks/KeyCounter;)V",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lappeng/crafting/CraftingTreeNode;addContainerItems(Lappeng/api/stacks/AEKey;JLappeng/api/stacks/KeyCounter;)V"),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void captureRequestedAmount(CraftingSimulationState inv, long requestedAmount, KeyCounter containerItems, CallbackInfo ci) {
|
||||
// push the requestedAmount before addContainerItems is called
|
||||
RequestedAmountHolder.push(requestedAmount);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
package com.extendedae_plus.mixin.ae2.autopattern;
|
||||
|
||||
import appeng.api.crafting.IPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingService;
|
||||
import appeng.api.stacks.AEKey;
|
||||
import appeng.crafting.CraftingCalculation;
|
||||
import appeng.crafting.CraftingTreeNode;
|
||||
import appeng.crafting.CraftingTreeProcess;
|
||||
import appeng.crafting.pattern.AEProcessingPattern;
|
||||
import appeng.me.service.CraftingService;
|
||||
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
||||
import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern;
|
||||
import com.extendedae_plus.config.ModConfig;
|
||||
import com.extendedae_plus.util.smartDoubling.PatternScaler;
|
||||
import com.extendedae_plus.util.smartDoubling.RequestedAmountHolder;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.extendedae_plus.util.Logger.EAP$LOGGER;
|
||||
|
||||
/**
|
||||
* 注入 CraftingTreeProcess 构造器尾部:将 AEProcessingPattern 替换为 ScaledProcessingPattern
|
||||
* 以确保后续执行使用放大后的输入/输出视图。
|
||||
*/
|
||||
@Mixin(CraftingTreeProcess.class)
|
||||
public abstract class CraftingTreeProcessMixin {
|
||||
|
||||
@ModifyVariable(
|
||||
method = "<init>(Lappeng/api/networking/crafting/ICraftingService;Lappeng/crafting/CraftingCalculation;Lappeng/api/crafting/IPatternDetails;Lappeng/crafting/CraftingTreeNode;)V",
|
||||
at = @At("HEAD"),
|
||||
argsOnly = true,
|
||||
remap = false
|
||||
)
|
||||
private static IPatternDetails eap$replaceDetailsAtHead(IPatternDetails original,
|
||||
ICraftingService cc,
|
||||
CraftingCalculation job,
|
||||
IPatternDetails details,
|
||||
CraftingTreeNode craftingTreeNode) {
|
||||
try {
|
||||
// 若传入的 details 已经是缩放样板,且原始样板不允许缩放,则直接解包为原始样板
|
||||
if (details instanceof ScaledProcessingPattern sp) {
|
||||
var originalPattern = sp.getOriginal();
|
||||
if (originalPattern instanceof ISmartDoublingAwarePattern scalingAwarePattern && !scalingAwarePattern.eap$allowScaling()) {
|
||||
return originalPattern;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(details instanceof AEProcessingPattern processingPattern)) return original;
|
||||
|
||||
// 若样板标记为不允许缩放,则直接跳过
|
||||
if (processingPattern instanceof ISmartDoublingAwarePattern aware && !aware.eap$allowScaling()) {
|
||||
return original;
|
||||
}
|
||||
|
||||
CraftingTreeNodeAccessor parentAcc = (CraftingTreeNodeAccessor) craftingTreeNode;
|
||||
AEKey parentTarget = parentAcc.eap$getWhat();
|
||||
long requested = RequestedAmountHolder.get();
|
||||
RequestedAmountHolder.pop();
|
||||
|
||||
// 根据配置决定是否在 provider 间轮询分配请求量(默认开启)
|
||||
long perProvider = 1L;
|
||||
if (!ModConfig.INSTANCE.providerRoundRobinEnable) {
|
||||
// 关闭轮询:直接使用完整请求量,不需要查询 provider 列表
|
||||
perProvider = requested;
|
||||
if (perProvider <= 0) perProvider = 1L;
|
||||
} else {
|
||||
// 计算 provider 数量
|
||||
Iterable<ICraftingProvider> providerIterable = ((CraftingService) cc).getProviders(original);
|
||||
List<ICraftingProvider> providerList = ((CraftingProviderListAccessor) providerIterable).getProviders();
|
||||
int size = providerList == null ? 0 : providerList.size();
|
||||
|
||||
// 将 requested 在 providers 间均分,向上取整保证每个 provider 分配整数且总量不少于 requested
|
||||
if (size > 0) {
|
||||
perProvider = requested / size + ((requested % size) == 0 ? 0 : 1);
|
||||
if (perProvider <= 0) perProvider = 1L;
|
||||
}
|
||||
}
|
||||
|
||||
// 使用每-provider 的分配量来缩放样板
|
||||
var scaled = PatternScaler.scale(processingPattern, parentTarget, perProvider);
|
||||
return scaled != null ? scaled : original;
|
||||
} catch (Exception e) {
|
||||
EAP$LOGGER.warn("构建倍增样板出错", e);
|
||||
return original;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user