diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-09-08 20:35:09 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-09-08 20:35:09 +1000 |
commit | 4fd354bed6a53a9319392b5a300cb8aa77cacb34 (patch) | |
tree | fda4a7c35a801ab52f67ed078250683cac876eae /src/Java/gregtech/api/util | |
parent | d37252418e361dc154fa33156755ec35dfc0c331 (diff) | |
download | GT5-Unofficial-4fd354bed6a53a9319392b5a300cb8aa77cacb34.tar.gz GT5-Unofficial-4fd354bed6a53a9319392b5a300cb8aa77cacb34.tar.bz2 GT5-Unofficial-4fd354bed6a53a9319392b5a300cb8aa77cacb34.zip |
$ Improved multiblock recipe handling.
Diffstat (limited to 'src/Java/gregtech/api/util')
-rw-r--r-- | src/Java/gregtech/api/util/CustomRecipeMap.java | 29 | ||||
-rw-r--r-- | src/Java/gregtech/api/util/MultiblockRecipeMapHandler.java | 194 |
2 files changed, 221 insertions, 2 deletions
diff --git a/src/Java/gregtech/api/util/CustomRecipeMap.java b/src/Java/gregtech/api/util/CustomRecipeMap.java index 3a0f1724b0..d01beb1486 100644 --- a/src/Java/gregtech/api/util/CustomRecipeMap.java +++ b/src/Java/gregtech/api/util/CustomRecipeMap.java @@ -22,6 +22,14 @@ public class CustomRecipeMap/* extends GT_Recipe_Map*/{ //Fission Fuel Plant Recipes public static final CustomRecipeMap sFissionFuelProcessing = new CustomRecipeMap(new HashSet<GT_Recipe>(50), "gt.recipe.fissionfuel", "Fission Fuel Processing", null, RES_PATH_GUI + "basicmachines/FissionFuel", 0, 0, 0, 4, 1, E, 1, E, true, true); + + public static final CustomRecipeMap mMultiWireMill = new CustomRecipeMap(new HashSet<GT_Recipe>(500), "gt.recipe.multi.wiremill", "Multiblock Wiremill", null, RES_PATH_GUI + "basicmachines/FissionFuel", 1, 1, 0, 0, 1, E, 1, E, true, true); + public static final CustomRecipeMap mMultiMacerator = new CustomRecipeMap(new HashSet<GT_Recipe>(500), "gt.recipe.multi.macerator", "Maceration Stack", null, RES_PATH_GUI + "basicmachines/FissionFuel", 1, 3, 0, 0, 1, E, 1, E, true, true); + public static final CustomRecipeMap mMultiCentrifuge = new CustomRecipeMap(new HashSet<GT_Recipe>(500), "gt.recipe.multi.centrifuge", "Multiblock Centrifuge", null, RES_PATH_GUI + "basicmachines/FissionFuel", 2, 6, 0, 0, 1, E, 1, E, true, true); + public static final CustomRecipeMap mMultiElectrolyzer = new CustomRecipeMap(new HashSet<GT_Recipe>(500), "gt.recipe.multi.electrolyzer", "Multiblock Electrolyzer", null, RES_PATH_GUI + "basicmachines/FissionFuel", 2, 6, 0, 0, 1, E, 1, E, true, true); + + + /** * HashMap of Recipes based on their Items */ @@ -101,7 +109,7 @@ public class CustomRecipeMap/* extends GT_Recipe_Map*/{ return this.addRecipe(aRecipe, true, false, false); } - protected GT_Recipe addRecipe(final GT_Recipe aRecipe, final boolean aCheckForCollisions, final boolean aFakeRecipe, final boolean aHidden) { + public GT_Recipe addRecipe(final GT_Recipe aRecipe, final boolean aCheckForCollisions, final boolean aFakeRecipe, final boolean aHidden) { aRecipe.mHidden = aHidden; aRecipe.mFakeRecipe = aFakeRecipe; if ((aRecipe.mFluidInputs.length < this.mMinimalInputFluids) && (aRecipe.mInputs.length < this.mMinimalInputItems)) { @@ -255,27 +263,38 @@ public class CustomRecipeMap/* extends GT_Recipe_Map*/{ // 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)) { + Utils.LOG_INFO("BAD RECIPE [a]"); return aRecipe.mEnabled && ((aVoltage * this.mAmperage) >= aRecipe.mEUt) ? aRecipe : null; } } // Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items. if ((this.mUsualInputCount > 0) && (aInputs != null)) { + Utils.LOG_INFO("BAD RECIPE [b0]"); for (final ItemStack tStack : aInputs) { + Utils.LOG_INFO("BAD RECIPE [b1]"); if (tStack != null) { + Utils.LOG_INFO("BAD RECIPE [b2] | "+tStack.getDisplayName()); Collection<GT_Recipe> tRecipes = this.mRecipeItemMap.get(new GT_ItemStack(tStack)); if (tRecipes != null) { + Utils.LOG_INFO("BAD RECIPE [b3]"); for (final GT_Recipe tRecipe : tRecipes) { + Utils.LOG_INFO("BAD RECIPE [b4]"); if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) { + Utils.LOG_INFO("BAD RECIPE [b5]"); return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null; } } } + Utils.LOG_INFO("BAD RECIPE [b6]"); tRecipes = this.mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, tStack))); if (tRecipes != null) { + Utils.LOG_INFO("BAD RECIPE [b7]"); for (final GT_Recipe tRecipe : tRecipes) { + Utils.LOG_INFO("BAD RECIPE [b8]"); if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) { + Utils.LOG_INFO("BAD RECIPE [b9]"); return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null; } } @@ -285,14 +304,20 @@ public class CustomRecipeMap/* extends GT_Recipe_Map*/{ } // 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 ((this.mMinimalInputItems == 0) && (aFluids != null)) { + if ((this.mMinimalInputItems == 0) && (aFluids != null && aFluids.length > 0)) { + Utils.LOG_INFO("BAD RECIPE [c0] "+aFluids.length); for (final FluidStack aFluid : aFluids) { + Utils.LOG_INFO("BAD RECIPE [c1]"); if (aFluid != null) { + Utils.LOG_INFO("BAD RECIPE [c2]"); final Collection<GT_Recipe> tRecipes = this.mRecipeFluidMap.get(aFluid.getFluid()); if (tRecipes != null) { + Utils.LOG_INFO("BAD RECIPE [c3]"); for (final GT_Recipe tRecipe : tRecipes) { + Utils.LOG_INFO("BAD RECIPE [c4]"); if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) { + Utils.LOG_INFO("BAD RECIPE [c5]"); return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null; } } diff --git a/src/Java/gregtech/api/util/MultiblockRecipeMapHandler.java b/src/Java/gregtech/api/util/MultiblockRecipeMapHandler.java new file mode 100644 index 0000000000..143f465233 --- /dev/null +++ b/src/Java/gregtech/api/util/MultiblockRecipeMapHandler.java @@ -0,0 +1,194 @@ +package gregtech.api.util; + +import java.util.ArrayList; +import java.util.Collection; + +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +public class MultiblockRecipeMapHandler{ + + public static void run() { + + if(CORE.configSwitches.enableMultiblock_IndustrialElectrolyzer){ + generateSimpleMultimachineRecipeMap(GT_Recipe.GT_Recipe_Map.sElectrolyzerRecipes, CustomRecipeMap.mMultiElectrolyzer); + } + if(CORE.configSwitches.enableMultiblock_IndustrialCentrifuge){ + generateSimpleMultimachineRecipeMap(GT_Recipe.GT_Recipe_Map.sCentrifugeRecipes, CustomRecipeMap.mMultiCentrifuge); + } + if(CORE.configSwitches.enableMultiblock_IndustrialMacerationStack){ + generateSimpleMultimachineRecipeMap(GT_Recipe.GT_Recipe_Map.sMaceratorRecipes, CustomRecipeMap.mMultiMacerator); + } + if(CORE.configSwitches.enableMultiblock_IndustrialWireMill){ + generateSimpleMultimachineRecipeMap(GT_Recipe.GT_Recipe_Map.sWiremillRecipes, CustomRecipeMap.mMultiWireMill); + } + + } + + + + + + + + + + + + + + + + + + + + + + + + public static boolean isCell(ItemStack cell) { + if (cell == null){ + return false; + } + if (cell.getDisplayName().toLowerCase().contains("cell") + || cell.getUnlocalizedName().toLowerCase().contains("cell") + || FluidContainerRegistry.isFilledContainer(cell)) { + if (cell.getDisplayName().toLowerCase().contains("plasma") + || cell.getUnlocalizedName().toLowerCase().contains("plasma")) { + return false; + } + return true; + } + return false; + } + + public static boolean isCellEmpty(ItemStack cell){ + if (cell.getDisplayName().toLowerCase().contains("empty") + || cell.getUnlocalizedName().toLowerCase().contains("empty") + ) { + return true; + } + return false; + } + + private static ItemStack[] copyItemElements(ItemStack[] items){ + int inputCount = 0; + ItemStack[] item = new ItemStack[9]; + for (ItemStack input : items) { + if (!isCell(input)){ + item[inputCount] = input; + inputCount++; + } + } + return item; + } + + private static ItemStack[] copyItemElementsWithCells(ItemStack[] items){ + int inputCount = 0; + ItemStack[] item = new ItemStack[9]; + for (ItemStack input : items) { + item[inputCount] = input; + inputCount++; + } + return item; + } + + private static FluidStack[] copyFluidElements(FluidStack[] fluids){ + FluidStack fluid[] = new FluidStack[9]; + for (int r = 0; r<fluids.length;r++){ + fluid[r] = fluids[r]; + } + return fluid; + } + + private static FluidStack[] addRemovedCellsToArray(ItemStack[] items, FluidStack[] fluids){ + ArrayList<FluidStack> fluidInputs = new ArrayList<FluidStack>(); + + for (FluidStack fluid : fluids){ + fluidInputs.add(fluid); + } + + for (ItemStack input : items) { + if (input != null){ + if (isCell(input) && !isCellEmpty(input)){ + FluidStack cellFluid = FluidContainerRegistry.getFluidForFilledItem(input); + if (cellFluid != null){ + cellFluid.amount = 1000; + fluidInputs.add(cellFluid); + } + } + } + } + FluidStack[] returnArray = new FluidStack[fluidInputs.size()]; + for (int h=0;h<fluidInputs.size();h++){ + returnArray[h] = fluidInputs.get(h); + } + return returnArray; + } + + private static void generateSimpleMultimachineRecipeMap(GT_Recipe_Map inputMap, CustomRecipeMap newMap) { + GT_Recipe_Map r = inputMap; + final Collection<GT_Recipe> x = r.mRecipeList; + for (final GT_Recipe newBo : x) { + int duration = MathUtils.findPercentageOfInt(newBo.mDuration, 80); + if (newMap.addRecipe(new GT_Recipe(true, newBo.mInputs, newBo.mOutputs, newBo.mSpecialItems, newBo.mChances, newBo.mFluidInputs, newBo.mFluidOutputs, duration, newBo.mEUt, newBo.mSpecialValue), false, true, true) != null){ + Utils.LOG_INFO("Successfully added a simple recipe to the "+newMap.mNEIName+" map."); + } + else { + Utils.LOG_INFO("Failed adding a simple recipe to the "+newMap.mNEIName+" map."); + } + } + } + + private static void generateMultimachineRecipeMap(GT_Recipe_Map inputMap, CustomRecipeMap newMap) { + GT_Recipe_Map r = inputMap; + final Collection<GT_Recipe> x = r.mRecipeList; + for (final GT_Recipe newBo : x) { + ItemStack[] mInputs = copyItemElementsWithCells(newBo.mInputs); + ItemStack[] mOutputs = copyItemElementsWithCells(newBo.mOutputs); + FluidStack[] mFluidInputs = copyFluidElements(newBo.mFluidInputs); + FluidStack[] mFluidOutputs = copyFluidElements(newBo.mFluidOutputs); + int duration = MathUtils.findPercentageOfInt(newBo.mDuration, 80); + + //Change bonus chances + int[] outputChances = null; + if (newBo.mChances != null){ + outputChances = newBo.mChances.clone(); + for (int g=0;g<outputChances.length;g++){ + Utils.LOG_WARNING("Output["+g+"] chance = "+outputChances[g]); + if (outputChances[g]<10000){ + int temp = outputChances[g]; + if (outputChances[g] < 8000 && outputChances[g] >= 1){ + outputChances[g] = temp+600; + Utils.LOG_WARNING("Output["+g+"] chance now = "+outputChances[g]); + } + else if (outputChances[g] < 9000 && outputChances[g] >= 8000){ + outputChances[g] = temp+200; + Utils.LOG_WARNING("Output["+g+"] chance now = "+outputChances[g]); + } + else if (outputChances[g] <= 9900 && outputChances[g] >= 9000){ + outputChances[g] = temp+100; + Utils.LOG_WARNING("Output["+g+"] chance now = "+outputChances[g]); + } + } + } + } + if (newMap.addRecipe(new GT_Recipe(true, mInputs, mOutputs, newBo.mSpecialItems, outputChances, mFluidInputs, mFluidOutputs, duration, newBo.mEUt, newBo.mSpecialValue), false, true, true) != null){ + Utils.LOG_INFO("Successfully added a recipe to the "+newMap.mNEIName+" map."); + } + else { + Utils.LOG_INFO("Failed adding a recipe to the "+newMap.mNEIName+" map."); + } + } + } + + + +} |