From f74c7cc297d1d19d38a19683cd277ad9ce605d3a Mon Sep 17 00:00:00 2001 From: miozune Date: Mon, 4 Dec 2023 05:34:27 +0900 Subject: 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> --- .../gregtech/api/interfaces/IGT_RecipeMap.java | 74 ---------------------- .../java/gregtech/api/interfaces/IRecipeMap.java | 74 ++++++++++++++++++++++ .../api/interfaces/internal/IGT_RecipeAdder.java | 26 -------- .../interfaces/metatileentity/IMetaTileEntity.java | 8 --- .../tileentity/IOverclockDescriptionProvider.java | 15 +++++ .../api/interfaces/tileentity/IRecipeLockable.java | 5 +- .../interfaces/tileentity/RecipeMapWorkable.java | 49 ++++++++++++++ 7 files changed, 139 insertions(+), 112 deletions(-) delete mode 100644 src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java create mode 100644 src/main/java/gregtech/api/interfaces/IRecipeMap.java create mode 100644 src/main/java/gregtech/api/interfaces/tileentity/IOverclockDescriptionProvider.java create mode 100644 src/main/java/gregtech/api/interfaces/tileentity/RecipeMapWorkable.java (limited to 'src/main/java/gregtech/api/interfaces') diff --git a/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java b/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java deleted file mode 100644 index 2c5259882a..0000000000 --- a/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java +++ /dev/null @@ -1,74 +0,0 @@ -package gregtech.api.interfaces; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Function; - -import javax.annotation.Nonnull; - -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_RecipeBuilder; -import gregtech.api.util.GT_Utility; - -/** - * Represents the target of a recipe adding action, usually, but not necessarily, is a recipe map itself. - */ -public interface IGT_RecipeMap { - - /** - * Add a downstream recipe map that will get to handle the original builder. - *

- * Downstream recipe maps got passed the recipe builder after parent recipe map is done with its business. Notice - * at this time the original recipe builder might be modified by the parent recipe map in some form, but it will - * remain as valid. - *

- * A downstream will only be invoked if parent recipe map added something. - * - * @param downstream the downstream recipe map to add - */ - void addDownstream(IGT_RecipeMap downstream); - - /** - * Actually add the recipe represented by the builder. CAN modify the builder's internal states!!! - */ - @Nonnull - Collection doAdd(GT_RecipeBuilder builder); - - /** - * Return a variant of this recipe map that will perform a deep copy on input recipe builder before doing anything - * to it. - *

- * The returned recipe map will not have any downstreams, but can accept new downstreams. - */ - default IGT_RecipeMap deepCopyInput() { - return newRecipeMap(b -> doAdd(b.copy())); - } - - static IGT_RecipeMap newRecipeMap(Function> func) { - return new IGT_RecipeMap() { - - private final Collection downstreams = new ArrayList<>(); - - @Override - public void addDownstream(IGT_RecipeMap downstream) { - downstreams.add(downstream); - } - - @Nonnull - @Override - public Collection doAdd(GT_RecipeBuilder builder) { - List> ret = new ArrayList<>(); - Collection out = func.apply(builder); - ret.add(out); - builder.clearInvalid(); - if (!out.isEmpty()) { - for (IGT_RecipeMap downstream : downstreams) { - ret.add(downstream.doAdd(builder)); - } - } - return GT_Utility.concat(ret); - } - }; - } -} diff --git a/src/main/java/gregtech/api/interfaces/IRecipeMap.java b/src/main/java/gregtech/api/interfaces/IRecipeMap.java new file mode 100644 index 0000000000..ce48b29927 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IRecipeMap.java @@ -0,0 +1,74 @@ +package gregtech.api.interfaces; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; + +import javax.annotation.Nonnull; + +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_RecipeBuilder; +import gregtech.api.util.GT_Utility; + +/** + * Represents the target of a recipe adding action, usually, but not necessarily, is a recipe map itself. + */ +public interface IRecipeMap { + + /** + * Add a downstream recipe map that will get to handle the original builder. + *

+ * Downstream recipe maps got passed the recipe builder after parent recipe map is done with its business. Notice + * at this time the original recipe builder might be modified by the parent recipe map in some form, but it will + * remain as valid. + *

+ * A downstream will only be invoked if parent recipe map added something. + * + * @param downstream the downstream recipe map to add + */ + void addDownstream(IRecipeMap downstream); + + /** + * Actually add the recipe represented by the builder. CAN modify the builder's internal states!!! + */ + @Nonnull + Collection doAdd(GT_RecipeBuilder builder); + + /** + * Return a variant of this recipe map that will perform a deep copy on input recipe builder before doing anything + * to it. + *

+ * The returned recipe map will not have any downstreams, but can accept new downstreams. + */ + default IRecipeMap deepCopyInput() { + return newRecipeMap(b -> doAdd(b.copy())); + } + + static IRecipeMap newRecipeMap(Function> func) { + return new IRecipeMap() { + + private final Collection downstreams = new ArrayList<>(); + + @Override + public void addDownstream(IRecipeMap downstream) { + downstreams.add(downstream); + } + + @Nonnull + @Override + public Collection doAdd(GT_RecipeBuilder builder) { + List> ret = new ArrayList<>(); + Collection out = func.apply(builder); + ret.add(out); + builder.clearInvalid(); + if (!out.isEmpty()) { + for (IRecipeMap downstream : downstreams) { + ret.add(downstream.doAdd(builder)); + } + } + return GT_Utility.concat(ret); + } + }; + } +} diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index 361e391a9b..e7abfea98f 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -320,17 +320,6 @@ public interface IGT_RecipeAdder { boolean addAlloySmelterRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, int aDuration, int aEUt, boolean hidden); - /** - * Adds a CNC-Machine Recipe - * - * @param aInput1 must be != null - * @param aOutput1 must be != null - * @param aDuration must be > 0 - * @param aEUt should be > 0 - */ - @Deprecated - boolean addCNCRecipe(ItemStack aInput1, ItemStack aOutput1, int aDuration, int aEUt); - /** * Adds an Assembler Recipe * @@ -1046,21 +1035,6 @@ public interface IGT_RecipeAdder { boolean addNanoForgeRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, ItemStack[] aOutputs, FluidStack[] aFluidOutputs, int[] aChances, int aDuration, int aEUt, int aSpecialValue); - /** - * Add a Board Manufacturer Recipe. The Board Manufacturer's main use is to make the circuit boards needed to make - * circuits. - * - * @param aInputs must not be null - * @param aFluidInputs must not be null - * @param aOutputs must not be null - * @param aDuration recipe duration - * @param aEUt recipe EU/t expenditure - * @param aSpecialValue defines the tier of the board manufacturer required. - */ - @Deprecated - boolean addPCBFactoryRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, ItemStack[] aOutputs, int aDuration, - int aEUt, int aSpecialValue); - /** * Add a breeder cell. * diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java index ba164352aa..04522b1012 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java @@ -38,7 +38,6 @@ import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Util; -import gregtech.common.power.Power; /** * Warning, this Interface has just been made to be able to add multiple kinds of MetaTileEntities (Cables, Pipes, @@ -365,13 +364,6 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand */ String getSpecialVoltageToolTip(); - /** - * @return Power object used for displaying in NEI - */ - default Power getPower() { - return null; - } - /** * Icon of the Texture. If this returns null then it falls back to getTextureIndex. * diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IOverclockDescriptionProvider.java b/src/main/java/gregtech/api/interfaces/tileentity/IOverclockDescriptionProvider.java new file mode 100644 index 0000000000..495cd9def4 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IOverclockDescriptionProvider.java @@ -0,0 +1,15 @@ +package gregtech.api.interfaces.tileentity; + +import javax.annotation.Nullable; + +import gregtech.api.objects.overclockdescriber.OverclockDescriber; + +/** + * Classes implementing this interface can provide {@link OverclockDescriber} to provide overclock behavior and NEI + * description. + */ +public interface IOverclockDescriptionProvider { + + @Nullable + OverclockDescriber getOverclockDescriber(); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IRecipeLockable.java b/src/main/java/gregtech/api/interfaces/tileentity/IRecipeLockable.java index f793221a50..54d178af3c 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IRecipeLockable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IRecipeLockable.java @@ -1,12 +1,11 @@ package gregtech.api.interfaces.tileentity; import gregtech.api.recipe.check.SingleRecipeCheck; -import gregtech.api.util.GT_Recipe; /** * Machines implementing this interface can have logic to lock to a single recipe. */ -public interface IRecipeLockable { +public interface IRecipeLockable extends RecipeMapWorkable { /** * @return if this machine supports single recipe locking. @@ -29,6 +28,4 @@ public interface IRecipeLockable { } default void setSingleRecipeCheck(SingleRecipeCheck recipeCheck) {} - - GT_Recipe.GT_Recipe_Map getRecipeMap(); } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/RecipeMapWorkable.java b/src/main/java/gregtech/api/interfaces/tileentity/RecipeMapWorkable.java new file mode 100644 index 0000000000..7d4db4396c --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/RecipeMapWorkable.java @@ -0,0 +1,49 @@ +package gregtech.api.interfaces.tileentity; + +import java.util.Collection; +import java.util.Collections; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; + +import gregtech.api.recipe.RecipeMap; + +/** + * Machines implementing this interface are capable of executing certain recipes provided by {@link RecipeMap}. + * They will also be automatically registered as NEI recipe catalyst for the corresponding recipemaps. + */ +public interface RecipeMapWorkable { + + /** + * @return RecipeMap this machine currently can execute. In general, it's allowed to be null. + */ + RecipeMap getRecipeMap(); + + /** + * @return ItemStack form of this machine. + */ + ItemStack getStackForm(long amount); + + /** + * If the machine supports multiple recipemaps by switching mode, override this method so that it will be displayed + * as NEI recipe catalyst on all the supported recipemaps. + * + * @return List of possible {@link RecipeMap}s this machine can execute. Must not contain null element. + */ + @Nonnull + default Collection> getAvailableRecipeMaps() { + RecipeMap recipeMap = getRecipeMap(); + if (recipeMap != null) { + return Collections.singletonList(recipeMap); + } + return Collections.emptyList(); + } + + /** + * @return Priority for NEI recipe catalyst. Higher priority comes first. + */ + default int getRecipeCatalystPriority() { + return 0; + } +} -- cgit