From db83ad0447c2711c1a4cc3610cc6ebac5c91c1b4 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Sat, 31 Dec 2016 18:45:41 +1000 Subject: + Gave Fission Fuels their own NEI handler, which allows 9 input fluids. % Moved Fission Fuel recipe map to it's own class, specially for the NEI handler. ^ Updated CodeChickenCore-1.7.10-1.0.6.44-dev.jar to CodeChickenCore-1.7.10-1.0.7.47-dev.jar. ^ Updated CodeChickenLib-1.7.10-1.1.3.136-dev.jar to CodeChickenLib-1.7.10-1.1.3.140-dev.jar. ^ Updated NotEnoughItems-1.7.10-1.0.4.107-dev.jar to NotEnoughItems-1.7.10-1.0.5.120-dev.jar. --- src/Java/gregtech/api/util/CustomRecipeMap.java | 263 ++++++++++++++++++++++++ src/Java/gregtech/api/util/Recipe_GT.java | 20 +- 2 files changed, 277 insertions(+), 6 deletions(-) create mode 100644 src/Java/gregtech/api/util/CustomRecipeMap.java (limited to 'src/Java/gregtech/api/util') diff --git a/src/Java/gregtech/api/util/CustomRecipeMap.java b/src/Java/gregtech/api/util/CustomRecipeMap.java new file mode 100644 index 0000000000..3434239ca7 --- /dev/null +++ b/src/Java/gregtech/api/util/CustomRecipeMap.java @@ -0,0 +1,263 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.*; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; +import gregtech.api.objects.GT_ItemStack; + +import java.util.*; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +public class CustomRecipeMap/* extends GT_Recipe_Map*/{ + /** + * Contains all Recipe Maps + */ + public static final Collection sMappings = new ArrayList(); + + //public static final CustomRecipeMap sOreWasherRecipes = new GT_Recipe_Map_OreWasher(new HashSet(0), "ic.recipe.orewasher", "Ore Washer", "ic2.blockOreWashingPlant", RES_PATH_GUI + "basicmachines/OreWasher", 1, 3, 1, 1, 1, E, 1, E, true, false); + //Fission Fuel Plant Recipes + public static final CustomRecipeMap sFissionFuelProcessing = new CustomRecipeMap(new HashSet(50), "gt.recipe.fissionfuel", "Fission Fuel Processing", null, RES_PATH_GUI + "basicmachines/LFTR", 0, 0, 0, 9, 1, E, 1, E, true, true); + + /** + * HashMap of Recipes based on their Items + */ + public final Map> mRecipeItemMap = new HashMap>(); + /** + * HashMap of Recipes based on their Fluids + */ + public final Map> mRecipeFluidMap = new HashMap>(); + /** + * The List of all Recipes + */ + public final Collection mRecipeList; + /** + * String used as an unlocalised Name. + */ + public final String mUnlocalizedName; + /** + * String used in NEI for the Recipe Lists. If null it will use the unlocalised Name instead + */ + public final String mNEIName; + /** + * GUI used for NEI Display. Usually the GUI of the Machine itself + */ + public final String mNEIGUIPath; + public final String mNEISpecialValuePre, mNEISpecialValuePost; + public final int mUsualInputCount, mUsualOutputCount, mNEISpecialValueMultiplier, mMinimalInputItems, mMinimalInputFluids, mAmperage; + public final boolean mNEIAllowed, mShowVoltageAmperageInNEI; + + /** + * Initialises a new type of Recipe Handler. + * + * @param aRecipeList a List you specify as Recipe List. Usually just an ArrayList with a pre-initialised Size. + * @param aUnlocalizedName the unlocalised Name of this Recipe Handler, used mainly for NEI. + * @param aLocalName the displayed Name inside the NEI Recipe GUI. + * @param aNEIGUIPath the displayed GUI Texture, usually just a Machine GUI. Auto-Attaches ".png" if forgotten. + * @param aUsualInputCount the usual amount of Input Slots this Recipe Class has. + * @param aUsualOutputCount the usual amount of Output Slots this Recipe Class has. + * @param aNEISpecialValuePre the String in front of the Special Value in NEI. + * @param aNEISpecialValueMultiplier the Value the Special Value is getting Multiplied with before displaying + * @param aNEISpecialValuePost the String after the Special Value. Usually for a Unit or something. + * @param aNEIAllowed if NEI is allowed to display this Recipe Handler in general. + */ + public CustomRecipeMap(Collection aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) { + //super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed); + sMappings.add(this); + mNEIAllowed = aNEIAllowed; + mShowVoltageAmperageInNEI = aShowVoltageAmperageInNEI; + mRecipeList = aRecipeList; + mNEIName = aNEIName == null ? aUnlocalizedName : aNEIName; + mNEIGUIPath = aNEIGUIPath.endsWith(".png") ? aNEIGUIPath : aNEIGUIPath + ".png"; + mNEISpecialValuePre = aNEISpecialValuePre; + mNEISpecialValueMultiplier = aNEISpecialValueMultiplier; + mNEISpecialValuePost = aNEISpecialValuePost; + mAmperage = aAmperage; + mUsualInputCount = aUsualInputCount; + mUsualOutputCount = aUsualOutputCount; + mMinimalInputItems = aMinimalInputItems; + mMinimalInputFluids = aMinimalInputFluids; + GregTech_API.sFluidMappings.add(mRecipeFluidMap); + GregTech_API.sItemStackMappings.add(mRecipeItemMap); + GT_LanguageManager.addStringLocalization(mUnlocalizedName = aUnlocalizedName, aLocalName); + } + + public GT_Recipe addRecipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, int[] aOutputChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + return addRecipe(new GT_Recipe(aOptimize, aInputs, aOutputs, aSpecial, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue)); + } + + public GT_Recipe addRecipe(int[] aOutputChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + return addRecipe(new GT_Recipe(false, null, null, null, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue), false, false, false); + } + + public GT_Recipe addRecipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + return addRecipe(new GT_Recipe(aOptimize, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue)); + } + + public GT_Recipe addRecipe(GT_Recipe aRecipe) { + return addRecipe(aRecipe, true, false, false); + } + + protected GT_Recipe addRecipe(GT_Recipe aRecipe, boolean aCheckForCollisions, boolean aFakeRecipe, boolean aHidden) { + aRecipe.mHidden = aHidden; + aRecipe.mFakeRecipe = aFakeRecipe; + if (aRecipe.mFluidInputs.length < mMinimalInputFluids && aRecipe.mInputs.length < mMinimalInputItems) + return null; + if (aCheckForCollisions && findRecipe(null, false, Long.MAX_VALUE, aRecipe.mFluidInputs, aRecipe.mInputs) != null) + return null; + return add(aRecipe); + } + + /** + * Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes + */ + public GT_Recipe addFakeRecipe(boolean aCheckForCollisions, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, int[] aOutputChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + return addFakeRecipe(aCheckForCollisions, new GT_Recipe(false, aInputs, aOutputs, aSpecial, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue)); + } + + /** + * Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes + */ + public GT_Recipe addFakeRecipe(boolean aCheckForCollisions, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + return addFakeRecipe(aCheckForCollisions, new GT_Recipe(false, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue)); + } + + /** + * Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes + */ + public GT_Recipe addFakeRecipe(boolean aCheckForCollisions, GT_Recipe aRecipe) { + return addRecipe(aRecipe, aCheckForCollisions, true, false); + } + + public GT_Recipe add(GT_Recipe aRecipe) { + mRecipeList.add(aRecipe); + for (FluidStack aFluid : aRecipe.mFluidInputs) + if (aFluid != null) { + Collection tList = mRecipeFluidMap.get(aFluid.getFluid()); + if (tList == null) mRecipeFluidMap.put(aFluid.getFluid(), tList = new HashSet(1)); + tList.add(aRecipe); + } + return addToItemMap(aRecipe); + } + + public void reInit() { + Map> tMap = mRecipeItemMap; + if (tMap != null) tMap.clear(); + for (GT_Recipe tRecipe : mRecipeList) { + GT_OreDictUnificator.setStackArray(true, tRecipe.mInputs); + GT_OreDictUnificator.setStackArray(true, tRecipe.mOutputs); + if (tMap != null) addToItemMap(tRecipe); + } + } + + /** + * @return if this Item is a valid Input for any for the Recipes + */ + public boolean containsInput(ItemStack aStack) { + return aStack != null && (mRecipeItemMap.containsKey(new GT_ItemStack(aStack)) || mRecipeItemMap.containsKey(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack)))); + } + + /** + * @return if this Fluid is a valid Input for any for the Recipes + */ + public boolean containsInput(FluidStack aFluid) { + return aFluid != null && containsInput(aFluid.getFluid()); + } + + /** + * @return if this Fluid is a valid Input for any for the Recipes + */ + public boolean containsInput(Fluid aFluid) { + return aFluid != null && mRecipeFluidMap.containsKey(aFluid); + } + + public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack... aInputs) { + return findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, null, aInputs); + } + + public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack... aInputs) { + return findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, null, aInputs); + } + + /** + * finds a Recipe matching the aFluid and ItemStack Inputs. + * + * @param aTileEntity an Object representing the current coordinates of the executing Block/Entity/Whatever. This may be null, especially during Startup. + * @param aRecipe in case this is != null it will try to use this Recipe first when looking things up. + * @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs + * @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage + * @param aFluids the Fluid Inputs + * @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with this, but some custom ones do. + * @param aInputs the Item Inputs + * @return the Recipe it has found or null for no matching Recipe + */ + public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) { + // No Recipes? Well, nothing to be found then. + if (mRecipeList.isEmpty()) return null; + + // Some Recipe Classes require a certain amount of Inputs of certain kinds. Like "at least 1 Fluid + 1 Stack" or "at least 2 Stacks" before they start searching for Recipes. + // This improves Performance massively, especially if people leave things like Circuits, Molds or Shapes in their Machines to select Sub Recipes. + if (GregTech_API.sPostloadFinished) { + if (mMinimalInputFluids > 0) { + if (aFluids == null) return null; + int tAmount = 0; + for (FluidStack aFluid : aFluids) if (aFluid != null) tAmount++; + if (tAmount < mMinimalInputFluids) return null; + } + if (mMinimalInputItems > 0) { + if (aInputs == null) return null; + int tAmount = 0; + for (ItemStack aInput : aInputs) if (aInput != null) tAmount++; + if (tAmount < mMinimalInputItems) return null; + } + } + + // Unification happens here in case the Input isn't already unificated. + if (aNotUnificated) aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs); + + // Check the Recipe which has been used last time in order to not have to search for it again, if possible. + if (aRecipe != null) + if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) + return aRecipe.mEnabled && aVoltage * mAmperage >= aRecipe.mEUt ? aRecipe : null; + + // Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items. + if (mUsualInputCount > 0 && aInputs != null) for (ItemStack tStack : aInputs) + if (tStack != null) { + Collection + tRecipes = mRecipeItemMap.get(new GT_ItemStack(tStack)); + if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) + if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) + return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null; + tRecipes = mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, tStack))); + if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) + if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) + return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null; + } + + // If the minimal Amount of Items for the Recipe is 0, then it could be a Fluid-Only Recipe, so check that Map too. + if (mMinimalInputItems == 0 && aFluids != null) for (FluidStack aFluid : aFluids) + if (aFluid != null) { + Collection + tRecipes = mRecipeFluidMap.get(aFluid.getFluid()); + if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) + if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) + return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null; + } + + // And nothing has been found. + return null; + } + + protected GT_Recipe addToItemMap(GT_Recipe aRecipe) { + for (ItemStack aStack : aRecipe.mInputs) + if (aStack != null) { + GT_ItemStack tStack = new GT_ItemStack(aStack); + Collection tList = mRecipeItemMap.get(tStack); + if (tList == null) mRecipeItemMap.put(tStack, tList = new HashSet(1)); + tList.add(aRecipe); + } + return aRecipe; + } + } \ No newline at end of file diff --git a/src/Java/gregtech/api/util/Recipe_GT.java b/src/Java/gregtech/api/util/Recipe_GT.java index c020b7eeb9..f0b80f084a 100644 --- a/src/Java/gregtech/api/util/Recipe_GT.java +++ b/src/Java/gregtech/api/util/Recipe_GT.java @@ -133,7 +133,7 @@ public class Recipe_GT extends GT_Recipe{ int aDuration, int aEUt) { this(true, null, null, null, null, new FluidStack[]{aInput1, aInput2, aInput3, aInput4, aInput5, aInput6, aInput7, aInput8, aInput9}, new FluidStack[]{aOutput1, aOutput2}, Math.max(aDuration, 1), aEUt, 0); if (mInputs.length > 1) { - Gregtech_Recipe_Map.sFissionFuelProcessing.addRecipe(this); + CustomRecipeMap.sFissionFuelProcessing.addRecipe(this); } } @@ -150,39 +150,47 @@ public class Recipe_GT extends GT_Recipe{ for (Gregtech_Recipe_Map tMapEntry : Gregtech_Recipe_Map.sMappings) tMapEntry.reInit(); } + @Override public ItemStack getRepresentativeInput(int aIndex) { if (aIndex < 0 || aIndex >= mInputs.length) return null; return GT_Utility.copy(mInputs[aIndex]); } - public ItemStack getOutput(int aIndex) { + @Override + public ItemStack getOutput(int aIndex) { if (aIndex < 0 || aIndex >= mOutputs.length) return null; return GT_Utility.copy(mOutputs[aIndex]); } - public int getOutputChance(int aIndex) { + @Override + public int getOutputChance(int aIndex) { if (aIndex < 0 || aIndex >= mChances.length) return 10000; return mChances[aIndex]; } - public FluidStack getRepresentativeFluidInput(int aIndex) { + @Override + public FluidStack getRepresentativeFluidInput(int aIndex) { if (aIndex < 0 || aIndex >= mFluidInputs.length || mFluidInputs[aIndex] == null) return null; return mFluidInputs[aIndex].copy(); } - public FluidStack getFluidOutput(int aIndex) { + @Override + public FluidStack getFluidOutput(int aIndex) { if (aIndex < 0 || aIndex >= mFluidOutputs.length || mFluidOutputs[aIndex] == null) return null; return mFluidOutputs[aIndex].copy(); } + @Override public GT_Recipe copy() { return this.copy(); } + @Override public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, FluidStack[] aFluidInputs, ItemStack... aInputs) { return isRecipeInputEqual(aDecreaseStacksizeBySuccess, false, aFluidInputs, aInputs); } + @Override public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) { if (mFluidInputs.length > 0 && aFluidInputs == null) return false; for (FluidStack tFluid : mFluidInputs) @@ -253,7 +261,7 @@ public class Recipe_GT extends GT_Recipe{ //LFTR recipes public static final GT_Recipe_Map sLiquidFluorineThoriumReactorRecipes = new GT_Recipe_Map(new HashSet(50), "gt.recipe.lftr", "Liquid Fluoride Thorium Reactor", null, RES_PATH_GUI + "basicmachines/LFTR", 0, 0, 0, 2, 1, "Start: ", 1, " EU", true, true); //Fission Fuel Plant Recipes - public static final GT_Recipe_Map sFissionFuelProcessing = new GT_Recipe_Map(new HashSet(50), "gt.recipe.fissionfuel", "Fission Fuel Processing", null, RES_PATH_GUI + "basicmachines/LFTR", 0, 0, 0, 9, 1, E, 1, E, true, true); + //public static final GT_Recipe_Map sFissionFuelProcessing = new GT_Recipe_Map(new HashSet(50), "gt.recipe.fissionfuel", "Fission Fuel Processing", null, RES_PATH_GUI + "basicmachines/LFTR", 0, 0, 0, 9, 1, E, 1, E, true, true); /** * HashMap of Recipes based on their Items -- cgit