Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip recipe checks if input contains only programmed circuits. #3305

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9b8d176
Skip recipe checks if input contains only programmed circuits.
AbdielKavash Oct 1, 2024
1773fe5
Simplify logic a little.
AbdielKavash Oct 1, 2024
e9e4b55
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 1, 2024
3e7fee8
Merge branch 'GTNewHorizons:master' into CircuitRecipeChecks
AbdielKavash Oct 1, 2024
900d42b
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 2, 2024
1a7ed47
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 3, 2024
484c6c0
Merge branch 'GTNewHorizons:master' into CircuitRecipeChecks
AbdielKavash Oct 4, 2024
97309ac
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 4, 2024
f008587
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 6, 2024
d45a441
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 6, 2024
3e78af7
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 8, 2024
a9f5ace
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 8, 2024
70962be
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 10, 2024
a50b3ee
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 12, 2024
5cb664b
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 13, 2024
19bb975
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 15, 2024
0faa52a
Merge branch 'master' into CircuitRecipeChecks
AbdielKavash Oct 16, 2024
3611e6b
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 17, 2024
df44959
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 18, 2024
e43191c
Merge branch 'master' into CircuitRecipeChecks
Dream-Master Oct 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/gregtech/api/recipe/RecipeMapBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static gregtech.api.util.GTRecipeBuilder.handleInvalidRecipeLowItems;
import static gregtech.api.util.GTRecipeBuilder.handleRecipeCollision;
import static gregtech.api.util.GTUtility.areStacksEqualOrNull;
import static gregtech.api.util.GTUtility.isAnyIntegratedCircuit;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -392,11 +393,24 @@ Stream<GTRecipe> matchRecipeStream(ItemStack[] rawItems, FluidStack[] fluids, @N
}
if (properties.minItemInputs > 0) {
int count = 0;
for (ItemStack item : rawItems) if (item != null) count++;
for (ItemStack item : rawItems) if (!isAnyIntegratedCircuit(item)) count++;
if (count < properties.minItemInputs) {
return Stream.empty();
}
}
if (!properties.allowCircuitOnly && properties.minItemInputs == 0 && properties.minFluidInputs == 0) {
// Both items and fluids can be empty, but we still need at least one non-circuit input.
boolean isEmpty = true;
for (FluidStack fluid : fluids) if (fluid != null) {
isEmpty = false;
break;
}
if (isEmpty) for (ItemStack item : rawItems) if (!isAnyIntegratedCircuit(item)) {
isEmpty = false;
break;
}
if (isEmpty) return Stream.empty();
}
}

