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> --- src/main/java/gregtech/api/GregTech_API.java | 43 +- src/main/java/gregtech/api/enums/Element.java | 3 + src/main/java/gregtech/api/enums/ItemList.java | 1 - src/main/java/gregtech/api/enums/MachineType.java | 4 +- .../java/gregtech/api/enums/MetaTileEntityIDs.java | 1 - .../gregtech/api/gui/modularui/GT_UITextures.java | 7 + .../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 + .../gregtech/api/items/GT_MetaGenerated_Item.java | 4 +- .../api/logic/ComplexParallelProcessingLogic.java | 7 +- .../java/gregtech/api/logic/ProcessingLogic.java | 174 +- .../implementations/GT_MetaPipeEntity_Frame.java | 4 +- .../GT_MetaTileEntity_BasicGenerator.java | 22 +- .../GT_MetaTileEntity_BasicMachine.java | 325 +- .../GT_MetaTileEntity_BasicMachine_Bronze.java | 14 +- .../GT_MetaTileEntity_BasicMachine_GT_Recipe.java | 278 +- .../GT_MetaTileEntity_BasicMachine_Steel.java | 8 +- ...MetaTileEntity_ExtendedPowerMultiBlockBase.java | 31 +- .../GT_MetaTileEntity_Hatch_Input.java | 10 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 17 +- .../GT_MetaTileEntity_MultiBlockBase.java | 107 +- .../multiblock/base/Controller.java | 4 +- .../overclockdescriber/EUNoOverclockDescriber.java | 110 + .../overclockdescriber/EUOverclockDescriber.java | 80 + .../FusionOverclockDescriber.java | 69 + .../overclockdescriber/OverclockDescriber.java | 106 + .../SteamOverclockDescriber.java | 64 + .../gregtech/api/recipe/BasicUIProperties.java | 251 + .../api/recipe/BasicUIPropertiesBuilder.java | 264 + .../java/gregtech/api/recipe/FindRecipeQuery.java | 178 + .../gregtech/api/recipe/NEIRecipeProperties.java | 89 + .../api/recipe/NEIRecipePropertiesBuilder.java | 100 + .../java/gregtech/api/recipe/RecipeCategories.java | 56 + .../java/gregtech/api/recipe/RecipeCategory.java | 81 + .../gregtech/api/recipe/RecipeCategoryHolder.java | 13 + .../gregtech/api/recipe/RecipeCategorySetting.java | 52 + src/main/java/gregtech/api/recipe/RecipeMap.java | 395 ++ .../java/gregtech/api/recipe/RecipeMapBackend.java | 461 ++ .../api/recipe/RecipeMapBackendProperties.java | 77 + .../recipe/RecipeMapBackendPropertiesBuilder.java | 119 + .../java/gregtech/api/recipe/RecipeMapBuilder.java | 522 ++ .../gregtech/api/recipe/RecipeMapFrontend.java | 395 ++ src/main/java/gregtech/api/recipe/RecipeMaps.java | 1177 ++++ .../gregtech/api/recipe/RecipeMetadataKey.java | 84 + .../api/recipe/check/FindRecipeResult.java | 125 - .../gregtech/api/recipe/check/RecipeValidator.java | 80 - .../api/recipe/check/SingleRecipeCheck.java | 25 +- .../gregtech/api/recipe/maps/AssemblerBackend.java | 35 + .../api/recipe/maps/AssemblyLineFrontend.java | 76 + .../api/recipe/maps/DistillationTowerFrontend.java | 38 + .../api/recipe/maps/FluidCannerBackend.java | 73 + .../api/recipe/maps/FluidOnlyFrontend.java | 33 + .../api/recipe/maps/FormingPressBackend.java | 92 + .../java/gregtech/api/recipe/maps/FuelBackend.java | 75 + .../gregtech/api/recipe/maps/FurnaceBackend.java | 52 + .../api/recipe/maps/LargeBoilerFuelBackend.java | 132 + .../api/recipe/maps/LargeBoilerFuelFrontend.java | 25 + .../gregtech/api/recipe/maps/LargeNEIFrontend.java | 65 + .../gregtech/api/recipe/maps/MicrowaveBackend.java | 145 + .../gregtech/api/recipe/maps/NonGTBackend.java | 52 + .../api/recipe/maps/OilCrackerBackend.java | 41 + .../gregtech/api/recipe/maps/PrinterBackend.java | 142 + .../gregtech/api/recipe/maps/RecyclerBackend.java | 51 + .../api/recipe/maps/ReplicatorBackend.java | 100 + .../api/recipe/maps/SpaceProjectFrontend.java | 131 + .../maps/TranscendentPlasmaMixerFrontend.java | 56 + .../api/recipe/maps/UnpackagerBackend.java | 53 + .../metadata/EmptyRecipeMetadataStorage.java | 50 + .../recipe/metadata/IRecipeMetadataStorage.java | 34 + .../api/recipe/metadata/PCBFactoryTierKey.java | 30 + .../api/recipe/metadata/PCBFactoryUpgrade.java | 7 + .../api/recipe/metadata/PCBFactoryUpgradeKey.java | 32 + .../api/recipe/metadata/RecipeMetadataStorage.java | 56 + .../recipe/metadata/SimpleRecipeMetadataKey.java | 27 + .../api/util/FieldsAreNonnullByDefault.java | 18 + src/main/java/gregtech/api/util/GT_Config.java | 14 + .../java/gregtech/api/util/GT_Forestry_Compat.java | 25 +- .../java/gregtech/api/util/GT_LanguageManager.java | 1 - src/main/java/gregtech/api/util/GT_ModHandler.java | 34 +- .../gregtech/api/util/GT_OverclockCalculator.java | 34 +- .../java/gregtech/api/util/GT_ParallelHelper.java | 66 +- .../api/util/GT_ProcessingArray_Manager.java | 8 +- src/main/java/gregtech/api/util/GT_Recipe.java | 5863 +------------------- .../java/gregtech/api/util/GT_RecipeBuilder.java | 257 +- .../java/gregtech/api/util/GT_RecipeConstants.java | 125 +- .../java/gregtech/api/util/GT_RecipeMapUtil.java | 28 +- .../gregtech/api/util/GT_RecipeRegistrator.java | 113 +- src/main/java/gregtech/api/util/GT_StreamUtil.java | 44 + src/main/java/gregtech/api/util/GT_Utility.java | 27 +- .../api/util/MethodsReturnNonnullByDefault.java | 22 + .../gregtech/api/util/VoidProtectionHelper.java | 22 - 96 files changed, 7634 insertions(+), 7058 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 create mode 100644 src/main/java/gregtech/api/objects/overclockdescriber/EUNoOverclockDescriber.java create mode 100644 src/main/java/gregtech/api/objects/overclockdescriber/EUOverclockDescriber.java create mode 100644 src/main/java/gregtech/api/objects/overclockdescriber/FusionOverclockDescriber.java create mode 100644 src/main/java/gregtech/api/objects/overclockdescriber/OverclockDescriber.java create mode 100644 src/main/java/gregtech/api/objects/overclockdescriber/SteamOverclockDescriber.java create mode 100644 src/main/java/gregtech/api/recipe/BasicUIProperties.java create mode 100644 src/main/java/gregtech/api/recipe/BasicUIPropertiesBuilder.java create mode 100644 src/main/java/gregtech/api/recipe/FindRecipeQuery.java create mode 100644 src/main/java/gregtech/api/recipe/NEIRecipeProperties.java create mode 100644 src/main/java/gregtech/api/recipe/NEIRecipePropertiesBuilder.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeCategories.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeCategory.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeCategoryHolder.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeCategorySetting.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMap.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMapBackend.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMapBackendProperties.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMapBackendPropertiesBuilder.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMapBuilder.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMapFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMaps.java create mode 100644 src/main/java/gregtech/api/recipe/RecipeMetadataKey.java delete mode 100644 src/main/java/gregtech/api/recipe/check/FindRecipeResult.java delete mode 100644 src/main/java/gregtech/api/recipe/check/RecipeValidator.java create mode 100644 src/main/java/gregtech/api/recipe/maps/AssemblerBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/AssemblyLineFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/DistillationTowerFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/FluidCannerBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/FluidOnlyFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/FormingPressBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/FuelBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/FurnaceBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/LargeBoilerFuelBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/LargeBoilerFuelFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/LargeNEIFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/MicrowaveBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/NonGTBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/OilCrackerBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/PrinterBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/RecyclerBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/ReplicatorBackend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/SpaceProjectFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/TranscendentPlasmaMixerFrontend.java create mode 100644 src/main/java/gregtech/api/recipe/maps/UnpackagerBackend.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/EmptyRecipeMetadataStorage.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/IRecipeMetadataStorage.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/PCBFactoryTierKey.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/PCBFactoryUpgrade.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/PCBFactoryUpgradeKey.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/RecipeMetadataStorage.java create mode 100644 src/main/java/gregtech/api/recipe/metadata/SimpleRecipeMetadataKey.java create mode 100644 src/main/java/gregtech/api/util/FieldsAreNonnullByDefault.java create mode 100644 src/main/java/gregtech/api/util/GT_StreamUtil.java create mode 100644 src/main/java/gregtech/api/util/MethodsReturnNonnullByDefault.java (limited to 'src/main/java/gregtech/api') diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 6848c66a38..c5e27aebca 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -36,6 +36,7 @@ import net.minecraft.world.World; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; +import com.google.common.collect.SetMultimap; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; @@ -107,6 +108,7 @@ public class GregTech_API { * Fixes the HashMap Mappings for ItemStacks once the Server started */ public static final Collection> sItemStackMappings = new ArrayList<>(); + public static final Collection> itemStackMultiMaps = new ArrayList<>(); /** * The MetaTileEntity-ID-List-Length @@ -121,17 +123,36 @@ public class GregTech_API { /** * A List of all registered MetaTileEntities *

- * 0 - 749 are used by GregTech. 750 - 999 are reserved for Alkalus. 1000 - 2047 are used by GregTech. 2048 - 2559 - * are reserved for OvermindDL. 2560 - 3071 are reserved for Immibis. 3072 - 3583 are reserved for LinusPhoenix. - * 3584 - 4095 are reserved for BloodyAsp. 4096 - 5095 are used for GregTech Frames. 5096 - 6099 are used for - * GregTech Pipes. 6100 - 8191 are used for GregTech Decoration Blocks. 8192 - 8703 are reserved for ZL123. 8704 - - * 9215 are reserved for Mr10Movie. 9216 - 9727 are used for GregTech Automation Machines. 9728 - 10239 are reserved - * for 28Smiles. 10240 - 10751 are reserved for VirMan. 10752 - 11263 are reserved for Briareos81. 11264 - 12000 are - * reserved for Quantum64. 12001 - 12500 are reserved for RedMage17. 12501 - 13000 are reserved for bartimaeusnek. - * 13001 - 13100 are reserved for Techlone 13101 - 13500 are reserved for kekzdealer 13501 - 14000 are reserved for - * glee8e. 14001 - 14100 are reserved for glowredman 14101 - 14200 are reserved for MuXiu1997. 14201 - 14300 are - * reserved for kuba6000. 14301 - 14999 are currently free. 15000 - 16999 are reserved for TecTech. 17000 - 29999 - * are currently free. 30000 - 31999 are reserved for Alkalus. 32001 - 32766 are reserved for Glod. + * 0 - 749 are used by GregTech. + * 750 - 999 are reserved for Alkalus. + * 1000 - 2047 are used by GregTech. + * 2048 - 2559 are reserved for OvermindDL. + * 2560 - 3071 are reserved for Immibis. + * 3072 - 3583 are reserved for LinusPhoenix. + * 3584 - 4095 are reserved for BloodyAsp. + * 4096 - 5095 are used for GregTech Frames. + * 5096 - 6099 are used for GregTech Pipes. + * 6100 - 8191 are used for GregTech Decoration Blocks. + * 8192 - 8703 are reserved for ZL123. + * 8704 - 9215 are reserved for Mr10Movie. + * 9216 - 9727 are used for GregTech Automation Machines. + * 9728 - 10239 are reserved for 28Smiles. + * 10240 - 10751 are reserved for VirMan. + * 10752 - 11263 are reserved for Briareos81. + * 11264 - 12000 are reserved for Quantum64. + * 12001 - 12500 are reserved for RedMage17. + * 12501 - 13000 are reserved for bartimaeusnek. + * 13001 - 13100 are reserved for Techlone. + * 13101 - 13500 are reserved for kekzdealer. + * 13501 - 14000 are reserved for glee8e. + * 14001 - 14100 are reserved for glowredman. + * 14101 - 14200 are reserved for MuXiu1997. + * 14201 - 14300 are reserved for kuba6000. + * 14301 - 14999 are currently free. + * 15000 - 16999 are reserved for TecTech. + * 17000 - 29999 are currently free. + * 30000 - 31999 are reserved for Alkalus. + * 32001 - 32766 are reserved for Glod. *

* Contact me if you need a free ID-Range, which doesn't conflict with other Addons. You could make an ID-Config, * but we all know what "stupid" customers think about conflicting ID's diff --git a/src/main/java/gregtech/api/enums/Element.java b/src/main/java/gregtech/api/enums/Element.java index a0f8e6c0b1..0931663b0b 100644 --- a/src/main/java/gregtech/api/enums/Element.java +++ b/src/main/java/gregtech/api/enums/Element.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nonnull; + /** * This is some kind of Periodic Table, which I use to determine Properties of the Materials. */ @@ -308,6 +310,7 @@ public enum Element { Companion.VALUES.put(name(), this); } + @Nonnull public static Element get(String aMaterialName) { return Companion.VALUES.getOrDefault(aMaterialName, _NULL); } diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java index ed2cad0ce1..5ecf39a722 100644 --- a/src/main/java/gregtech/api/enums/ItemList.java +++ b/src/main/java/gregtech/api/enums/ItemList.java @@ -807,7 +807,6 @@ public enum ItemList implements IItemContainer { Machine_Bronze_Hammer, Machine_Bronze_Compressor, Machine_Bronze_AlloySmelter, - Machine_Bronze_BlastFurnace, Machine_Bricked_BlastFurnace, Machine_Steel_Boiler_Lava, Machine_Steel_Boiler, diff --git a/src/main/java/gregtech/api/enums/MachineType.java b/src/main/java/gregtech/api/enums/MachineType.java index 7868d80f8f..14e1781350 100644 --- a/src/main/java/gregtech/api/enums/MachineType.java +++ b/src/main/java/gregtech/api/enums/MachineType.java @@ -10,7 +10,7 @@ public enum MachineType { ASSEMBLER(FunnyTexts.ASSEMBLER, "gt.recipe.assembler"), AUTOCLAVE(FunnyTexts.AUTOCLAVE, "gt.recipe.autoclave"), BENDING_MACHINE(FunnyTexts.BENDING_MACHINE, "gt.recipe.metalbender"), - BREWERY(FunnyTexts.BREWERY, "gt.recipe.brewery"), + BREWERY(FunnyTexts.BREWERY, "gt.recipe.brewer"), CANNER(FunnyTexts.CANNER, "gt.recipe.canner"), CENTRIFUGE(FunnyTexts.CENTRIFUGE, "gt.recipe.centrifuge"), CHEMICAL_BATH(FunnyTexts.CHEMICAL_BATH, "gt.recipe.chemicalbath"), @@ -62,7 +62,7 @@ public enum MachineType { static final String ASSEMBLER = "gt.recipe.assembler.description"; static final String AUTOCLAVE = "gt.recipe.autoclave.description"; static final String BENDING_MACHINE = "gt.recipe.metalbender.description"; - static final String BREWERY = "gt.recipe.brewery.description"; + static final String BREWERY = "gt.recipe.brewer.description"; static final String CANNER = "gt.recipe.canner.description"; static final String CENTRIFUGE = "gt.recipe.centrifuge.description"; static final String CHEMICAL_BATH = "gt.recipe.chemicalbath.description"; diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index ace5f620d4..3994a02085 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -108,7 +108,6 @@ public enum MetaTileEntityIDs { SIMPLE_SOLAR_BOILER(105), STEAM_MACERATOR(106), HP_STEAM_MACERATOR(107), - BRONZE_BLAST_FURNACE_CONTROLLER(108), STEAM_EXTRACTOR(109), HP_STEAM_EXTRACTOR(110), AUTO_MAINTENANCE_HATCH(111), diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java index 1a47e41e8c..1dd7c9f6d2 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture; import com.gtnewhorizons.modularui.api.drawable.UITexture; public class GT_UITextures { @@ -23,6 +24,8 @@ public class GT_UITextures { .of(GregTech.ID, "gui/background/text_field", 142, 28, 1); public static final AdaptableUITexture BACKGROUND_TEXT_FIELD_LIGHT_GRAY = AdaptableUITexture .of(GregTech.ID, "gui/background/text_field_light_gray", 61, 12, 1); + public static final AdaptableUITexture BACKGROUND_NEI_SINGLE_RECIPE = AdaptableUITexture + .of(GregTech.ID, "gui/background/nei_single_recipe.png", 64, 64, 2); public static final SteamTexture SLOT_ITEM_STEAM = SteamTexture.fullImage(GregTech.ID, "gui/slot/item_%s"); public static final SteamTexture SLOT_FLUID_STEAM = SteamTexture.fullImage(GregTech.ID, "gui/slot/fluid_%s"); @@ -200,6 +203,10 @@ public class GT_UITextures { public static final UITexture PROGRESSBAR_STORED_EU = UITexture.fullImage(GregTech.ID, "gui/progressbar/stored_eu"); public static final UITexture PROGRESSBAR_WIREMILL = UITexture.fullImage(GregTech.ID, "gui/progressbar/wiremill"); + public static FallbackableUITexture fallbackableProgressbar(String name, UITexture fallback) { + return new FallbackableUITexture(UITexture.fullImage(GregTech.ID, "gui/progressbar/" + name), fallback); + } + public static final UITexture TAB_COVER_NORMAL = UITexture.fullImage(GregTech.ID, "gui/tab/cover_normal"); public static final UITexture TAB_COVER_HIGHLIGHT = UITexture.fullImage(GregTech.ID, "gui/tab/cover_highlight"); public static final UITexture TAB_COVER_DISABLED = UITexture.fullImage(GregTech.ID, "gui/tab/cover_disabled"); 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; + } +} diff --git a/src/main/java/gregtech/api/items/GT_MetaGenerated_Item.java b/src/main/java/gregtech/api/items/GT_MetaGenerated_Item.java index 828fab4368..465c4bc9d6 100644 --- a/src/main/java/gregtech/api/items/GT_MetaGenerated_Item.java +++ b/src/main/java/gregtech/api/items/GT_MetaGenerated_Item.java @@ -3,7 +3,7 @@ package gregtech.api.items; import static gregtech.api.enums.GT_Values.D1; import static gregtech.api.enums.Mods.AppleCore; import static gregtech.api.enums.Mods.GregTech; -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sCannerRecipes; +import static gregtech.api.recipe.RecipeMaps.cannerRecipes; import static gregtech.api.util.GT_RecipeBuilder.SECONDS; import java.util.ArrayList; @@ -153,7 +153,7 @@ public abstract class GT_MetaGenerated_Item extends GT_MetaBase_Item implements : ItemList.IC2_Food_Can_Filled.get(tFoodValue)) .duration(tFoodValue * 5 * SECONDS) .eut(1) - .addTo(sCannerRecipes); + .addTo(cannerRecipes); } } tUseOreDict = false; diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java index 05d39cd02c..3c7974db9e 100644 --- a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java @@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import gregtech.api.multitileentity.multiblock.base.Controller; +import gregtech.api.recipe.RecipeMap; import gregtech.api.util.GT_OverclockCalculator; import gregtech.api.util.GT_ParallelHelper; import gregtech.api.util.GT_Recipe; @@ -13,7 +14,7 @@ import gregtech.api.util.GT_Recipe; public class ComplexParallelProcessingLogic { protected Controller tileEntity; - protected GT_Recipe.GT_Recipe_Map recipeMap; + protected RecipeMap recipeMap; protected boolean hasPerfectOverclock; protected final int maxComplexParallels; protected final ItemStack[][] outputItems; @@ -30,7 +31,7 @@ public class ComplexParallelProcessingLogic { this(null, maxComplexParallels); } - public ComplexParallelProcessingLogic(GT_Recipe.GT_Recipe_Map recipeMap, int maxComplexParallels) { + public ComplexParallelProcessingLogic(RecipeMap recipeMap, int maxComplexParallels) { this.maxComplexParallels = maxComplexParallels; this.recipeMap = recipeMap; inputItems = new ItemStack[maxComplexParallels][]; @@ -44,7 +45,7 @@ public class ComplexParallelProcessingLogic { isFluidVoidProtected = new boolean[maxComplexParallels]; } - public ComplexParallelProcessingLogic setRecipeMap(GT_Recipe.GT_Recipe_Map recipeMap) { + public ComplexParallelProcessingLogic setRecipeMap(RecipeMap recipeMap) { this.recipeMap = recipeMap; return this; } diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 803abafbe3..6b9f2d454f 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -2,6 +2,7 @@ package gregtech.api.logic; import java.util.List; import java.util.function.Supplier; +import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -13,15 +14,13 @@ import org.jetbrains.annotations.NotNull; import gregtech.api.interfaces.tileentity.IRecipeLockable; import gregtech.api.interfaces.tileentity.IVoidable; +import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; -import gregtech.api.recipe.check.FindRecipeResult; -import gregtech.api.recipe.check.RecipeValidator; import gregtech.api.recipe.check.SingleRecipeCheck; import gregtech.api.util.GT_OverclockCalculator; import gregtech.api.util.GT_ParallelHelper; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; /** * Logic class to calculate result of recipe check from inputs, based on recipemap. @@ -31,9 +30,9 @@ public class ProcessingLogic { protected IVoidable machine; protected IRecipeLockable recipeLockableMachine; - protected Supplier recipeMapSupplier; + protected Supplier> recipeMapSupplier; protected GT_Recipe lastRecipe; - protected GT_Recipe_Map lastRecipeMap; + protected RecipeMap lastRecipeMap; protected ItemStack specialSlotItem; protected ItemStack[] inputItems; protected ItemStack[] outputItems; @@ -146,11 +145,11 @@ public class ProcessingLogic { return this; } - public ProcessingLogic setRecipeMap(GT_Recipe_Map recipeMap) { + public ProcessingLogic setRecipeMap(RecipeMap recipeMap) { return setRecipeMapSupplier(() -> recipeMap); } - public ProcessingLogic setRecipeMapSupplier(Supplier supplier) { + public ProcessingLogic setRecipeMapSupplier(Supplier> supplier) { this.recipeMapSupplier = supplier; return this; } @@ -263,7 +262,7 @@ public class ProcessingLogic { */ @Nonnull public CheckRecipeResult process() { - GT_Recipe_Map recipeMap; + RecipeMap recipeMap; if (recipeMapSupplier == null) { recipeMap = null; } else { @@ -278,6 +277,13 @@ public class ProcessingLogic { maxParallel = maxParallelSupplier.get(); } + if (inputItems == null) { + inputItems = new ItemStack[0]; + } + if (inputFluids == null) { + inputFluids = new FluidStack[0]; + } + if (isRecipeLocked && recipeLockableMachine != null && recipeLockableMachine.getSingleRecipeCheck() != null) { // Recipe checker is already built, we'll use it SingleRecipeCheck singleRecipeCheck = recipeLockableMachine.getSingleRecipeCheck(); @@ -287,55 +293,39 @@ public class ProcessingLogic { return CheckRecipeResultRegistry.NO_RECIPE; } - return processRecipe( + return validateAndCalculateRecipe( recipeLockableMachine.getSingleRecipeCheck() - .getRecipe()); + .getRecipe()).checkRecipeResult; } - FindRecipeResult findRecipeResult = findRecipe(recipeMap); - // If processRecipe is not overridden, advanced recipe validation logic is used, and we can reuse calculations. - if (findRecipeResult.hasRecipeValidator()) { - RecipeValidator recipeValidator = findRecipeResult.getRecipeValidator(); - - // There are two cases: - // 1 - there are actually no matching recipes - // 2 - there are some matching recipes, but we rejected it due to our advanced validation (e.g. OUTPUT_FULL) - if (findRecipeResult.getState() == FindRecipeResult.State.NOT_FOUND - && recipeValidator.getFirstCheckResult() != null) { - // Here we're handling case 2 - // If there are matching recipes but our validation rejected them, - // we should return a first one to display a proper error in the machine GUI - return recipeValidator.getFirstCheckResult(); + Stream matchedRecipes = findRecipeMatches(recipeMap); + Iterable recipeIterable = matchedRecipes::iterator; + CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NO_RECIPE; + for (GT_Recipe matchedRecipe : recipeIterable) { + CalculationResult foundResult = validateAndCalculateRecipe(matchedRecipe); + if (foundResult.successfullyConsumedInputs) { + // Successfully found and set recipe, so return it + return foundResult.checkRecipeResult; } - - // If everything is ok, reuse our calculations - if (recipeValidator.isExecutedAtLeastOnce() && findRecipeResult.isSuccessful()) { - return applyRecipe( - findRecipeResult.getRecipeNonNull(), - recipeValidator.getLastParallelHelper(), - recipeValidator.getLastOverclockCalculator(), - recipeValidator.getLastCheckResult()); + if (foundResult.checkRecipeResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + checkRecipeResult = foundResult.checkRecipeResult; } } - - if (!findRecipeResult.isSuccessful()) { - return CheckRecipeResultRegistry.NO_RECIPE; - } - - return processRecipe(findRecipeResult.getRecipeNonNull()); + return checkRecipeResult; } /** - * Checks if supplied recipe is valid for process. - * If so, additionally performs input consumption, output calculation with parallel, and overclock calculation. + * Checks if supplied recipe is valid for process. This involves voltage check, output full check. If successful, + * additionally performs input consumption, output calculation with parallel, and overclock calculation. * * @param recipe The recipe which will be checked and processed */ @Nonnull - protected CheckRecipeResult processRecipe(@Nonnull GT_Recipe recipe) { + private CalculationResult validateAndCalculateRecipe(@Nonnull GT_Recipe recipe) { CheckRecipeResult result = validateRecipe(recipe); if (!result.wasSuccessful()) { - return result; + return CalculationResult.ofFailure(result); } GT_ParallelHelper helper = createParallelHelper(recipe); @@ -343,19 +333,20 @@ public class ProcessingLogic { helper.setCalculator(calculator); helper.build(); - return applyRecipe(recipe, helper, calculator, result); + if (!helper.getResult() + .wasSuccessful()) { + return CalculationResult.ofFailure(helper.getResult()); + } + + return CalculationResult.ofSuccess(applyRecipe(recipe, helper, calculator, result)); } /** - * Applies the recipe and calculated parameters + * Check has been succeeded, so it applies the recipe and calculated parameters. + * At this point, inputs have been already consumed. */ private CheckRecipeResult applyRecipe(@NotNull GT_Recipe recipe, GT_ParallelHelper helper, GT_OverclockCalculator calculator, CheckRecipeResult result) { - if (!helper.getResult() - .wasSuccessful()) { - return helper.getResult(); - } - if (recipe.mCanBeBuffered) { lastRecipe = recipe; } else { @@ -398,30 +389,31 @@ public class ProcessingLogic { } /** - * Override if you don't work with regular gt recipe maps + * Finds a list of matched recipes. At this point no additional check to the matched recipe has been done. + *

+ * Override {@link #validateRecipe} to have custom check. + *

+ * Override this method if it doesn't work with normal recipemaps. */ @Nonnull - protected FindRecipeResult findRecipe(@Nullable GT_Recipe_Map map) { - if (map == null) return FindRecipeResult.NOT_FOUND; - - RecipeValidator recipeValidator = new RecipeValidator( - this::validateRecipe, - this::createParallelHelper, - this::createOverclockCalculator); - - FindRecipeResult findRecipeResult = map.findRecipeWithResult( - lastRecipe, - recipeValidator, - false, - false, - amperageOC ? availableVoltage * availableAmperage : availableVoltage, - inputFluids, - specialSlotItem, - inputItems); - - findRecipeResult.setRecipeValidator(recipeValidator); + protected Stream findRecipeMatches(@Nullable RecipeMap map) { + if (map == null) { + return Stream.empty(); + } + return map.findRecipeQuery() + .items(inputItems) + .fluids(inputFluids) + .specialSlot(specialSlotItem) + .cachedRecipe(lastRecipe) + .findAll(); + } - return findRecipeResult; + /** + * Override to do additional check for found recipe if needed. + */ + @Nonnull + protected CheckRecipeResult validateRecipe(@Nonnull GT_Recipe recipe) { + return CheckRecipeResultRegistry.SUCCESSFUL; } /** @@ -442,24 +434,6 @@ public class ProcessingLogic { .setOutputCalculation(true); } - /** - * Override to do additional check for finding recipe if needed, mainly for special value of the recipe. - */ - @Nonnull - protected CheckRecipeResult validateRecipe(@Nonnull GT_Recipe recipe) { - return CheckRecipeResultRegistry.SUCCESSFUL; - } - - /** - * Use {@link #createOverclockCalculator(GT_Recipe)} - */ - @Nonnull - @Deprecated - protected GT_OverclockCalculator createOverclockCalculator(@Nonnull GT_Recipe recipe, - @Nullable GT_ParallelHelper helper) { - return createOverclockCalculator(recipe); - } - /** * Override to tweak overclock logic if needed. */ @@ -514,4 +488,28 @@ public class ProcessingLogic { } // endregion + + /** + * Represents the status of check recipe calculation. {@link #successfullyConsumedInputs} does not necessarily mean + * {@link #checkRecipeResult} being successful, when duration or power is overflowed. Being failure means + * recipe cannot meet requirements and recipe search should be continued if possible. + */ + protected final static class CalculationResult { + + public final boolean successfullyConsumedInputs; + public final CheckRecipeResult checkRecipeResult; + + public static CalculationResult ofSuccess(CheckRecipeResult checkRecipeResult) { + return new CalculationResult(true, checkRecipeResult); + } + + public static CalculationResult ofFailure(CheckRecipeResult checkRecipeResult) { + return new CalculationResult(false, checkRecipeResult); + } + + private CalculationResult(boolean successfullyConsumedInputs, CheckRecipeResult checkRecipeResult) { + this.successfullyConsumedInputs = successfullyConsumedInputs; + this.checkRecipeResult = checkRecipeResult; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Frame.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Frame.java index f17626cdd8..399c536b9f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Frame.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Frame.java @@ -1,6 +1,6 @@ package gregtech.api.metatileentity.implementations; -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sAssemblerRecipes; +import static gregtech.api.recipe.RecipeMaps.assemblerRecipes; import static gregtech.api.util.GT_RecipeBuilder.SECONDS; import static gregtech.api.util.GT_RecipeBuilder.TICKS; import static gregtech.api.util.GT_Utility.calculateRecipeEU; @@ -54,7 +54,7 @@ public class GT_MetaPipeEntity_Frame extends MetaPipeEntity { .itemOutputs(getStackForm(1)) .duration(3 * SECONDS + 4 * TICKS) .eut(calculateRecipeEU(aMaterial, 7)) - .addTo(sAssemblerRecipes); + .addTo(assemblerRecipes); } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 93bbdd2d18..897f9dad6f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -15,14 +15,17 @@ import gregtech.api.enums.Textures; import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.RecipeMapWorkable; import gregtech.api.objects.ItemData; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.maps.FuelBackend; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; -public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity_BasicTank { +public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity_BasicTank + implements RecipeMapWorkable { public GT_MetaTileEntity_BasicGenerator(int aID, String aName, String aNameRegional, int aTier, String aDescription, ITexture... aTextures) { @@ -273,7 +276,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public abstract int getPollution(); - public abstract GT_Recipe_Map getRecipes(); + @Override + public abstract RecipeMap getRecipeMap(); public abstract int getEfficiency(); @@ -287,8 +291,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity } public long getFuelValue(FluidStack aLiquid, boolean aLong) { - GT_Recipe_Map tRecipes = getRecipes(); - if (aLiquid == null || !(tRecipes instanceof GT_Recipe.GT_Recipe_Map_Fuel tFuels)) return 0; + RecipeMap tRecipes = getRecipeMap(); + if (aLiquid == null || !(tRecipes.getBackend() instanceof FuelBackend tFuels)) return 0; GT_Recipe tFuel = tFuels.findFuel(aLiquid); if (tFuel == null) return 0; @@ -301,8 +305,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity } public long getFuelValue(ItemStack aStack, boolean aLong) { - if (GT_Utility.isStackInvalid(aStack) || getRecipes() == null) return 0; - GT_Recipe tFuel = getRecipes().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (GT_Utility.isStackInvalid(aStack) || getRecipeMap() == null) return 0; + GT_Recipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); if (tFuel == null) return 0; long liters = 10L; // 1000mb/100 @@ -310,8 +314,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity } public ItemStack getEmptyContainer(ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || getRecipes() == null) return null; - GT_Recipe tFuel = getRecipes().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (GT_Utility.isStackInvalid(aStack) || getRecipeMap() == null) return null; + GT_Recipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); if (tFuel != null) return GT_Utility.copyOrNull(tFuel.getOutput(0)); return GT_Utility.getContainerItem(aStack, true); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 0e86829027..ba8c865301 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -14,6 +14,8 @@ import static gregtech.api.metatileentity.BaseTileEntity.STALLED_STUTTERING_TOOL import static gregtech.api.metatileentity.BaseTileEntity.STALLED_VENT_TOOLTIP; import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import static gregtech.api.metatileentity.BaseTileEntity.UNUSED_SLOT_TOOLTIP; +import static gregtech.api.util.GT_RecipeConstants.EXPLODE; +import static gregtech.api.util.GT_RecipeConstants.ON_FIRE; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; import static net.minecraftforge.common.util.ForgeDirection.DOWN; import static net.minecraftforge.common.util.ForgeDirection.UNKNOWN; @@ -23,6 +25,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import javax.annotation.Nonnull; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -39,7 +43,6 @@ import net.minecraftforge.fluids.IFluidHandler; import org.apache.commons.lang3.tuple.Pair; import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -65,21 +68,24 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.modularui.IAddGregtechLogo; import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IOverclockDescriptionProvider; +import gregtech.api.interfaces.tileentity.RecipeMapWorkable; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.recipe.check.FindRecipeResult; +import gregtech.api.objects.overclockdescriber.EUOverclockDescriber; +import gregtech.api.objects.overclockdescriber.OverclockDescriber; +import gregtech.api.recipe.BasicUIProperties; +import gregtech.api.recipe.RecipeMap; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ClientPreference; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_OverclockCalculator; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_TooltipDataCache; import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Waila; import gregtech.common.gui.modularui.UIHelper; -import gregtech.common.power.BasicMachineEUPower; -import gregtech.common.power.Power; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -89,8 +95,8 @@ import mcp.mobius.waila.api.IWailaDataAccessor; * This is the main construct for my Basic Machines such as the Automatic Extractor Extend this class to make a simple * Machine */ -public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_BasicTank - implements IConfigurationCircuitSupport, IAddGregtechLogo, IAddUIWidgets { +public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_BasicTank implements RecipeMapWorkable, + IConfigurationCircuitSupport, IOverclockDescriptionProvider, IAddGregtechLogo, IAddUIWidgets { /** * return values for checkRecipe() @@ -108,9 +114,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B public int mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mOutputBlocked = 0; public ForgeDirection mMainFacing = ForgeDirection.WEST; public FluidStack mOutputFluid; - @Deprecated - public String mGUIName = "", mNEIName = ""; - protected final Power mPower; + protected final OverclockDescriber overclockDescriber; /** * Contains the Recipe which has been previously used, or null if there was no previous Recipe, which could have @@ -147,29 +151,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; - mPower = buildPower(); - } - - /** - * @deprecated Use {@link #GT_MetaTileEntity_BasicMachine(int, String, String, int, int, String, int, int, - * ITexture...)} - */ - @Deprecated - public GT_MetaTileEntity_BasicMachine(int aID, String aName, String aNameRegional, int aTier, int aAmperage, - String aDescription, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName, - ITexture... aOverlays) { - super( - aID, - aName, - aNameRegional, - aTier, - OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, - aDescription, - aOverlays); - mInputSlotCount = Math.max(0, aInputSlotCount); - mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; - mAmperage = aAmperage; - mPower = buildPower(); + overclockDescriber = createOverclockDescriber(); } /** @@ -188,42 +170,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; - mPower = buildPower(); - } - - /** - * @deprecated Use {@link #GT_MetaTileEntity_BasicMachine(int, String, String, int, int, String[], int, int, - * ITexture...)} - */ - @Deprecated - public GT_MetaTileEntity_BasicMachine(int aID, String aName, String aNameRegional, int aTier, int aAmperage, - String[] aDescription, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName, - ITexture... aOverlays) { - super( - aID, - aName, - aNameRegional, - aTier, - OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, - aDescription, - aOverlays); - mInputSlotCount = Math.max(0, aInputSlotCount); - mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; - mAmperage = aAmperage; - mPower = buildPower(); - } - - /** - * @deprecated Use {@link #GT_MetaTileEntity_BasicMachine(String, int, int, String[], ITexture[][][], int, int)} - */ - @Deprecated - public GT_MetaTileEntity_BasicMachine(String aName, int aTier, int aAmperage, String aDescription, - ITexture[][][] aTextures, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName) { - super(aName, aTier, OTHER_SLOT_COUNT + aInputSlotCount + aOutputSlotCount + 1, aDescription, aTextures); - mInputSlotCount = Math.max(0, aInputSlotCount); - mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; - mAmperage = aAmperage; - mPower = buildPower(); + overclockDescriber = createOverclockDescriber(); } /** @@ -235,27 +182,14 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B mInputSlotCount = Math.max(0, aInputSlotCount); mOutputItems = new ItemStack[Math.max(0, aOutputSlotCount)]; mAmperage = aAmperage; - mPower = buildPower(); - } - - /** - * @deprecated Use {@link #GT_MetaTileEntity_BasicMachine(String, int, int, String[], ITexture[][][], int, int)} - */ - @Deprecated - public GT_MetaTileEntity_BasicMachine(String aName, int aTier, int aAmperage, String[] aDescription, - ITexture[][][] aTextures, int aInputSlotCount, int aOutputSlotCount, String aGUIName, String aNEIName) { - super(aName, aTier, OTHER_SLOT_COUNT + aI