diff options
author | miozune <miozune@gmail.com> | 2023-12-05 00:02:31 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 16:02:31 +0100 |
commit | 2a11aa84b61c1e5c97768edec81e9e9169315fa9 (patch) | |
tree | 8544d663c3318d4a4e1dcc9faf8ebc5357e13e7a /src/main/java | |
parent | 6624299effd1eee77b0e90c45d32f6279ff5c821 (diff) | |
download | GT5-Unofficial-2a11aa84b61c1e5c97768edec81e9e9169315fa9.tar.gz GT5-Unofficial-2a11aa84b61c1e5c97768edec81e9e9169315fa9.tar.bz2 GT5-Unofficial-2a11aa84b61c1e5c97768edec81e9e9169315fa9.zip |
Add API to limit number of recipe outputs (#2390)
Diffstat (limited to 'src/main/java')
3 files changed, 37 insertions, 12 deletions
diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java index 72dda0ddec..841fd07bba 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java @@ -58,6 +58,22 @@ public interface IVoidable { List<? extends IFluidStore> getFluidOutputSlots(FluidStack[] toOutput); /** + * @return How many slots of items this machine can output per recipe. Item outputs whose slot number + * exceeding this limit will be voided. + */ + default int getItemOutputLimit() { + return Integer.MAX_VALUE; + } + + /** + * @return How many slots of fluids this machine can output per recipe. Fluid outputs whose slot number + * exceeding this limit will be voided. + */ + default int getFluidOutputLimit() { + return Integer.MAX_VALUE; + } + + /** * @return If this machine has ability to dump item outputs to ME network. * This doesn't need to check if it can actually dump to ME, * as this might be called every tick and cause lag. diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index 64dd8cba96..0f0dc4549f 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -1,5 +1,6 @@ package gregtech.api.util; +import java.util.Arrays; import java.util.Objects; import java.util.function.Function; @@ -377,6 +378,13 @@ public class GT_ParallelHelper { maxParallel *= batchModifier; } + final ItemStack[] truncatedItemOutputs = recipe.mOutputs != null + ? Arrays.copyOfRange(recipe.mOutputs, 0, Math.min(machine.getItemOutputLimit(), recipe.mOutputs.length)) + : new ItemStack[0]; + final FluidStack[] truncatedFluidOutputs = recipe.mFluidOutputs != null ? Arrays + .copyOfRange(recipe.mFluidOutputs, 0, Math.min(machine.getFluidOutputLimit(), recipe.mFluidOutputs.length)) + : new FluidStack[0]; + SingleRecipeCheck recipeCheck = null; SingleRecipeCheck.Builder tSingleRecipeCheckBuilder = null; if (isRecipeLocked && singleRecipeMachine != null) { @@ -399,8 +407,8 @@ public class GT_ParallelHelper { } VoidProtectionHelper voidProtectionHelper = new VoidProtectionHelper(); voidProtectionHelper.setMachine(machine) - .setItemOutputs(recipe.mOutputs) - .setFluidOutputs(recipe.mFluidOutputs) + .setItemOutputs(truncatedItemOutputs) + .setFluidOutputs(truncatedFluidOutputs) .setMaxParallel(maxParallel) .build(); maxParallel = Math.min(voidProtectionHelper.getMaxParallel(), maxParallel); @@ -466,11 +474,11 @@ public class GT_ParallelHelper { // If we want to calculate outputs we do it here if (calculateOutputs && currentParallel > 0) { - if (recipe.mOutputs != null) { - calculateItemOutputs(); + if (truncatedItemOutputs.length > 0) { + calculateItemOutputs(truncatedItemOutputs); } - if (recipe.mFluidOutputs != null) { - calculateFluidOutputs(); + if (truncatedFluidOutputs.length > 0) { + calculateFluidOutputs(truncatedFluidOutputs); } } result = CheckRecipeResultRegistry.SUCCESSFUL; @@ -491,13 +499,13 @@ public class GT_ParallelHelper { fluidInputs = fluidInputsToUse; } - protected void calculateItemOutputs() { + private void calculateItemOutputs(ItemStack[] truncatedItemOutputs) { if (customItemOutputCalculation != null) { itemOutputs = customItemOutputCalculation.apply(currentParallel); return; } - itemOutputs = new ItemStack[recipe.mOutputs.length]; - for (int i = 0; i < recipe.mOutputs.length; i++) { + itemOutputs = new ItemStack[truncatedItemOutputs.length]; + for (int i = 0; i < truncatedItemOutputs.length; i++) { if (recipe.getOutputChance(i) >= 10000) { ItemStack item = recipe.getOutput(i) .copy(); @@ -523,13 +531,13 @@ public class GT_ParallelHelper { } } - protected void calculateFluidOutputs() { + private void calculateFluidOutputs(FluidStack[] truncatedFluidOutputs) { if (customFluidOutputCalculation != null) { fluidOutputs = customFluidOutputCalculation.apply(currentParallel); return; } - fluidOutputs = new FluidStack[recipe.mFluidOutputs.length]; - for (int i = 0; i < recipe.mFluidOutputs.length; i++) { + fluidOutputs = new FluidStack[truncatedFluidOutputs.length]; + for (int i = 0; i < truncatedFluidOutputs.length; i++) { if (recipe.getFluidOutput(i) == null) { fluidOutputs[i] = null; } else { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index 68828e55c4..3b6c868977 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -729,6 +729,7 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile .orElseGet(() -> StatCollector.translateToLocalFormatted("GT5U.gui.text.drill_offline_generic"))); } + @Override public boolean supportsVoidProtection() { return true; } |