修复相同输出不同倍率或样板其他不同时造成的NPE

This commit is contained in:
C-H716 2025-11-07 21:41:53 +08:00
parent 2dd15ae686
commit d41b2faceb
8 changed files with 44 additions and 80 deletions

View File

@ -97,7 +97,7 @@ dependencies {
// Runtime test // Runtime test
modRuntimeOnly "curse.maven:curios-309927:${curios_version}" modRuntimeOnly "curse.maven:curios-309927:${curios_version}"
modRuntimeOnly "curse.maven:jade-324717:${jade_version}" modRuntimeOnly "curse.maven:jade-324717:${jade_version}"
modRuntimeOnly "curse.maven:architectury-api-419699:${architectury_version}" modRuntimeOnly "dev.architectury:architectury-forge:9.2.14"
modRuntimeOnly "curse.maven:applied-energistics-2-wireless-terminals-459929:${wireless_terminals_version}" modRuntimeOnly "curse.maven:applied-energistics-2-wireless-terminals-459929:${wireless_terminals_version}"
modRuntimeOnly "mezz.jei:jei-${minecraft_version}-forge:${jei_version}" modRuntimeOnly "mezz.jei:jei-${minecraft_version}-forge:${jei_version}"
modRuntimeOnly "curse.maven:cloth-config-348521:5729105" modRuntimeOnly "curse.maven:cloth-config-348521:5729105"

View File

@ -0,0 +1,7 @@
package com.extendedae_plus.api.smartDoubling;
import appeng.api.networking.IGrid;
public interface ICraftingCalculationExt {
IGrid getGrid();
}

View File

@ -1,8 +0,0 @@
package com.extendedae_plus.api.smartDoubling;
import appeng.crafting.CraftingTreeProcess;
public interface ICraftingSimulationStateExt {
void setSourceProcess(CraftingTreeProcess process);
CraftingTreeProcess getSourceProcess();
}

View File

@ -1,7 +0,0 @@
package com.extendedae_plus.api.smartDoubling;
import appeng.api.networking.crafting.ICraftingService;
public interface ICraftingTreeProcessExt {
ICraftingService getCraftingService();
}

View File

@ -0,0 +1,30 @@
package com.extendedae_plus.mixin.ae2.autopattern;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.CalculationStrategy;
import appeng.api.networking.crafting.ICraftingSimulationRequester;
import appeng.api.stacks.GenericStack;
import appeng.crafting.CraftingCalculation;
import com.extendedae_plus.api.smartDoubling.ICraftingCalculationExt;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings({"AddedMixinMembersNamePattern"})
@Mixin(value = CraftingCalculation.class, remap = false)
public class CraftingCalculationMixin implements ICraftingCalculationExt {
@Unique private IGrid grid;
@Inject(method = "<init>",at = @At("RETURN"))
private void init(Level level, IGrid grid, ICraftingSimulationRequester simRequester, GenericStack output, CalculationStrategy strategy, CallbackInfo ci) {
this.grid = grid;
}
@Override
public IGrid getGrid() {
return grid;
}
}

View File

@ -3,19 +3,16 @@ package com.extendedae_plus.mixin.ae2.autopattern;
import appeng.api.crafting.IPatternDetails; import appeng.api.crafting.IPatternDetails;
import appeng.crafting.CraftingCalculation; import appeng.crafting.CraftingCalculation;
import appeng.crafting.CraftingPlan; import appeng.crafting.CraftingPlan;
import appeng.crafting.CraftingTreeProcess;
import appeng.crafting.inv.CraftingSimulationState; import appeng.crafting.inv.CraftingSimulationState;
import appeng.crafting.pattern.AEProcessingPattern; import appeng.crafting.pattern.AEProcessingPattern;
import appeng.me.service.CraftingService; import appeng.me.service.CraftingService;
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern; import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
import com.extendedae_plus.api.smartDoubling.ICraftingSimulationStateExt; import com.extendedae_plus.api.smartDoubling.ICraftingCalculationExt;
import com.extendedae_plus.api.smartDoubling.ICraftingTreeProcessExt;
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 com.extendedae_plus.util.smartDoubling.PatternScaler; import com.extendedae_plus.util.smartDoubling.PatternScaler;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@ -23,11 +20,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@SuppressWarnings({"AddedMixinMembersNamePattern"})
@Mixin(value = CraftingSimulationState.class, remap = false) @Mixin(value = CraftingSimulationState.class, remap = false)
public abstract class CraftingSimulationStateMixin implements ICraftingSimulationStateExt { public abstract class CraftingSimulationStateMixin {
@Unique private CraftingTreeProcess sourceProcess;
/** /**
* 替换 CraftingPlan 构建逻辑在此统一处理样板倍率 * 替换 CraftingPlan 构建逻辑在此统一处理样板倍率
*/ */
@ -64,15 +58,12 @@ public abstract class CraftingSimulationStateMixin implements ICraftingSimulatio
perCraftLimit = ModConfig.INSTANCE.smartScalingMaxMultiplier; perCraftLimit = ModConfig.INSTANCE.smartScalingMaxMultiplier;
} }
// 获取供应器数量
CraftingTreeProcess process = ((ICraftingSimulationStateExt) state).getSourceProcess();
CraftingService craftingService = (CraftingService) ((ICraftingTreeProcessExt) process).getCraftingService();
long providerCount = Iterables.size(craftingService.getProviders(processingPattern));
if (providerCount <= 0) providerCount = 1;
if (perCraftLimit <= 0) { if (perCraftLimit <= 0) {
// 检查是否开启 provider 轮询分配功能 // 检查是否开启 provider 轮询分配功能
if (ModConfig.INSTANCE.providerRoundRobinEnable) { if (ModConfig.INSTANCE.providerRoundRobinEnable) {
CraftingService craftingService = (CraftingService) ((ICraftingCalculationExt) calculation).getGrid().getCraftingService();
int providerCount = Math.max(Iterables.size(craftingService.getProviders(processingPattern)), 1);
long base = totalAmount / providerCount; long base = totalAmount / providerCount;
long remainder = totalAmount % providerCount; long remainder = totalAmount % providerCount;
@ -112,14 +103,4 @@ public abstract class CraftingSimulationStateMixin implements ICraftingSimulatio
crafts.clear(); crafts.clear();
crafts.putAll(finalCrafts); crafts.putAll(finalCrafts);
} }
@Override
public CraftingTreeProcess getSourceProcess() {
return this.sourceProcess;
}
@Override
public void setSourceProcess(CraftingTreeProcess process) {
this.sourceProcess = process;
}
} }

View File

@ -1,39 +0,0 @@
package com.extendedae_plus.mixin.ae2.autopattern;
import appeng.api.crafting.IPatternDetails;
import appeng.api.networking.crafting.ICraftingService;
import appeng.crafting.CraftingCalculation;
import appeng.crafting.CraftingTreeNode;
import appeng.crafting.CraftingTreeProcess;
import appeng.crafting.inv.CraftingSimulationState;
import com.extendedae_plus.api.smartDoubling.ICraftingSimulationStateExt;
import com.extendedae_plus.api.smartDoubling.ICraftingTreeProcessExt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings({"AddedMixinMembersNamePattern"})
@Mixin(value = CraftingTreeProcess.class, remap = false)
public class CraftingTreeProcessMixin implements ICraftingTreeProcessExt {
@Unique private ICraftingService craftingService;
@Inject(method = "<init>",at = @At("RETURN"))
private void init(ICraftingService cc, CraftingCalculation job, IPatternDetails details, CraftingTreeNode craftingTreeNode, CallbackInfo ci) {
this.craftingService = cc;
}
@Inject(
method = "request",
at = @At("HEAD")
)
private void bindSimulationState(CraftingSimulationState inv, long times, CallbackInfo ci) {
((ICraftingSimulationStateExt) inv).setSourceProcess((CraftingTreeProcess) (Object) this);
}
@Override
public ICraftingService getCraftingService() {
return this.craftingService;
}
}

View File

@ -51,10 +51,10 @@
"ae2.accessor.PatternEncodingTermMenuAccessor", "ae2.accessor.PatternEncodingTermMenuAccessor",
"ae2.accessor.PatternProviderLogicAccessor", "ae2.accessor.PatternProviderLogicAccessor",
"ae2.accessor.PatternProviderMenuAccessor", "ae2.accessor.PatternProviderMenuAccessor",
"ae2.autopattern.CraftingCalculationMixin",
"ae2.autopattern.CraftingServiceGetProvidersMixin", "ae2.autopattern.CraftingServiceGetProvidersMixin",
"ae2.autopattern.CraftingSimulationStateAccessor", "ae2.autopattern.CraftingSimulationStateAccessor",
"ae2.autopattern.CraftingSimulationStateMixin", "ae2.autopattern.CraftingSimulationStateMixin",
"ae2.autopattern.CraftingTreeProcessMixin",
"ae2.autopattern.PatternProviderLogicContainsRedirectMixin", "ae2.autopattern.PatternProviderLogicContainsRedirectMixin",
"ae2.compat.PatternProviderCompatMixin", "ae2.compat.PatternProviderCompatMixin",
"ae2.compat.PatternProviderLogicCompatMixin", "ae2.compat.PatternProviderLogicCompatMixin",