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> --- .../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 - 17 files changed, 595 insertions(+), 6106 deletions(-) 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/util') diff --git a/src/main/java/gregtech/api/util/FieldsAreNonnullByDefault.java b/src/main/java/gregtech/api/util/FieldsAreNonnullByDefault.java new file mode 100644 index 0000000000..1f51aa39a7 --- /dev/null +++ b/src/main/java/gregtech/api/util/FieldsAreNonnullByDefault.java @@ -0,0 +1,18 @@ +package gregtech.api.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +/** + * This annotation can be applied to a package or class to indicate that + * the fields in that element are nonnull by default unless there is an explicit nullness annotation. + * + */ +@Nonnull +@TypeQualifierDefault({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface FieldsAreNonnullByDefault {} diff --git a/src/main/java/gregtech/api/util/GT_Config.java b/src/main/java/gregtech/api/util/GT_Config.java index 36585559c2..dc56def68f 100644 --- a/src/main/java/gregtech/api/util/GT_Config.java +++ b/src/main/java/gregtech/api/util/GT_Config.java @@ -139,6 +139,20 @@ public class GT_Config implements Runnable { return rResult; } + public String getWithValidValues(Object aCategory, String aName, String[] validValues, String aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get( + aCategory.toString() + .replaceAll("\\|", "_"), + aName.replaceAll("\\|", "_"), + aDefault, + null, + validValues); + String rResult = tProperty.getString(); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + @Override public void run() { mConfig.save(); diff --git a/src/main/java/gregtech/api/util/GT_Forestry_Compat.java b/src/main/java/gregtech/api/util/GT_Forestry_Compat.java index 933c379db1..427703e6f7 100644 --- a/src/main/java/gregtech/api/util/GT_Forestry_Compat.java +++ b/src/main/java/gregtech/api/util/GT_Forestry_Compat.java @@ -11,12 +11,13 @@ import forestry.api.recipes.RecipeManagers; import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; +import gregtech.api.recipe.RecipeMaps; public class GT_Forestry_Compat { public static void populateFakeNeiRecipes() { if (ItemList.FR_Bee_Drone.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Bee_Drone.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Bee_Drone.getWithName(1L, "Scanned Drone") }, @@ -28,7 +29,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Bee_Princess.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Bee_Princess.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Bee_Princess.getWithName(1L, "Scanned Princess") }, @@ -40,7 +41,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Bee_Queen.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Bee_Queen.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Bee_Queen.getWithName(1L, "Scanned Queen") }, @@ -52,7 +53,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Tree_Sapling.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Tree_Sapling.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Tree_Sapling.getWithName(1L, "Scanned Sapling") }, @@ -64,7 +65,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Butterfly.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Butterfly.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Butterfly.getWithName(1L, "Scanned Butterfly") }, @@ -76,7 +77,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Larvae.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Larvae.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Larvae.getWithName(1L, "Scanned Larvae") }, @@ -88,7 +89,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Serum.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Serum.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Serum.getWithName(1L, "Scanned Serum") }, @@ -100,7 +101,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_Caterpillar.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_Caterpillar.getWildcard(1L) }, new ItemStack[] { ItemList.FR_Caterpillar.getWithName(1L, "Scanned Caterpillar") }, @@ -112,7 +113,7 @@ public class GT_Forestry_Compat { 0); } if (ItemList.FR_PollenFertile.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe( + RecipeMaps.scannerFakeRecipes.addFakeRecipe( false, new ItemStack[] { ItemList.FR_PollenFertile.getWildcard(1L) }, new ItemStack[] { ItemList.FR_PollenFertile.getWithName(1L, "Scanned Pollen") }, @@ -138,7 +139,7 @@ public class GT_Forestry_Compat { .copy(); i++; } - GT_Recipe.GT_Recipe_Map.sCentrifugeRecipes.addRecipe( + RecipeMaps.centrifugeRecipes.addRecipe( true, new ItemStack[] { tRecipe.getInput() }, tOutputs, @@ -149,7 +150,7 @@ public class GT_Forestry_Compat { 128, 5, 0); - GT_Recipe.GT_Recipe_Map.sMultiblockCentrifugeRecipes.addRecipe( + RecipeMaps.centrifugeNonCellRecipes.addRecipe( true, new ItemStack[] { tRecipe.getInput() }, tOutputs, @@ -172,7 +173,7 @@ public class GT_Forestry_Compat { try { for (ISqueezerRecipe tRecipe : RecipeManagers.squeezerManager.recipes()) { if ((tRecipe.getResources().length == 1) && (tRecipe.getFluidOutput() != null)) { - GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes.addRecipe( + RecipeMaps.fluidExtractionRecipes.addRecipe( true, new ItemStack[] { tRecipe.getResources()[0] }, new ItemStack[] { tRecipe.getRemnants() }, diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java index 76e59eed22..ed82befbcc 100644 --- a/src/main/java/gregtech/api/util/GT_LanguageManager.java +++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java @@ -315,7 +315,6 @@ public class GT_LanguageManager { addStringLocalization("Interaction_DESCRIPTION_Index_151.2", "Outputs 1 specific Fluid"); addStringLocalization("Interaction_DESCRIPTION_Index_151.4", "Successfully locked Fluid to %s"); addStringLocalization("Interaction_DESCRIPTION_Index_152", "Total: "); - addStringLocalization("Interaction_DESCRIPTION_Index_152.1", "Max EU: "); addStringLocalization("Interaction_DESCRIPTION_Index_153", "Usage: "); addStringLocalization("Interaction_DESCRIPTION_Index_154", "Voltage: "); addStringLocalization("Interaction_DESCRIPTION_Index_155", "Amperage: "); diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index e16e559360..b83c70d7de 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -9,9 +9,9 @@ import static gregtech.api.enums.GT_Values.M; import static gregtech.api.enums.GT_Values.RA; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.W; -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sExtractorRecipes; -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sOreWasherRecipes; +import static gregtech.api.recipe.RecipeMaps.alloySmelterRecipes; +import static gregtech.api.recipe.RecipeMaps.extractorRecipes; +import static gregtech.api.recipe.RecipeMaps.oreWasherRecipes; import static gregtech.api.util.GT_RecipeBuilder.SECONDS; import static gregtech.api.util.GT_RecipeBuilder.TICKS; @@ -70,6 +70,8 @@ import gregtech.api.items.GT_MetaBase_Item; import gregtech.api.objects.GT_HashSet; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; +import gregtech.api.recipe.RecipeCategories; +import gregtech.api.recipe.RecipeMap; import ic2.api.item.IBoxable; import ic2.api.item.IC2Items; import ic2.api.item.IElectricItem; @@ -569,11 +571,12 @@ public class GT_ModHandler { } recipeBuilder.itemOutputs(aOutput) .duration(duration * TICKS) - .eut(3); + .eut(3) + .recipeCategory(RecipeCategories.alloySmelterRecycling); if (hidden) { recipeBuilder.hidden(); } - recipeBuilder.addTo(sAlloySmelterRecipes); + recipeBuilder.addTo(alloySmelterRecipes); return true; } @@ -617,7 +620,7 @@ public class GT_ModHandler { .itemOutputs(aOutput) .duration(15 * SECONDS) .eut(2) - .addTo(sExtractorRecipes); + .addTo(extractorRecipes); return true; } @@ -733,7 +736,7 @@ public class GT_ModHandler { .itemOutputs(aOutput1) .duration(aDuration) .eut(aEUt) - .addTo(sAlloySmelterRecipes); + .addTo(alloySmelterRecipes); return true; } @@ -759,9 +762,8 @@ public class GT_ModHandler { /** * Adds GT versions of the IC2 recipes from the supplied IC2RecipeList. */ - public static void addIC2RecipesToGT(Map aIC2RecipeList, - GT_Recipe.GT_Recipe_Map aGTRecipeMap, boolean aAddGTRecipe, boolean aRemoveIC2Recipe, - boolean aExcludeGTIC2Items) { + public static void addIC2RecipesToGT(Map aIC2RecipeList, RecipeMap aGTRecipeMap, + boolean aAddGTRecipe, boolean aRemoveIC2Recipe, boolean aExcludeGTIC2Items) { Map aRecipesToRemove = new HashMap<>(); for (Entry iRecipeInputRecipeOutputEntry : aIC2RecipeList.entrySet()) { if (iRecipeInputRecipeOutputEntry.getValue().items.isEmpty()) { @@ -773,7 +775,7 @@ public class GT_ModHandler { continue; } - if (aAddGTRecipe && (aGTRecipeMap.findRecipe(null, false, Long.MAX_VALUE, null, tStack) == null)) { + if (aAddGTRecipe) { try { if (aExcludeGTIC2Items && ((tStack.getUnlocalizedName() .contains("gt.metaitem.01") @@ -784,7 +786,7 @@ public class GT_ModHandler { || tStack.getUnlocalizedName() .contains("ic2.itemPurifiedCrushed")))) continue; - switch (aGTRecipeMap.mUnlocalizedName) { + switch (aGTRecipeMap.unlocalizedName) { case "gt.recipe.macerator", "gt.recipe.extractor", "gt.recipe.compressor" -> aGTRecipeMap .addRecipe( true, @@ -928,7 +930,7 @@ public class GT_ModHandler { .fluidInputs(GT_ModHandler.getWater(aWaterAmount)) .duration(25 * SECONDS) .eut(16) - .addTo(sOreWasherRecipes); + .addTo(oreWasherRecipes); RA.stdBuilder() .itemInputs(aInput) @@ -937,7 +939,7 @@ public class GT_ModHandler { .fluidInputs(GT_ModHandler.getDistilledWater(aWaterAmount / 5)) .duration(15 * SECONDS) .eut(16) - .addTo(sOreWasherRecipes); + .addTo(oreWasherRecipes); return true; } @@ -950,7 +952,7 @@ public class GT_ModHandler { .fluidInputs(GT_ModHandler.getWater(aWaterAmount)) .duration(25 * SECONDS) .eut(16) - .addTo(sOreWasherRecipes); + .addTo(oreWasherRecipes); RA.stdBuilder() .itemInputs(aInput) @@ -958,7 +960,7 @@ public class GT_ModHandler { .fluidInputs(GT_ModHandler.getDistilledWater(aWaterAmount / 5)) .duration(15 * SECONDS) .eut(16) - .addTo(sOreWasherRecipes); + .addTo(oreWasherRecipes); return true; } diff --git a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java index 582b65e7ec..8e896fd8de 100644 --- a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java +++ b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java @@ -197,14 +197,6 @@ public class GT_OverclockCalculator { return this; } - /** - * Use {@link #setHeatOC(boolean)} - */ - @Deprecated - public GT_OverclockCalculator enableHeatOC() { - return setHeatOC(true); - } - /** * Set if we should be calculating overclocking using EBF's perfectOC */ @@ -213,14 +205,6 @@ public class GT_OverclockCalculator { return this; } - /** - * Use {@link #setHeatDiscount(boolean)} - */ - @Deprecated - public GT_OverclockCalculator enableHeatDiscount() { - return setHeatDiscount(true); - } - /** * Sets if we should add a heat discount at the end of calculating an overclock, just like the EBF */ @@ -237,14 +221,6 @@ public class GT_OverclockCalculator { return this; } - /** - * Use {@link #setMachineHeat(int)} - */ - @Deprecated - public GT_OverclockCalculator setMultiHeat(int machineHeat) { - return setMachineHeat(machineHeat); - } - /** * Sets the heat of the coils on the machine */ @@ -312,14 +288,6 @@ public class GT_OverclockCalculator { return this; } - /** - * Use {@link #setOneTickDiscount(boolean)} - */ - @Deprecated - public GT_OverclockCalculator enableOneTickDiscount() { - return setOneTickDiscount(true); - } - /** * Set One Tick Discount on EUt based on Duration Decrease Per Overclock. This functions the same as single * blocks. @@ -556,7 +524,7 @@ public class GT_OverclockCalculator { /** * Returns the EUt consumption one would get from overclocking under 1 tick * This Doesn't count as calculating - * + * * @param originalMaxParallel Parallels which are of the actual machine before the overclocking extra ones */ public long calculateEUtConsumptionUnderOneTick(int originalMaxParallel, int currentParallel) { diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index d3921b613d..8a5cd0b9f8 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -10,8 +10,8 @@ import net.minecraftforge.fluids.FluidStack; import gregtech.api.interfaces.tileentity.IRecipeLockable; import gregtech.api.interfaces.tileentity.IVoidable; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.objects.XSTR; +import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.recipe.check.SingleRecipeCheck; @@ -123,27 +123,6 @@ public class GT_ParallelHelper { public GT_ParallelHelper() {} - /** - * Sets MetaTE controller, with current configuration for void protection mode. - * - * @deprecated Use {@link #setMachine(IVoidable)} - */ - @Deprecated - public GT_ParallelHelper setController(GT_MetaTileEntity_MultiBlockBase machineMeta) { - return setMachine(machineMeta, machineMeta.protectsExcessItem(), machineMeta.protectsExcessFluid()); - } - - /** - * Sets MetaTE controller, with void protection mode forcibly. - * - * @deprecated Use {@link #setMachine(IVoidable, boolean, boolean)} - */ - @Deprecated - public GT_ParallelHelper setController(GT_MetaTileEntity_MultiBlockBase machineMeta, boolean protectExcessItem, - boolean protectExcessFluid) { - return setMachine(machineMeta, protectExcessItem, protectExcessFluid); - } - /** * Sets machine, with current configuration for void protection mode. */ @@ -212,14 +191,6 @@ public class GT_ParallelHelper { return this; } - /** - * Use {@link #setConsumption(boolean)} - */ - @Deprecated - public GT_ParallelHelper enableConsumption() { - return setConsumption(true); - } - /** * Set if we should consume inputs or not when trying for parallels * @@ -248,14 +219,6 @@ public class GT_ParallelHelper { return this; } - /** - * Use {@link #setOutputCalculation(boolean)} - */ - @Deprecated - public GT_ParallelHelper enableOutputCalculation() { - return setOutputCalculation(true); - } - /** * Sets if we should calculate outputs with the parallels we found or not * @@ -338,14 +301,6 @@ public class GT_ParallelHelper { return 1; } - /** - * @deprecated Use {@link #getDurationMultiplierDouble()} - */ - @Deprecated - public float getDurationMultiplier() { - return (float) getDurationMultiplierDouble(); - } - /** * @return The ItemOutputs from the recipe */ @@ -381,23 +336,6 @@ public class GT_ParallelHelper { return result; } - /** - * @deprecated Use {@link #setMaxParallelCalculator} and {@link #setInputConsumer} - */ - @Deprecated - protected boolean tryConsumeRecipeInputs(GT_Recipe recipe, FluidStack[] fluids, ItemStack[] items) { - return false; - } - - /** - * @deprecated Use {@link #setMaxParallelCalculator} and {@link #setInputConsumer} - */ - @Deprecated - protected boolean tryConsumeRecipeInputs(GT_Recipe recipe, FluidStack[] fluids, ItemStack[] items, - int minParallel) { - return false; - } - /** * Called by build(). Determines the parallels and everything else that needs to be done at build time */ @@ -446,7 +384,7 @@ public class GT_ParallelHelper { if (recipeCheck == null) { // Machine is configured to lock to a single recipe, but haven't built the recipe checker yet. // Build the checker on next successful recipe. - GT_Recipe.GT_Recipe_Map recipeMap = singleRecipeMachine.getRecipeMap(); + RecipeMap recipeMap = singleRecipeMachine.getRecipeMap(); if (recipeMap != null) { tSingleRecipeCheckBuilder = SingleRecipeCheck.builder(recipeMap) .setBefore(itemInputs, fluidInputs); diff --git a/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java b/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java index 7ff37a927c..ead9393d0e 100644 --- a/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java +++ b/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java @@ -5,24 +5,24 @@ import java.util.HashMap; import net.minecraft.item.ItemStack; import gregtech.api.enums.SoundResource; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.recipe.RecipeMap; @Deprecated public class GT_ProcessingArray_Manager { - private static final HashMap mRecipeSaves = new HashMap<>(); + private static final HashMap> mRecipeSaves = new HashMap<>(); private static final HashMap machineSounds = new HashMap<>(); // Adds recipe Maps to the PA using the machines unlocalized name. // Example: basicmachine.electrolyzer, with its recipe map will add the electrolyzer's recipe map to the PA - public static void addRecipeMapToPA(String aMachineName, GT_Recipe_Map aMap) { + public static void addRecipeMapToPA(String aMachineName, RecipeMap aMap) { if (aMachineName != null) { mRecipeSaves.put(aMachineName, aMap); } } // Allows the PA to extract the recipe map for the machine inside it. - public static GT_Recipe_Map giveRecipeMap(String aMachineName) { + public static RecipeMap giveRecipeMap(String aMachineName) { if (aMachineName != null) { return mRecipeSaves.get(aMachineName); } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 535da25934..a444a16ef2 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1,148 +1,38 @@ package gregtech.api.util; -import static gregtech.api.enums.GT_Values.D1; import static gregtech.api.enums.GT_Values.D2; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.L; -import static gregtech.api.enums.GT_Values.W; -import static gregtech.api.enums.Mods.GTPlusPlus; -import static gregtech.api.enums.Mods.GregTech; -import static gregtech.api.enums.Mods.NEICustomDiagrams; -import static gregtech.api.enums.Mods.Railcraft; -import static gregtech.api.recipe.check.FindRecipeResult.EXPLODE; -import static gregtech.api.recipe.check.FindRecipeResult.NOT_FOUND; -import static gregtech.api.recipe.check.FindRecipeResult.ON_FIRE; -import static gregtech.api.recipe.check.FindRecipeResult.ofSuccess; -import static gregtech.api.util.GT_RecipeBuilder.handleRecipeCollision; -import static gregtech.api.util.GT_RecipeConstants.ADDITIVE_AMOUNT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_FLUIDSTACK_INPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_FLUIDSTACK_OUTPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_FLUID_OUTPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_ITEM_INPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_ITEM_OR_FLUID_INPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_ITEM_OR_FLUID_OUTPUT; -import static gregtech.api.util.GT_RecipeMapUtil.FIRST_ITEM_OUTPUT; -import static gregtech.api.util.GT_RecipeMapUtil.GT_RecipeTemplate; -import static gregtech.api.util.GT_RecipeMapUtil.SPECIAL_VALUE_ALIASES; -import static gregtech.api.util.GT_RecipeMapUtil.asTemplate; -import static gregtech.api.util.GT_RecipeMapUtil.buildOrEmpty; -import static gregtech.api.util.GT_Utility.formatNumbers; -import static gregtech.api.util.GT_Utility.isArrayEmptyOrNull; -import static gregtech.api.util.GT_Utility.isArrayOfLength; -import static net.minecraft.util.EnumChatFormatting.GRAY; -import static net.minecraft.util.StatCollector.translateToLocal; -import java.awt.Rectangle; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.Contract; -import com.google.common.collect.Iterables; -import com.gtnewhorizons.modularui.api.GlStateManager; -import com.gtnewhorizons.modularui.api.ModularUITextures; -import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture; -import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.drawable.UITexture; -import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; -import com.gtnewhorizons.modularui.api.math.Alignment; -import com.gtnewhorizons.modularui.api.math.Pos2d; -import com.gtnewhorizons.modularui.api.math.Size; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; -import com.gtnewhorizons.modularui.common.widget.ProgressBar; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; - -import appeng.util.ReadableNumberConverter; -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.PositionedStack; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; -import gnu.trove.map.TByteObjectMap; -import gnu.trove.map.hash.TByteObjectHashMap; import gregtech.GT_Mod; import gregtech.api.GregTech_API; -import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Element; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.SteamVariant; -import gregtech.api.enums.SubTag; -import gregtech.api.gui.GT_GUIColorOverride; -import gregtech.api.gui.modularui.FallbackableSteamTexture; -import gregtech.api.gui.modularui.GT_UITextures; -import gregtech.api.gui.modularui.SteamTexture; -import gregtech.api.interfaces.IGT_RecipeMap; -import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.objects.ItemData; -import gregtech.api.objects.MaterialStack; -import gregtech.api.recipe.check.FindRecipeResult; +import gregtech.api.recipe.RecipeCategory; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.RecipeMetadataKey; +import gregtech.api.recipe.metadata.EmptyRecipeMetadataStorage; +import gregtech.api.recipe.metadata.IRecipeMetadataStorage; import gregtech.api.util.extensions.ArrayExt; -import gregtech.common.gui.modularui.UIHelper; -import gregtech.common.items.GT_FluidDisplayItem; -import gregtech.common.misc.spaceprojects.SpaceProjectManager; -import gregtech.common.misc.spaceprojects.interfaces.ISpaceProject; -import gregtech.common.power.EUPower; -import gregtech.common.power.Power; -import gregtech.common.power.UnspecifiedEUPower; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator; -import gregtech.nei.FusionSpecialValueFormatter; -import gregtech.nei.GT_NEI_DefaultHandler; -import gregtech.nei.HeatingCoilSpecialValueFormatter; -import gregtech.nei.INEISpecialInfoFormatter; -import gregtech.nei.NEIRecipeInfo; import ic2.core.Ic2Items; -import mods.railcraft.common.blocks.aesthetics.cube.EnumCube; -import mods.railcraft.common.items.RailcraftToolItems; -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - *

- * This File contains the functions used for Recipes. Please do not include this File AT ALL in your Moddownload as it - * ruins compatibility This is just the Core of my Recipe System, if you just want to GET the Recipes I add, then you - * can access this File. Do NOT add Recipes using the Constructors inside this Class, The GregTech_API File calls the - * correct Functions for these Constructors. - *

- * I know this File causes some Errors, because of missing Main Functions, but if you just need to compile Stuff, then - * remove said erroreous Functions. - */ public class GT_Recipe implements Comparable { /** @@ -199,6 +89,16 @@ public class GT_Recipe implements Comparable { * Used for describing recipes that do not fit the default recipe pattern (for example Large Boiler Fuels) */ private String[] neiDesc = null; + /** + * Holds a set of metadata for this recipe. + */ + @Nonnull + private final IRecipeMetadataStorage metadataStorage; + /** + * Category this recipe belongs to. Recipes belonging to recipemap are forced to have non-null category when added, + * otherwise it can be null. + */ + private RecipeCategory recipeCategory; /** * Stores which mod added this recipe */ @@ -206,7 +106,8 @@ public class GT_Recipe implements Comparable { /** * Stores stack traces where this recipe was added */ - public List> stackTraces = new ArrayList<>(); + // BW wants to overwrite it, so no final + public List> stackTraces = new ArrayList<>(); private GT_Recipe(GT_Recipe aRecipe, boolean shallow) { mInputs = shallow ? aRecipe.mInputs : GT_Utility.copyItemArray(aRecipe.mInputs); @@ -219,18 +120,23 @@ public class GT_Recipe implements Comparable { mSpecialValue = aRecipe.mSpecialValue; mEUt = aRecipe.mEUt; mNeedsEmptyOutput = aRecipe.mNeedsEmptyOutput; + isNBTSensitive = aRecipe.isNBTSensitive; mCanBeBuffered = aRecipe.mCanBeBuffered; mFakeRecipe = aRecipe.mFakeRecipe; mEnabled = aRecipe.mEnabled; mHidden = aRecipe.mHidden; + metadataStorage = EmptyRecipeMetadataStorage.INSTANCE; owners = new ArrayList<>(aRecipe.owners); reloadOwner(); } - // only used for GT_RecipeBuilder. Should not be called otherwise + /** + * Only for {@link GT_RecipeBuilder}. + */ GT_Recipe(ItemStack[] mInputs, ItemStack[] mOutputs, FluidStack[] mFluidInputs, FluidStack[] mFluidOutputs, int[] mChances, Object mSpecialItems, int mDuration, int mEUt, int mSpecialValue, boolean mEnabled, - boolean mHidden, boolean mFakeRecipe, boolean mCanBeBuffered, boolean mNeedsEmptyOutput, String[] neiDesc) { + boolean mHidden, boolean mFakeRecipe, boolean mCanBeBuffered, boolean mNeedsEmptyOutput, boolean nbtSensitive, + String[] neiDesc, @Nullable IRecipeMetadataStorage metadataStorage, RecipeCategory recipeCategory) { this.mInputs = mInputs; this.mOutputs = mOutputs; this.mFluidInputs = mFluidInputs; @@ -245,7 +151,10 @@ public class GT_Recipe implements Comparable { this.mFakeRecipe = mFakeRecipe; this.mCanBeBuffered = mCanBeBuffered; this.mNeedsEmptyOutput = mNeedsEmptyOutput; + this.isNBTSensitive = nbtSensitive; this.neiDesc = neiDesc; + this.metadataStorage = metadataStorage == null ? EmptyRecipeMetadataStorage.INSTANCE : metadataStorage.copy(); + this.recipeCategory = recipeCategory; reloadOwner(); } @@ -311,19 +220,11 @@ public class GT_Recipe implements Comparable { mDuration = aDuration; mSpecialValue = aSpecialValue; mEUt = aEUt; + metadataStorage = EmptyRecipeMetadataStorage.INSTANCE; // checkCellBalance(); reloadOwner(); } - public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, int aFuelValue, int aType) { - this(aInput1, aOutput1, null, null, null, aFuelValue, aType); - } - - private static FluidStack[] tryGetFluidInputsFromCells(ItemStack aInput) { - FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); - return tFluid == null ? null : new FluidStack[] { tFluid }; - } - // aSpecialValue = EU per Liter! If there is no Liquid for this Object, then it gets multiplied with 1000! public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aSpecialValue, int aType) { @@ -343,208 +244,32 @@ public class GT_Recipe implements Comparable { switch (aType) { // Diesel Generator case 0 -> { - GT_Recipe_Map.sDieselFuels.addRecipe(this); - GT_Recipe_Map.sLargeBoilerFakeFuels.addDieselRecipe(this); + RecipeMaps.dieselFuels.addRecipe(this); + RecipeMaps.largeBoilerFakeFuels.getBackend() + .addDieselRecipe(this); } // Gas Turbine - case 1 -> GT_Recipe_Map.sTurbineFuels.addRecipe(this); + case 1 -> RecipeMaps.gasTurbineFuels.addRecipe(this); // Thermal Generator - case 2 -> GT_Recipe_Map.sHotFuels.addRecipe(this); + case 2 -> RecipeMaps.hotFuels.addRecipe(this); // Plasma Generator - case 4 -> GT_Recipe_Map.sPlasmaFuels.addRecipe(this); + case 4 -> RecipeMaps.plasmaFuels.addRecipe(this); // Magic Generator - case 5 -> GT_Recipe_Map.sMagicFuels.addRecipe(this); + case 5 -> RecipeMaps.magicFuels.addRecipe(this); // Fluid Generator. Usually 3. Every wrong Type ends up in the Semifluid Generator default -> { - GT_Recipe_Map.sDenseLiquidFuels.addRecipe(this); - GT_Recipe_Map.sLargeBoilerFakeFuels.addDenseLiquidRecipe(this); + RecipeMaps.denseLiquidFuels.addRecipe(this); + RecipeMaps.largeBoilerFakeFuels.getBackend() + .addDenseLiquidRecipe(this); } } } } - public GT_Recipe(FluidStack aInput1, FluidStack aInput2, FluidStack aOutput1, int aDuration, int aEUt, - int aSpecialValue) { - this( - true, - null, - null, - null, - null, - new FluidStack[] { aInput1, aInput2 }, - new FluidStack[] { aOutput1 }, - Math.max(aDuration, 1), - aEUt, - Math.max(Math.min(aSpecialValue, 160000000), 0)); - if (mInputs.length > 1) { - GT_Recipe_Map.sFusionRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, int aDuration, int aEUt) { - this( - true, - new ItemStack[] { aInput1 }, - new ItemStack[] { aOutput1, aOutput2 }, - null, - null, - null, - null, - aDuration, - aEUt, - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sLatheRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, int aCellAmount, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, - ItemStack aOutput4, int aDuration, int aEUt) { - this( - true, - new ItemStack[] { aInput1, - aCellAmount > 0 ? ItemList.Cell_Empty.get(Math.min(64, Math.max(1, aCellAmount))) : null }, - new ItemStack[] { aOutput1, aOutput2, aOutput3, aOutput4 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - Math.max(aEUt, 1), - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sDistillationRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, int aInput2, ItemStack aOutput1, ItemStack aOutput2) { - this( - true, - new ItemStack[] { aInput1, - GT_ModHandler.getIC2Item( - "industrialTnt", - aInput2 > 0 ? Math.min(aInput2, 64) : 1, - new ItemStack(Blocks.tnt, aInput2 > 0 ? Math.min(aInput2, 64) : 1)) }, - new ItemStack[] { aOutput1, aOutput2 }, - null, - null, - null, - null, - 20, - 30, - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sImplosionRecipes.addRecipe(this); - } - } - - public GT_Recipe(int aEUt, int aDuration, ItemStack aInput1, ItemStack aOutput1) { - this( - true, - new ItemStack[] { aInput1, ItemList.Circuit_Integrated.getWithDamage(0, aInput1.stackSize) }, - new ItemStack[] { aOutput1 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - Math.max(aEUt, 1), - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sBenderRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, ItemStack aInput2, int aEUt, int aDuration, ItemStack aOutput1) { - this( - true, - aInput2 == null ? new ItemStack[] { aInput1 } : new ItemStack[] { aInput1, aInput2 }, - new ItemStack[] { aOutput1 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - Math.max(aEUt, 1), - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sAlloySmelterRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, int aEUt, ItemStack aInput2, int aDuration, ItemStack aOutput1, - ItemStack aOutput2) { - this( - true, - aInput2 == null ? new ItemStack[] { aInput1 } : new ItemStack[] { aInput1, aInput2 }, - new ItemStack[] { aOutput1, aOutput2 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - Math.max(aEUt, 1), - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sCannerRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, int aDuration) { - this( - true, - new ItemStack[] { aInput1 }, - new ItemStack[] { aOutput1 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - 120, - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sVacuumRecipes.addRecipe(this); - } - } - - public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, int aDuration, int aEUt, int VACUUM) { - this( - true, - new ItemStack[] { aInput1 }, - new ItemStack[] { aOutput1 }, - null, - null, - null, - null, - Math.max(aDuration, 1), - aEUt, - 0); - if (mInputs.length > 0 && mOutputs[0] != null) { - GT_Recipe_Map.sVacuumRecipes.addRecipe(this); - } - } - - public GT_Recipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt) { - this( - false, - null, - null, - null, - null, - new FluidStack[] { aInput1 }, - new FluidStack[] { aOutput1 }, - Math.max(aDuration, 1), - aEUt, - 0); - if (mFluidInputs.length > 0 && mFluidOutputs[0] != null) { - GT_Recipe_Map.sVacuumRecipes.addRecipe(this); - } - } - // Dummy GT_Recipe maker... public GT_Recipe(ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { @@ -561,15 +286,17 @@ public class GT_Recipe implements Comparable { aSpecialValue); } + /** + * Re-unificates all the items present in recipes. + */ public static void reInit() { GT_Log.out.println("GT_Mod: Re-Unificating Recipes."); - for (GT_Recipe_Map tMapEntry : GT_Recipe_Map.sMappings) tMapEntry.reInit(); + for (RecipeMap map : RecipeMap.ALL_RECIPE_MAPS.values()) { + map.getBackend() + .reInit(); + } } - // ----- - // Old Constructors, do not use! - // ----- - public ItemStack getRepresentativeInput(int aIndex) { if (aIndex < 0 || aIndex >= mInputs.length) return null; return GT_Utility.copyOrNull(mInputs[aIndex]); @@ -580,16 +307,14 @@ public class GT_Recipe implements Comparable { return GT_Utility.copyOrNull(mOutputs[aIndex]); } - /*** + /** * Dictates the ItemStacks displayed in the output slots of any NEI page handled by the default GT NEI handler. * Override to make shown items differ from a GT_Recipe's item output array * * @see gregtech.nei.GT_NEI_DefaultHandler * @param i Slot index * @return ItemStack to be displayed in the slot - * */ - // public ItemStack getRepresentativeOutput(int i) { return getOutput(i); } @@ -851,59 +576,100 @@ public class GT_Recipe implements Comparable { /** * Sets description shown on NEI.
* If you have a large number of recipes for the recipemap, this is not efficient memory wise, so use - * {@link GT_Recipe_Map#setNEISpecialInfoFormatter} instead. + * {@link gregtech.api.recipe.RecipeMapBuilder#neiSpecialInfoFormatter} instead. */ - protected void setNeiDesc(String... neiDesc) { + public void setNeiDesc(String... neiDesc) { this.neiDesc = neiDesc; } + // region metadata + + // Don't try implementing setMetadata, as metadataStorage can be EmptyRecipeMetadataStorage + + /** + * Gets metadata associated with this recipe. Can return null. Use + * {@link #getMetadataOrDefault(RecipeMetadataKey, Object)} + * if you want to specify default value. + */ + @Nullable + public T getMetadata(RecipeMetadataKey key) { + return key.cast(metadataStorage.getMetadata(key)); + } + /** - * Use {@link GT_Recipe_Map#getItemInputPositions} or {@link GT_Recipe_Map#getSpecialItemPosition} or - * {@link GT_Recipe_Map#getFluidInputPositions} instead + * Gets metadata associated with this recipe with default value. Does not return null unless default value is null. */ - @SuppressWarnings("DeprecatedIsStillUsed") - @Deprecated - public ArrayList getInputPositionedStacks() { - return null; + @Contract("_, !null -> !null") + @Nullable + public T getMetadataOrDefault(RecipeMetadataKey key, @Nullable T defaultValue) { + return key.cast(metadataStorage.getMetadataOrDefault(key, defaultValue)); + } + + @Nonnull + public IRecipeMetadataStorage getMetadataStorage() { + return metadataStorage; + } + + // endregion + + public RecipeCategory getRecipeCategory() { + return recipeCategory; } /** - * Use {@link GT_Recipe_Map#getItemOutputPositions} or {@link GT_Recipe_Map#getFluidOutputPositions} instead + * Exists only for recipe copying from external. For ordinal use case, use {@link GT_RecipeBuilder#recipeCategory}. */ - @SuppressWarnings("DeprecatedIsStillUsed") - @Deprecated - public ArrayList getOutputPositionedStacks() { - return null; + public void setRecipeCategory(RecipeCategory recipeCategory) { + this.recipeCategory = recipeCategory; } + private static final List excludedStacktraces = Arrays.asList( + "java.lang.Thread", + "gregtech.api.interfaces.IRecipeMap", + "gregtech.api.interfaces.IRecipeMap$1", + "gregtech.api.recipe.RecipeMap", + "gregtech.api.recipe.RecipeMapBackend", + "gregtech.api.recipe.RecipeMapBackendPropertiesBuilder", + "gregtech.api.util.GT_Recipe", + "gregtech.api.util.GT_RecipeBuilder", + "gregtech.api.util.GT_RecipeConstants", + "gregtech.api.util.GT_RecipeMapUtil", + "gregtech.common.GT_RecipeAdder"); + public void reloadOwner() { setOwner( Loader.instance() .activeModContainer()); - final List excludedClasses = Arrays.asList( - "java.lang.Thread", - "gregtech.api.util.GT_Recipe", - "gregtech.api.util.GT_RecipeBuilder", - "gregtech.api.util.GT_Recipe$GT_Recipe_Map", - "gregtech.common.GT_RecipeAdder"); if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace) { - List toAdd = new ArrayList<>(); + List toAdd = new ArrayList<>(); for (StackTraceElement stackTrace : Thread.currentThread() .getStackTrace()) { - if (excludedClasses.stream() + if (excludedStacktraces.stream() .noneMatch( c -> stackTrace.getClassName() .equals(c))) { - toAdd.add(stackTrace); + toAdd.add(formatStackTrace(stackTrace)); } } stackTraces.add(toAdd); } } + private static String formatStackTrace(StackTraceElement stackTraceElement) { + String raw = stackTraceElement.toString(); + int startParen = raw.lastIndexOf('('); + int colon = raw.lastIndexOf(':'); + if (colon == -1) { + // native or unknown source + return raw; + } + // strip class name and leave line number, as class name is already shown + return raw.substring(0, startParen + 1) + raw.substring(colon); + } + public void setOwner(ModContainer newOwner) { - ModContainer oldOwner = owners.size() > 0 ? this.owners.get(owners.size() - 1) : null; + ModContainer oldOwner = !owners.isEmpty() ? this.owners.get(owners.size() - 1) : null; if (newOwner != null && newOwner != oldOwner) { owners.add(newOwner); } @@ -1144,5181 +910,57 @@ public class GT_Recipe implements Comparable { } } - @SuppressWarnings("StaticInitializerReferencesSubClass") - public static class GT_Recipe_Map implements IGT_RecipeMap { + public static class GT_Recipe_WithAlt extends GT_Recipe { + + ItemStack[][] mOreDictAlt; /** - * Contains all Recipe Maps - */ - public static final Collection sMappings = new ArrayList<>(); - /** - * All recipe maps indexed by their {@link #mUniqueIdentifier}. + * Only for {@link GT_RecipeBuilder}. */ - public static final Map sIndexedMappings = new HashMap<>(); + GT_Recipe_WithAlt(ItemStack[] mInputs, ItemStack[] mOutputs, FluidStack[] mFluidInputs, + FluidStack[] mFluidOutputs, int[] mChances, Object mSpecialItems, int mDuration, int mEUt, + int mSpecialValue, boolean mEnabled, boolean mHidden, boolean mFakeRecipe, boolean mCanBeBuffered, + boolean mNeedsEmptyOutput, boolean nbtSensitive, String[] neiDesc, + @Nullable IRecipeMetadataStorage metadataStorage, RecipeCategory recipeCategory, + ItemStack[][] mOreDictAlt) { + super( + mInputs, + mOutputs, + mFluidInputs, + mFluidOutputs, + mChances, + mSpecialItems, + mDuration, + mEUt, + mSpecialValue, + mEnabled, + mHidden, + mFakeRecipe, + mCanBeBuffered, + mNeedsEmptyOutput, + nbtSensitive, + neiDesc, + metadataStorage, + recipeCategory); + this.mOreDictAlt = mOreDictAlt; + } - static final String TEXTURES_GUI_BASICMACHINES = "textures/gui/basicmachines"; - public static final GT_Recipe_Map sOreWasherRecipes = new GT_Recipe_Map( - new HashSet<>(500), - "gt.recipe.orewasher", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "OreWasher"), - 1, - 3, - 1, - 1, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) - .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) - .setRecipeConfigFile("orewasher", FIRST_ITEM_INPUT) - .setProgressBar(GT_UITextures.PROGRESSBAR_BATH, ProgressBar.Direction.CIRCULAR_CW); - public static final GT_Recipe_Map sThermalCentrifugeRecipes = new GT_Recipe_Map( - new HashSet<>(1000), - "gt.recipe.thermalcentrifuge", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "ThermalCentrifuge"), - 1, - 3, - 1, - 0, - 2, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) - .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) - .setRecipeConfigFile("thermalcentrifuge", FIRST_ITEM_INPUT) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - public static final GT_Recipe_Map sCompressorRecipes = new GT_Recipe_Map( - new HashSet<>(750), - "gt.recipe.compressor", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Compressor"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_COMPRESSOR) - .setRecipeConfigFile("compressor", FIRST_ITEM_INPUT) - .setProgressBar(GT_UITextures.PROGRESSBAR_COMPRESS, ProgressBar.Direction.RIGHT) - .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_COMPRESSOR_STEAM) - .setProgressBarSteam(GT_UITextures.PROGRESSBAR_COMPRESS_STEAM); - public static final GT_Recipe_Map sExtractorRecipes = new GT_Recipe_Map( - new HashSet<>(250), - "gt.recipe.extractor", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Extractor"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE) - .setRecipeConfigFile("extractor", FIRST_ITEM_INPUT) - .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT) - .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE_STEAM) - .setProgressBarSteam(GT_UITextures.PROGRESSBAR_EXTRACT_STEAM); - public static final GT_Recipe_Map sRecyclerRecipes = new GT_Recipe_Map_Recycler( - new HashSet<>(0), - "ic.recipe.recycler", - null, - "ic2.recycler", - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Recycler"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_RECYCLE) - .setProgressBar(GT_UITextures.PROGRESSBAR_RECYCLE, ProgressBar.Direction.CIRCULAR_CW); - public static final GT_Recipe_Map sFurnaceRecipes = new GT_Recipe_Map_Furnace( - new HashSet<>(0), - "mc.recipe.furnace", - "Furnace", - "smelting", - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "E_Furnace"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_FURNACE) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) - .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_FURNACE_STEAM) - .setProgressBarSteam(GT_UITextures.PROGRESSBAR_ARROW_STEAM); - public static final GT_Recipe_Map sMicrowaveRecipes = new GT_Recipe_Map_Microwave( - new HashSet<>(0), - "gt.recipe.microwave", - null, - "smelting", - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "E_Furnace"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_FURNACE) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - - public static final GT_Recipe_Map sScannerFakeRecipes = new GT_Recipe_Map( - new HashSet<>(300), - "gt.recipe.scanner", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Scanner"), - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_MICROSCOPE) - .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map( - new HashSet<>(200), - "gt.recipe.rockbreaker", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "RockBreaker"), - 2, - 1, - 0, - 0, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_DUST) - .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) - .setProgressBar(GT_UITextures.PROGRESSBAR_MACERATE, ProgressBar.Direction.RIGHT); - @Deprecated - public static final GT_Recipe_Map sByProductList = new GT_Recipe_Map( - new HashSet<>(1000), - "gt.recipe.byproductlist", - "Ore Byproduct List", - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Default"), - 1, - 6, - 1, - 0, - 1, - E, - 1, - E, - true, - false).setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - public static final GT_Recipe_Map sReplicatorFakeRecipes = new ReplicatorFakeMap( - new HashSet<>(100), - "gt.recipe.replicator", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "Replicator"), - 0, - 1, - 0, - 1, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) - .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_UUM) - .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - public static final GT_Recipe_Map sAssemblylineVisualRecipes = new GT_Recipe_Map_AssemblyLineFake( - new HashSet<>(110), - "gt.recipe.fakeAssemblylineProcess", - "Assemblyline Process", - null, - GregTech.getResourcePath("textures", "gui", "FakeAssemblyline"), - 16, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true).setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) - .setUsualFluidInputCount(4) - .setDisableOptimize(true); - /** - * Usually, but not always, you should use {@link GT_RecipeConstants#UniversalArcFurnace} instead. - */ - public static final GT_Recipe_Map sPlasmaArcFurnaceRecipes = new GT_Recipe_Map( - new HashSet<>(20000), - "gt.recipe.plasmaarcfurnace", - null, - null, - GregTech.getResourcePath(TEXTURES_GUI_BASICMACHINES, "PlasmaArcFurnace"), - 1, - 9, - 1, - 1, - 1, - E, - 1, - E,