ItemStack[] items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static RecipeMapBackendPropertiesBuilder builder() {
* Minimum amount of fluid inputs required for the recipes.
*/
public final int minFluidInputs;
/**
* Whether to allow recipes which only use a programmed circuit, and no item/fluid inputs. If this is false, such
* recipes are optimized away.
*/
public boolean allowCircuitOnly;

/**
* Whether this backend should check for equality of special slot when searching recipe.
Expand All @@ -52,15 +57,16 @@ static RecipeMapBackendPropertiesBuilder builder() {
@Nullable
public final Function<? super GTRecipe, ? extends GTRecipe> recipeTransformer;

RecipeMapBackendProperties(int minItemInputs, int minFluidInputs, boolean specialSlotSensitive,
boolean disableOptimize,
RecipeMapBackendProperties(int minItemInputs, int minFluidInputs, boolean allowCircuitOnly,
boolean specialSlotSensitive, boolean disableOptimize,
Function<? super GTRecipeBuilder, ? extends Iterable<? extends GTRecipe>> recipeEmitter,
@Nullable Function<? super GTRecipe, ? extends GTRecipe> recipeTransformer) {
if (minItemInputs < 0 || minFluidInputs < 0) {
throw new IllegalArgumentException("minItemInputs and minFluidInputs cannot be negative");
}
this.minItemInputs = minItemInputs;
this.minFluidInputs = minFluidInputs;
this.allowCircuitOnly = allowCircuitOnly;
this.specialSlotSensitive = specialSlotSensitive;
this.disableOptimize = disableOptimize;
this.recipeEmitter = recipeEmitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class RecipeMapBackendPropertiesBuilder {

private int minItemInputs;
private int minFluidInputs;
private boolean allowCircuitOnly;

private boolean specialSlotSensitive;

Expand All @@ -39,6 +40,7 @@ RecipeMapBackendProperties build() {
return new RecipeMapBackendProperties(
minItemInputs,
minFluidInputs,
allowCircuitOnly,
specialSlotSensitive,
disableOptimize,
recipeEmitter,
Expand All @@ -55,6 +57,11 @@ public RecipeMapBackendPropertiesBuilder minFluidInputs(int minFluidInputs) {
return this;
}

public RecipeMapBackendPropertiesBuilder allowCircuitOnly(boolean allowCircuitOnly) {
this.allowCircuitOnly = allowCircuitOnly;
return this;
}

public RecipeMapBackendPropertiesBuilder specialSlotSensitive() {
this.specialSlotSensitive = true;
return this;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/gregtech/api/recipe/RecipeMapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,24 @@ private RecipeMapBuilder(String unlocalizedName, RecipeMapBackend.BackendCreator

/**
* Sets minimum amount of inputs required for the recipes.
* This ignores programmed circuits; so if a machine requires one input item and a programmed circuit, set
* minItemInputs to 1.
*/
public RecipeMapBuilder<B> minInputs(int minItemInputs, int minFluidInputs) {
backendPropertiesBuilder.minItemInputs(minItemInputs)
.minFluidInputs(minFluidInputs);
return this;
}

/**
* Whether to allow recipes which only use a programmed circuit, and no item/fluid inputs. If this is false, such
* recipes are optimized away.
*/
public RecipeMapBuilder<B> allowCircuitOnly(boolean allowCircuitOnly) {
backendPropertiesBuilder.allowCircuitOnly(allowCircuitOnly);
return this;
}

/**
* Whether this recipemap should check for equality of special slot when searching recipe.
*/
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/gregtech/api/recipe/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public final class RecipeMaps {
public static final RecipeMap<FormingPressBackend> formingPressRecipes = RecipeMapBuilder
.of("gt.recipe.press", FormingPressBackend::new)
.maxIO(6, 1, 0, 0)
.minInputs(2, 0)
.minInputs(1, 0)
.slotOverlays((index, isFluid, isOutput, isSpecial) -> {
if (isOutput) {
return GTUITextures.OVERLAY_SLOT_PRESS_3;
Expand Down Expand Up @@ -407,7 +407,7 @@ public final class RecipeMaps {
.build();
public static final RecipeMap<RecipeMapBackend> distilleryRecipes = RecipeMapBuilder.of("gt.recipe.distillery")
.maxIO(1, 1, 1, 1)
.minInputs(1, 1)
.minInputs(0, 1)
.slotOverlays((index, isFluid, isOutput, isSpecial) -> {
if (!isFluid) {
return null;
Expand Down Expand Up @@ -467,7 +467,7 @@ public final class RecipeMaps {
public static final RecipeMap<RecipeMapBackend> fluidSolidifierRecipes = RecipeMapBuilder
.of("gt.recipe.fluidsolidifier")
.maxIO(1, 1, 1, 0)
.minInputs(1, 1)
.minInputs(0, 1)
.slotOverlays(
(index, isFluid, isOutput, isSpecial) -> !isFluid && !isOutput ? GTUITextures.OVERLAY_SLOT_MOLD : null)
.recipeTransformer(r -> {
Expand Down Expand Up @@ -840,12 +840,11 @@ && isArrayEmptyOrNull(b.getFluidOutputs())
public static final RecipeMap<OilCrackerBackend> crackingRecipes = RecipeMapBuilder
.of("gt.recipe.craker", OilCrackerBackend::new)
.maxIO(1, 1, 2, 1)
.minInputs(1, 2)
.minInputs(0, 2)
.progressBar(GTUITextures.PROGRESSBAR_ARROW_MULTIPLE)
.build();
public static final RecipeMap<RecipeMapBackend> pyrolyseRecipes = RecipeMapBuilder.of("gt.recipe.pyro")
.maxIO(2, 1, 1, 1)
.minInputs(1, 0)
.disableOptimize()
.build();
public static final RecipeMap<RecipeMapBackend> wiremillRecipes = RecipeMapBuilder.of("gt.recipe.wiremill")
Expand All @@ -857,14 +856,14 @@ && isArrayEmptyOrNull(b.getFluidOutputs())
.build();
public static final RecipeMap<RecipeMapBackend> benderRecipes = RecipeMapBuilder.of("gt.recipe.metalbender")
.maxIO(2, 1, 0, 0)
.minInputs(2, 0)
.minInputs(1, 0)
.slotOverlays(
(index, isFluid, isOutput, isSpecial) -> !isFluid && !isOutput ? GTUITextures.OVERLAY_SLOT_BENDER : null)
.progressBar(GTUITextures.PROGRESSBAR_BENDING)
.build();
public static final RecipeMap<RecipeMapBackend> alloySmelterRecipes = RecipeMapBuilder.of("gt.recipe.alloysmelter")
.maxIO(2, 1, 0, 0)
.minInputs(2, 0)
.minInputs(1, 0)
.slotOverlays(
(index, isFluid, isOutput, isSpecial) -> !isFluid && !isOutput ? GTUITextures.OVERLAY_SLOT_FURNACE : null)
.slotOverlaysSteam((index, isFluid, isOutput, isSpecial) -> GTUITextures.OVERLAY_SLOT_FURNACE_STEAM)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GTPPRecipeMaps {
public static final RecipeMap<RecipeMapBackend> multiblockMassFabricatorRecipes = RecipeMapBuilder
.of("gtpp.recipe.matterfab2")
.maxIO(2, 0, 1, 1)
.allowCircuitOnly(true)
.build();
public static final RecipeMap<FuelBackend> rocketFuels = RecipeMapBuilder
.of("gtpp.recipe.rocketenginefuel", FuelBackend::new)
Expand Down