diff --git a/build.gradle b/build.gradle index 2436a25..ae8f2af 100644 --- a/build.gradle +++ b/build.gradle @@ -97,7 +97,7 @@ dependencies { // Runtime test modRuntimeOnly "curse.maven:curios-309927:${curios_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 "mezz.jei:jei-${minecraft_version}-forge:${jei_version}" modRuntimeOnly "curse.maven:cloth-config-348521:5729105" diff --git a/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingCalculationExt.java b/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingCalculationExt.java new file mode 100644 index 0000000..55c707a --- /dev/null +++ b/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingCalculationExt.java @@ -0,0 +1,7 @@ +package com.extendedae_plus.api.smartDoubling; + +import appeng.api.networking.IGrid; + +public interface ICraftingCalculationExt { + IGrid getGrid(); +} diff --git a/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingSimulationStateExt.java b/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingSimulationStateExt.java deleted file mode 100644 index 0758f54..0000000 --- a/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingSimulationStateExt.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.extendedae_plus.api.smartDoubling; - -import appeng.crafting.CraftingTreeProcess; - -public interface ICraftingSimulationStateExt { - void setSourceProcess(CraftingTreeProcess process); - CraftingTreeProcess getSourceProcess(); -} \ No newline at end of file diff --git a/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingTreeProcessExt.java b/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingTreeProcessExt.java deleted file mode 100644 index ee6d315..0000000 --- a/src/main/java/com/extendedae_plus/api/smartDoubling/ICraftingTreeProcessExt.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.extendedae_plus.api.smartDoubling; - -import appeng.api.networking.crafting.ICraftingService; - -public interface ICraftingTreeProcessExt { - ICraftingService getCraftingService(); -} diff --git a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingCalculationMixin.java b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingCalculationMixin.java new file mode 100644 index 0000000..770e0c3 --- /dev/null +++ b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingCalculationMixin.java @@ -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 = "",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; + } +} diff --git a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingSimulationStateMixin.java b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingSimulationStateMixin.java index 01bfe06..c923afa 100644 --- a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingSimulationStateMixin.java +++ b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingSimulationStateMixin.java @@ -3,19 +3,16 @@ package com.extendedae_plus.mixin.ae2.autopattern; import appeng.api.crafting.IPatternDetails; import appeng.crafting.CraftingCalculation; import appeng.crafting.CraftingPlan; -import appeng.crafting.CraftingTreeProcess; import appeng.crafting.inv.CraftingSimulationState; import appeng.crafting.pattern.AEProcessingPattern; import appeng.me.service.CraftingService; import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern; -import com.extendedae_plus.api.smartDoubling.ICraftingSimulationStateExt; -import com.extendedae_plus.api.smartDoubling.ICraftingTreeProcessExt; +import com.extendedae_plus.api.smartDoubling.ICraftingCalculationExt; import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern; import com.extendedae_plus.config.ModConfig; import com.extendedae_plus.util.smartDoubling.PatternScaler; import com.google.common.collect.Iterables; 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.CallbackInfoReturnable; @@ -23,11 +20,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.LinkedHashMap; import java.util.Map; -@SuppressWarnings({"AddedMixinMembersNamePattern"}) @Mixin(value = CraftingSimulationState.class, remap = false) -public abstract class CraftingSimulationStateMixin implements ICraftingSimulationStateExt { - @Unique private CraftingTreeProcess sourceProcess; - +public abstract class CraftingSimulationStateMixin { /** * 替换 CraftingPlan 构建逻辑,在此统一处理样板倍率 */ @@ -64,15 +58,12 @@ public abstract class CraftingSimulationStateMixin implements ICraftingSimulatio 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) { // 检查是否开启 provider 轮询分配功能 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 remainder = totalAmount % providerCount; @@ -112,14 +103,4 @@ public abstract class CraftingSimulationStateMixin implements ICraftingSimulatio crafts.clear(); crafts.putAll(finalCrafts); } - - @Override - public CraftingTreeProcess getSourceProcess() { - return this.sourceProcess; - } - - @Override - public void setSourceProcess(CraftingTreeProcess process) { - this.sourceProcess = process; - } } diff --git a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingTreeProcessMixin.java b/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingTreeProcessMixin.java deleted file mode 100644 index fe28216..0000000 --- a/src/main/java/com/extendedae_plus/mixin/ae2/autopattern/CraftingTreeProcessMixin.java +++ /dev/null @@ -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 = "",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; - } -} diff --git a/src/main/resources/extendedae_plus.mixins.json b/src/main/resources/extendedae_plus.mixins.json index 24eb674..987b176 100644 --- a/src/main/resources/extendedae_plus.mixins.json +++ b/src/main/resources/extendedae_plus.mixins.json @@ -51,10 +51,10 @@ "ae2.accessor.PatternEncodingTermMenuAccessor", "ae2.accessor.PatternProviderLogicAccessor", "ae2.accessor.PatternProviderMenuAccessor", + "ae2.autopattern.CraftingCalculationMixin", "ae2.autopattern.CraftingServiceGetProvidersMixin", "ae2.autopattern.CraftingSimulationStateAccessor", "ae2.autopattern.CraftingSimulationStateMixin", - "ae2.autopattern.CraftingTreeProcessMixin", "ae2.autopattern.PatternProviderLogicContainsRedirectMixin", "ae2.compat.PatternProviderCompatMixin", "ae2.compat.PatternProviderLogicCompatMixin",