diff options
author | Jordan Byrne <draknyte1@hotmail.com> | 2018-03-28 21:54:34 +1000 |
---|---|---|
committer | Jordan Byrne <draknyte1@hotmail.com> | 2018-03-28 21:54:34 +1000 |
commit | 634ba57d8239096e36ef23d62c52763e442c2375 (patch) | |
tree | b927b6ec21d475ca6e8ce01696955617eae35ca7 /src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java | |
parent | dfabbe2c18c26725cb03b01746868f087e022732 (diff) | |
download | GT5-Unofficial-634ba57d8239096e36ef23d62c52763e442c2375.tar.gz GT5-Unofficial-634ba57d8239096e36ef23d62c52763e442c2375.tar.bz2 GT5-Unofficial-634ba57d8239096e36ef23d62c52763e442c2375.zip |
$ Rewrote handling for the ABS to dynamically generate all recipes based on all pre-existing EBF recipes.
$ Rewrote ABS recipe handler to support temps within the recipes. This will allow coil upgrades like the EBF for higher tier smelting.
$ Fix Polonium Material trying to access ELEMENT.java instance before it's created.
+ Added ItemStackData.java, which allows storing ItemStacks for easy retrieval.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java new file mode 100644 index 0000000000..3001306d9e --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_GTNH.java @@ -0,0 +1,215 @@ +package gtPlusPlus.xmod.gregtech.loaders; + +import gregtech.api.util.*; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.ItemStackData; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.HashMap; +import java.util.Map; + +public class RecipeGen_BlastSmelterGT_GTNH { + + private static Map<String, FluidStack> mCachedIngotToFluidRegistry = new HashMap<String, FluidStack>(); + private static Map<String, String> mCachedHotToColdRegistry = new HashMap<String, String>(); + + private synchronized static void setIngotToFluid(final ItemStackData stack, final FluidStack fluid) { + if (stack != null && fluid != null) { + mCachedIngotToFluidRegistry.put(stack.getUniqueDataIdentifier(), fluid); + } + } + + private synchronized static void setHotToCold(final ItemStackData hot, final ItemStackData cold) { + if (hot != null && cold != null) { + mCachedHotToColdRegistry.put(hot.getUniqueDataIdentifier(), cold.getUniqueDataIdentifier()); + } + } + + private synchronized static FluidStack getFluidFromIngot(final ItemStackData ingot) { + ItemStackData h = ingot; + if (mCachedIngotToFluidRegistry.containsKey(h.getUniqueDataIdentifier())) { + Logger.INFO("[ABS] mCachedIngotToFluidRegistry contains Output Ingot."); + return mCachedIngotToFluidRegistry.get(h.getUniqueDataIdentifier()); + } + if (mCachedHotToColdRegistry.containsKey(h.getUniqueDataIdentifier())) { + Logger.INFO("[ABS] mCachedHotToColdRegistry contains Output Ingot."); + return mCachedIngotToFluidRegistry.get(mCachedHotToColdRegistry.get(h.getUniqueDataIdentifier())); + } + Logger.INFO("[ABS] Neither Cache contains Output Ingot."); + return null; + } + + private static boolean isValid(final ItemStack[] inputs, final ItemStack outputs[], final FluidStack[] fluidIn, final FluidStack fluidOut) { + if (inputs != null && outputs != null && fluidIn != null && fluidOut != null && inputs.length > 0 && outputs.length > 0) { + return true; + } + return false; + } + + public synchronized static boolean generateGTNHBlastSmelterRecipesFromEBFList() { + + //Make a counting object + int mSuccess = 0; + + Logger.INFO("[ABS] Starting recipe generation based on EBF recipe map."); + Logger.INFO("[ABS] Caching Ingots and their Molten fluid.."); + //First, we make sure that we have a valid recipe map of Ingots/Dusts -> Fluids + if (GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes.mRecipeList.size() > 0) { + //So, let's check every recipe + for (GT_Recipe x : GT_Recipe.GT_Recipe_Map.sFluidExtractionRecipes.mRecipeList) { + ItemStack validInput = null; + FluidStack validOutput = null; + //If we the input is an ingot and it and the output are valid, map it to cache. + if (x.mInputs[0] != null) { + for(int tag: OreDictionary.getOreIDs(x.mInputs[0])) { + String oreName = OreDictionary.getOreName(tag).toLowerCase(); + String mType = "dust"; + if (CORE.GTNH) { + mType = "ingot"; + } + if(oreName.startsWith(mType) && !oreName.contains("double") && !oreName.contains("triple") && !oreName.contains("quad") && !oreName.contains("quintuple")) { + validInput = x.mInputs[0]; + } + } + } + if (x.mFluidOutputs[0] != null) { + validOutput = x.mFluidOutputs[0]; + } + if (validInput != null && validOutput != null) { + ItemStackData R = new ItemStackData(validInput); + setIngotToFluid(R, validOutput); + Logger.INFO("[ABS][I2F] Cached "+validInput.getDisplayName()+" to "+validOutput.getLocalizedName()+". Stored Under ID of "+R.getUniqueDataIdentifier()); + } + } + } + + Logger.INFO("[ABS] Caching Ingots and their Hot form..."); + //Second, we make sure that we have a valid recipe map of Hot Ingots -> Cold Ingots + if (GT_Recipe.GT_Recipe_Map.sVacuumRecipes.mRecipeList.size() > 0) { + //So, let's check every recipe + for (GT_Recipe x : GT_Recipe.GT_Recipe_Map.sVacuumRecipes.mRecipeList) { + ItemStack validInput = null; + ItemStack validOutput = null; + //If we the input is an ingot and it and the output are valid, map it to cache. + if (x.mInputs[0] != null) { + validInput = x.mInputs[0]; + } + if (x.mOutputs[0] != null) { + validOutput = x.mOutputs[0]; + } + if (validInput != null && validOutput != null) { + ItemStackData R1 = new ItemStackData(validInput); + ItemStackData R2 = new ItemStackData(validOutput); + setHotToCold(R1, R2); + Logger.INFO("[ABS][H2C] Cached "+validInput.getDisplayName()+" to "+validOutput.getDisplayName()+". Stored Under ID of "+R1.getUniqueDataIdentifier()+", links to ID "+R2.getUniqueDataIdentifier()); + } + } + } + + Logger.INFO("[ABS] Generating recipes based on existing EBF recipes."); + //Okay, so now lets Iterate existing EBF recipes. + if (GT_Recipe.GT_Recipe_Map.sBlastRecipes.mRecipeList.size() > 0) { + for (GT_Recipe x : GT_Recipe.GT_Recipe_Map.sBlastRecipes.mRecipeList) { + if (x == null) { + continue; + } + ItemStack[] inputs, outputs; + FluidStack[] inputsF; + int voltage, time, special; + boolean enabled; + inputs = x.mInputs; + outputs = x.mOutputs; + inputsF = x.mFluidInputs; + voltage = x.mEUt; + time = x.mDuration; + enabled = x.mEnabled; + special = x.mSpecialValue; + + //Check for GTNH, if it's found, continue to next recipe if the Temp is too high. + if (CORE.GTNH && special > 3600) { + Logger.INFO("[ABS] Skipping ABS addition for GTNH due to temp."); + continue; + } + else { + FluidStack mMoltenStack = null; + int mMoltenCount = 0; + //If We have a valid Output, let's try use our cached data to get it's molten form. + if (x.mOutputs != null && x.mOutputs[0] != null) { + mMoltenCount = x.mOutputs[0].stackSize; + ItemStackData R = new ItemStackData(x.mOutputs[0]); + Logger.INFO("[ABS] Found "+x.mOutputs[0].getDisplayName()+" as valid EBF output, finding it's fluid from the cache. We will require "+(144*mMoltenCount)+"L. Looking for ID "+R.getUniqueDataIdentifier()); + FluidStack tempFluid = getFluidFromIngot(R); + if (tempFluid != null) { + //Logger.INFO("[ABS] Got Fluid from Cache."); + mMoltenStack = FluidUtils.getFluidStack(tempFluid, mMoltenCount*144); + } + else { + Logger.INFO("[ABS] Failed to get Fluid from Cache."); + } + } + //If this recipe is enabled and we have a valid molten fluidstack, let's try add this recipe. + if (enabled && isValid(inputs, outputs, inputsF, mMoltenStack)) { + //Build correct input stack + ItemStack[] newInput = new ItemStack[inputs.length+1]; + int l = 1; + for (ItemStack y : inputs) { + newInput[l++] = y; + } + newInput[0] = CI.getNumberedCircuit(inputs.length); + //Logger.INFO("[ABS] Generating ABS recipe for "+mMoltenStack.getLocalizedName()+"."); + if (CORE.RA.addBlastSmelterRecipe(newInput, (inputsF.length > 0 ? inputsF[0] : null), mMoltenStack, 100, MathUtils.roundToClosestInt(time*0.8), voltage, special)) { + //Logger.INFO("[ABS] Success."); + mSuccess++; + } + else { + Logger.INFO("[ABS] Failure."); + } + } + else { + if (!enabled) { + Logger.INFO("[ABS] Failure. EBF recipe was not enabled."); + } + else { + Logger.INFO("[ABS] Failure. Invalid Inputs or Outputs."); + if (inputs == null) { + Logger.INFO("[ABS] Inputs were not Valid."); + } + else { + Logger.INFO("[ABS] inputs size: "+inputs.length); + } + if (outputs == null) { + Logger.INFO("[ABS] Outputs were not Valid."); + } + else { + Logger.INFO("[ABS] outputs size: "+outputs.length); + } + if (inputsF == null) { + Logger.INFO("[ABS] Input Fluids were not Valid."); + } + else { + Logger.INFO("[ABS] inputsF size: "+inputsF.length); + } + if (mMoltenStack == null) { + Logger.INFO("[ABS] Output Fluid were not Valid."); + } + } + } + } + } + } + else { + Logger.INFO("[ABS] Failure. Did not find any EBF recipes to iterate."); + } + + Logger.INFO("[ABS] Processed "+mSuccess+" recipes."); + return mSuccess > 0; + } + +} |