Skip to content

Commit

Permalink
fix crash if can't parallel (oops,,,), steam machine parallel (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
screret authored May 5, 2024
1 parent a63a429 commit 0dff0ce
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
@AllArgsConstructor
public class ParallelLogic {

@Nullable
public static Pair<GTRecipe, Integer> applyParallel(MetaMachine machine, @Nullable GTRecipe recipe, int parallelLimit, boolean modifyDuration) {
if (recipe == null) {
return null;
}
@NotNull
public static Pair<GTRecipe, Integer> applyParallel(MetaMachine machine, @NotNull GTRecipe recipe, int parallelLimit, boolean modifyDuration) {
if (machine instanceof IRecipeLogicMachine rlm) {
return doParallelRecipes(recipe, rlm, parallelLimit, modifyDuration);
}
return null;
return Pair.of(recipe, 1);
}

/**
Expand All @@ -53,9 +50,9 @@ public static int getMaxRecipeMultiplier(@NotNull GTRecipe recipe, @NotNull IRec
multipliers.add(cap.getMaxParallelRatio(holder, recipe, parallelAmount));
}
}
if (multipliers.intStream().allMatch(value -> value == Integer.MAX_VALUE)) {
return 0;
}



// tick inputs.
for (RecipeCapability<?> cap : recipe.tickInputs.keySet()) {
if (cap.doMatchInRecipe()) {
Expand Down Expand Up @@ -185,14 +182,14 @@ public static int limitByOutputMerging(@NotNull GTRecipe recipe, @NotNull IRecip

// At this point, the recipe is already trimmed according to the item and fluid output limit, so we just need to
// take care of voiding
@Nullable
@NotNull
public static Pair<GTRecipe, Integer> doParallelRecipes(@NotNull GTRecipe currentRecipe,
@NotNull IRecipeLogicMachine machine,
int parallelAmount, boolean modifyDuration) {
@NotNull IRecipeLogicMachine machine,
int parallelAmount, boolean modifyDuration) {
// First check if we are limited by recipe inputs. This can short circuit a lot of consecutive checking
int multiplierByInputs = getMaxRecipeMultiplier(currentRecipe, machine, parallelAmount);
if (multiplierByInputs == 0) {
return null;
return Pair.of(currentRecipe, 1);
}

// Simulate the merging of the maximum amount of recipes that can be run with these items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import net.minecraft.MethodsReturnNonnullByDefault;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -12,5 +13,5 @@
@FunctionalInterface
public interface RecipeModifier {
@Nullable
GTRecipe apply(MetaMachine machine, @Nullable GTRecipe recipe);
GTRecipe apply(MetaMachine machine, @NotNull GTRecipe recipe);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import net.minecraft.MethodsReturnNonnullByDefault;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -19,11 +20,13 @@ public RecipeModifierList(RecipeModifier... modifiers) {

@Nullable
@Override
public GTRecipe apply(MetaMachine machine, @Nullable GTRecipe recipe) {
public GTRecipe apply(MetaMachine machine, @NotNull GTRecipe recipe) {
GTRecipe modifiedRecipe = recipe;

for (RecipeModifier modifier : modifiers) {
modifiedRecipe = modifier.apply(machine, modifiedRecipe);
if (modifiedRecipe != null) {
modifiedRecipe = modifier.apply(machine, modifiedRecipe);
}
}

return modifiedRecipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public ElectricOverclockModifier(OverclockingLogic overclockingLogic) {

@Nullable
@Override
public GTRecipe apply(MetaMachine machine, @Nullable GTRecipe recipe) {
if (recipe == null) {
return null;
}
public GTRecipe apply(MetaMachine machine, @NotNull GTRecipe recipe) {
if (machine instanceof ITieredMachine tieredMachine && RecipeHelper.getRecipeEUtTier(recipe) > tieredMachine.getTier()) {
return null;
}
Expand Down Expand Up @@ -102,7 +99,7 @@ public static Pair<GTRecipe, Integer> accurateParallel(MetaMachine machine, @Not
return ParallelLogic.applyParallel(machine, recipe, maxParallel, modifyDuration);
}

public static Pair<GTRecipe, Integer> hatchParallel(MetaMachine machine, @Nullable GTRecipe recipe, boolean modifyDuration) {
public static Pair<GTRecipe, Integer> hatchParallel(MetaMachine machine, @NotNull GTRecipe recipe, boolean modifyDuration) {
if (machine instanceof IMultiController controller && controller.isFormed()) {
Optional<IParallelHatch> optional = controller.getParts().stream().filter(IParallelHatch.class::isInstance).map(IParallelHatch.class::cast).findAny();
if (optional.isPresent()) {
Expand Down Expand Up @@ -130,10 +127,7 @@ public static GTRecipe crackerOverclock(MetaMachine machine, @NotNull GTRecipe r
return null;
}

public static GTRecipe ebfOverclock(MetaMachine machine, @Nullable GTRecipe recipe) {
if (recipe == null) {
return null;
}
public static GTRecipe ebfOverclock(MetaMachine machine, @NotNull GTRecipe recipe) {
if (machine instanceof CoilWorkableElectricMultiblockMachine coilMachine) {
final var blastFurnaceTemperature = coilMachine.getCoilType().getCoilTemperature() + 100 * Math.max(0, coilMachine.getTier() - GTValues.MV);
if (!recipe.data.contains("ebf_temp") || recipe.data.getInt("ebf_temp") > blastFurnaceTemperature) {
Expand All @@ -154,10 +148,7 @@ public static GTRecipe ebfOverclock(MetaMachine machine, @Nullable GTRecipe reci
return null;
}

public static GTRecipe pyrolyseOvenOverclock(MetaMachine machine, @Nullable GTRecipe recipe) {
if (recipe == null) {
return null;
}
public static GTRecipe pyrolyseOvenOverclock(MetaMachine machine, @NotNull GTRecipe recipe) {
if (machine instanceof CoilWorkableElectricMultiblockMachine coilMachine) {
if (RecipeHelper.getRecipeEUtTier(recipe) > coilMachine.getTier()) {
return null;
Expand All @@ -176,10 +167,7 @@ public static GTRecipe pyrolyseOvenOverclock(MetaMachine machine, @Nullable GTRe
return null;
}

public static GTRecipe multiSmelterParallel(MetaMachine machine, @Nullable GTRecipe recipe) {
if (recipe == null) {
return null;
}
public static GTRecipe multiSmelterParallel(MetaMachine machine, @NotNull GTRecipe recipe) {
if (machine instanceof CoilWorkableElectricMultiblockMachine coilMachine) {

var maxParallel = 32 * coilMachine.getCoilType().getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.gregtechceu.gtceu.api.pattern.MultiblockShapeInfo;
import com.gregtechceu.gtceu.api.pattern.Predicates;
import com.gregtechceu.gtceu.api.pattern.TraceabilityPredicate;
import com.gregtechceu.gtceu.api.pattern.MultiblockShapeInfo;
import com.gregtechceu.gtceu.api.recipe.OverclockingLogic;
import com.gregtechceu.gtceu.common.data.GTCompassSections;
import com.gregtechceu.gtceu.common.data.GTMaterials;
Expand Down

0 comments on commit 0dff0ce

Please sign in to comment.