aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/recipe/check
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/recipe/check')
-rw-r--r--src/main/java/gregtech/api/recipe/check/FindRecipeResult.java125
-rw-r--r--src/main/java/gregtech/api/recipe/check/RecipeValidator.java80
-rw-r--r--src/main/java/gregtech/api/recipe/check/SingleRecipeCheck.java25
3 files changed, 13 insertions, 217 deletions
diff --git a/src/main/java/gregtech/api/recipe/check/FindRecipeResult.java b/src/main/java/gregtech/api/recipe/check/FindRecipeResult.java
deleted file mode 100644
index fa0e251fa1..0000000000
--- a/src/main/java/gregtech/api/recipe/check/FindRecipeResult.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package gregtech.api.recipe.check;
-
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.jetbrains.annotations.NotNull;
-
-import gregtech.api.util.GT_Recipe;
-
-/**
- * Wrapper class to get result of recipe search for recipemap. Note that this only validates recipe input and voltage,
- * and does not involve in actual check in the machine such as output space or special value.
- */
-public class FindRecipeResult {
-
- @Nonnull
- private final State state;
- @Nullable
- private final GT_Recipe recipe;
- @Nullable
- private RecipeValidator recipeValidator;
-
- private FindRecipeResult(@Nonnull State state, @Nullable GT_Recipe recipe) {
- this.state = state;
- this.recipe = recipe;
- }
-
- @Nonnull
- public State getState() {
- return state;
- }
-
- public boolean isSuccessful() {
- return state.success;
- }
-
- /**
- * If you already checked {@link #isSuccessful()}, you can use {@link #getRecipeNonNull()} instead.
- */
- @Nullable
- public GT_Recipe getRecipe() {
- return recipe;
- }
-
- /**
- * You should use this ONLY WHEN state == FOUND.
- */
- @Nonnull
- public GT_Recipe getRecipeNonNull() {
- return Objects.requireNonNull(recipe);
- }
-
- /**
- * Gets recipeValidator if it is not null.
- * Be sure to call hasRecipeValidator before to determine if recipeValidator exists
- *
- * @return not null recipe validator
- */
- @NotNull
- public RecipeValidator getRecipeValidator() {
- return Objects.requireNonNull(recipeValidator);
- }
-
- /**
- * Sets recipeValidator which used to get this result
- */
- public void setRecipeValidator(@Nullable RecipeValidator recipeValidator) {
- this.recipeValidator = recipeValidator;
- }
-
- /**
- * Gets if this result has recipeValidator
- */
- public boolean hasRecipeValidator() {
- return recipeValidator != null;
- }
-
- /**
- * Successfully found recipe.
- */
- public static FindRecipeResult ofSuccess(@Nonnull GT_Recipe recipe) {
- return new FindRecipeResult(State.FOUND, Objects.requireNonNull(recipe));
- }
-
- /**
- * No recipe found.
- */
- public static final FindRecipeResult NOT_FOUND = new FindRecipeResult(State.NOT_FOUND, null);
- /**
- * For Microwave.
- */
- public static final FindRecipeResult EXPLODE = new FindRecipeResult(State.EXPLODE, null);
- /**
- * For Microwave.
- */
- public static final FindRecipeResult ON_FIRE = new FindRecipeResult(State.ON_FIRE, null);
-
- public enum State {
-
- /**
- * Successfully found recipe.
- */
- FOUND(true),
- /**
- * No recipe found.
- */
- NOT_FOUND(false),
- /**
- * For Microwave.
- */
- EXPLODE(false),
- /**
- * For Microwave.
- */
- ON_FIRE(false);
-
- private final boolean success;
-
- State(boolean success) {
- this.success = success;
- }
- }
-}
diff --git a/src/main/java/gregtech/api/recipe/check/RecipeValidator.java b/src/main/java/gregtech/api/recipe/check/RecipeValidator.java
deleted file mode 100644
index 8fb7b87cfe..0000000000
--- a/src/main/java/gregtech/api/recipe/check/RecipeValidator.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package gregtech.api.recipe.check;
-
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-import gregtech.api.util.GT_OverclockCalculator;
-import gregtech.api.util.GT_ParallelHelper;
-import gregtech.api.util.GT_Recipe;
-
-/**
- * Predicate for simple recipe validation.
- * Also store some validation results for reusing it
- */
-public class RecipeValidator implements Predicate<GT_Recipe> {
-
- private CheckRecipeResult firstCheckResult;
- private CheckRecipeResult lastCheckResult;
- private GT_ParallelHelper lastParallelHelper;
- private GT_OverclockCalculator lastOverclockCalculator;
- private boolean wasExecutedAtLeastOnce = false;
- private final Function<GT_Recipe, CheckRecipeResult> recipeValidator;
- private final Function<GT_Recipe, GT_ParallelHelper> parallelHelperFactory;
- private final Function<GT_Recipe, GT_OverclockCalculator> overclockCalculatorFactory;
-
- public RecipeValidator(Function<GT_Recipe, CheckRecipeResult> recipeValidator,
- Function<GT_Recipe, GT_ParallelHelper> parallelHelperFactory,
- Function<GT_Recipe, GT_OverclockCalculator> overclockCalculatorFactory) {
- this.recipeValidator = recipeValidator;
- this.parallelHelperFactory = parallelHelperFactory;
- this.overclockCalculatorFactory = overclockCalculatorFactory;
- }
-
- @Override
- public boolean test(GT_Recipe recipe) {
- wasExecutedAtLeastOnce = true;
- CheckRecipeResult checkRecipeResult = checkRecipe(recipe);
- if (firstCheckResult == null) {
- firstCheckResult = checkRecipeResult;
- }
- return checkRecipeResult.wasSuccessful();
- }
-
- private CheckRecipeResult checkRecipe(GT_Recipe recipe) {
- lastCheckResult = recipeValidator.apply(recipe);
-
- if (!lastCheckResult.wasSuccessful()) {
- return lastCheckResult;
- }
-
- lastParallelHelper = parallelHelperFactory.apply(recipe);
- lastOverclockCalculator = overclockCalculatorFactory.apply(recipe);
- lastParallelHelper.setCalculator(lastOverclockCalculator);
- lastParallelHelper.build();
-
- return lastParallelHelper.getResult();
- }
-
- public Boolean isExecutedAtLeastOnce() {
- return wasExecutedAtLeastOnce;
- }
-
- /**
- * Gets first check result in case if nothing matching recipe found.
- */
- public CheckRecipeResult getFirstCheckResult() {
- return firstCheckResult;
- }
-
- public CheckRecipeResult getLastCheckResult() {
- return lastCheckResult;
- }
-
- public GT_ParallelHelper getLastParallelHelper() {
- return lastParallelHelper;
- }
-
- public GT_OverclockCalculator getLastOverclockCalculator() {
- return lastOverclockCalculator;
- }
-}
diff --git a/src/main/java/gregtech/api/recipe/check/SingleRecipeCheck.java b/src/main/java/gregtech/api/recipe/check/SingleRecipeCheck.java
index d0a952b8d5..8683812d84 100644
--- a/src/main/java/gregtech/api/recipe/check/SingleRecipeCheck.java
+++ b/src/main/java/gregtech/api/recipe/check/SingleRecipeCheck.java
@@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidStack;
import com.google.common.collect.ImmutableMap;
import gregtech.api.enums.GT_Values;
+import gregtech.api.recipe.RecipeMap;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Utility.ItemId;
@@ -34,7 +35,7 @@ import gregtech.api.util.GT_Utility.ItemId;
* <ul>
* Normal recipe check:
* <ul>
- * {@link GT_Recipe.GT_Recipe_Map#findRecipeWithResult Find recipe from recipemap}: O(NCR)
+ * {@link gregtech.api.recipe.FindRecipeQuery#find Find recipe from recipemap}: O(NCR)
* where N = number of machine inputs, C = average amount of recipe candidates found for specific input,
* R = computation time to {@link GT_Recipe#isRecipeInputEqual check if inputs match to recipe}
* </ul>
@@ -53,7 +54,7 @@ public class SingleRecipeCheck {
@Nonnull
private final GT_Recipe recipe;
@Nonnull
- private final GT_Recipe.GT_Recipe_Map recipeMap;
+ private final RecipeMap<?> recipeMap;
@Nonnull
private final ImmutableMap<ItemId, Integer> itemCost;
@Nonnull
@@ -62,7 +63,7 @@ public class SingleRecipeCheck {
private final int totalItemCost;
private final int totalFluidCost;
- private SingleRecipeCheck(@Nonnull GT_Recipe recipe, @Nonnull GT_Recipe.GT_Recipe_Map recipeMap,
+ private SingleRecipeCheck(@Nonnull GT_Recipe recipe, @Nonnull RecipeMap<?> recipeMap,
@Nonnull ImmutableMap<ItemId, Integer> itemCost, @Nonnull ImmutableMap<Fluid, Integer> fluidCost) {
this.recipe = recipe;
this.recipeMap = recipeMap;
@@ -85,7 +86,7 @@ public class SingleRecipeCheck {
}
@Nonnull
- public GT_Recipe.GT_Recipe_Map getRecipeMap() {
+ public RecipeMap<?> getRecipeMap() {
return recipeMap;
}
@@ -189,7 +190,7 @@ public class SingleRecipeCheck {
// we don't yet have a mean to uniquely name a recipe, this will have to make do.
// Consider move serialization code to GT_Recipe once this has been proven to work
NBTTagCompound tag = new NBTTagCompound();
- tag.setString("recipemap", recipeMap.mUnlocalizedName);
+ tag.setString("recipemap", recipeMap.unlocalizedName);
if (recipe.mInputs != null) {
tag.setTag("inputs", writeList(recipe.mInputs, GT_Utility::saveItem));
}
@@ -250,13 +251,13 @@ public class SingleRecipeCheck {
}
@Nullable
- public static SingleRecipeCheck tryLoad(GT_Recipe.GT_Recipe_Map recipeMap, NBTTagCompound tag) {
+ public static SingleRecipeCheck tryLoad(RecipeMap<?> recipeMap, NBTTagCompound tag) {
if (tag == null || tag.hasNoTags()) return null;
- GT_Recipe.GT_Recipe_Map mapToUse;
+ RecipeMap<?> mapToUse;
if (tag.hasKey("recipemap")) {
String mapName = tag.getString("recipemap");
- GT_Recipe.GT_Recipe_Map foundMap = GT_Recipe.GT_Recipe_Map.findRecipeMap(mapName);
+ RecipeMap<?> foundMap = RecipeMap.ALL_RECIPE_MAPS.get(mapName);
if (foundMap != null) {
mapToUse = foundMap;
} else {
@@ -288,7 +289,7 @@ public class SingleRecipeCheck {
.toImmutableMapSerial(t -> ItemId.create(t.getCompoundTag("id")), t -> t.getInteger("count")));
}
- private static GT_Recipe tryFindRecipe(@Nonnull GT_Recipe.GT_Recipe_Map recipeMap, NBTTagCompound tag) {
+ private static GT_Recipe tryFindRecipe(@Nonnull RecipeMap<?> recipeMap, NBTTagCompound tag) {
ItemStack[] inputs = GT_Utility.streamCompounds(tag.getTagList("inputs", Constants.NBT.TAG_COMPOUND))
.map(GT_Utility::loadItem)
.toArray(ItemStack[]::new);
@@ -334,13 +335,13 @@ public class SingleRecipeCheck {
return ImmutableMap.copyOf(fluidMap);
}
- public static Builder builder(@Nonnull GT_Recipe.GT_Recipe_Map recipeMap) {
+ public static Builder builder(@Nonnull RecipeMap<?> recipeMap) {
return new Builder(Objects.requireNonNull(recipeMap));
}
public static class Builder {
- private final GT_Recipe.GT_Recipe_Map recipeMap;
+ private final RecipeMap<?> recipeMap;
// In order to compute which items and fluids are consumed by the recipe, we compare the
// multi-block's items and fluids before and after inputs are consumed by the recipe.
@@ -351,7 +352,7 @@ public class SingleRecipeCheck {
private GT_Recipe recipe;
- private Builder(@Nonnull GT_Recipe.GT_Recipe_Map recipeMap) {
+ private Builder(@Nonnull RecipeMap<?> recipeMap) {
this.recipeMap = recipeMap;
}