diff options
author | miozune <miozune@gmail.com> | 2023-12-04 05:34:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-03 21:34:27 +0100 |
commit | f74c7cc297d1d19d38a19683cd277ad9ce605d3a (patch) | |
tree | b2a5d66ec5a959099240fb1db239ffc0f9531839 /src/main/java/gregtech/api/recipe/check | |
parent | b08cde7de4ec93cba05fb070991ad1dffb800ce1 (diff) | |
download | GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.gz GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.bz2 GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.zip |
Refactor RecipeMap (#2345)
* Remove deprecated and unused things
* Move recipemap subclasses
* Move GT_Recipe_Map to outside and rename to RecipeMap
* Move recipemap instances to separated class & remove prepending s
* Remove useless GT_Recipe constructors
* Always use ModularUI
* Rename IGT_RecipeMap -> IRecipeMap
* Add RecipeMapBuilder
* Remove more deprecated and unused things
* Fix RecipeMap type parameters
* Use multimap for recipe index
* Fix bending recipe error in dev env
* Remove mUniqueIdentifier
* Update AE2FC
* Less edgy texture for NEI recipe background
* Add replicator fluid output slot for NEI and machine GUI
* Fix fluid fuels not having fuel value in large boilers
* Remove GT_RectHandler and NEI_TransferRectHost
* Remove RecipeMapHandler
* Move NEI energy description from RecipeMapFrontend to Power
* Refactor the way to filter fusion recipes
* Check restriction for some properties
* Remove showVoltageAmperage
* Make Power accept GT_Recipe
* Fix NPE
* Move NEI duration description to Power from Frontend
* Directly implement IRecipeProcessingAwareHatch for GT_MetaTileEntity_Hatch_InputBus_ME
* Make Power integrated with GT_OverclockCalculator
* Rename Power -> OverclockDescriber
* Don't modify recipe find logic until postload finishes
* Reformat reserved MTE ids
* Fix check for too few inputs on recipe addition
* Move replicator logic to backend
* Stop un-hiding assline recipes
* Allow setting custom recipe comparator & implement for fusion
* Update AE2FC
* Rename getRecipeList and getRecipes -> getRecipeMap
* Automatically register recipe catalysts
* Cleanup the way to detect recipe collision
* Make use of BasicUIProperties for basic machines
* Make use of BasicUIProperties for UIHelper
* Rename specialHandler -> recipeTransformer
* Add way to automatically register handler info
* Add recipe category
* Add some APIs for addons
* Rename blastRecipes ->
blastFurnaceRecipes
* Remove GT_MetaTileEntity_BasicMachine_GT_Recipe#mSharedTank and #mRequiresFluidForFiltering
* Don't require setting duration and EU/t for fuel recipes
* Don't require setting EU/t for primitive blast furnace recipes
* Revert change to addMultiblockChemicalRecipe
* Fix large boiler general desc recipe not being added
* Hide duration and EU/t from large boiler
* Cleanup recipe stacktrace draw
* Extend metadata usage of recipe builder to recipe itself
* Implement metadata handling & NEI comparator for PCB factory
* Some rename around NEIRecipeInfo
* Some toString implementations
* Add more APIs for addons & some rename
* Infer handler icon from recipe catalyst if one is not set
* Also shrink recipe title when OC is not used
* Remove rare earth centrifuge recipe
* Use metadata for replicator backend
* Adjust geothermal generator output slot
* Allow having multiple transferrects
* Store recipemap reference in backend
* Rename vacuumRecipes -> vacuumFreezerRecipes
* Add config to tweak visibility of recipe categories
* Remove mHideRecyclingRecipes in favor of recipe category config
* Fix typo fluidSolidfierRecipes -> fluidSolidifierRecipes
* Refactor findRecipe and ProcessingLogic to use Stream
* Fix BBF handler icon & remove bronze blast furnace
* Add fluent API for findRecipe
* Add way to stop adding progressbar
* Change arg order for special texture
* Avoid overwriting interesting failure with NO_RECIPE
* Some changes for FuelBackend
* Set space project icon
* Remove localization from TT
* Remove CNC recipe adder
* Move recipe extractor from AE2FC
* Minor internal change for ProcessingLogic#applyRecipe
* More javadoc on #getAvailableRecipeMaps
* Better implementation of #ofSupplier
* Move replicator exponent config to GT_Proxy
* Remove RC & IC2 macerator handling
* Rename StreamUtil -> GT_StreamUtil
* Refactor code around RecipeMetadataStorage
* Revise #compileRecipe javadoc
* Switch extreme diesel recipe loader to downstream recipe map
* Optimize #reMap
* Rename reload -> reloadNEICache
* Minor tweak for drawEnergyInfo
* a bit more doc
* Adjust recipe catalysts
* Add toString implementation for GT_Fluid for debug
* Minor revision for OilCrackerBackend
* Index replicator recipes by material
---------
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/recipe/check')
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; } |