diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-10-10 17:45:37 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-10-10 17:45:37 +0100 |
commit | ab84b1d95f8c4880891debc594a41f57941de78a (patch) | |
tree | c3bcdbda25cb0d45028dff77944d3e5fbff7edcd /src/Java/gtPlusPlus/xmod/gregtech | |
parent | 89d30a5cfcc2d3d5773647350edf913f156062b3 (diff) | |
download | GT5-Unofficial-ab84b1d95f8c4880891debc594a41f57941de78a.tar.gz GT5-Unofficial-ab84b1d95f8c4880891debc594a41f57941de78a.tar.bz2 GT5-Unofficial-ab84b1d95f8c4880891debc594a41f57941de78a.zip |
+ Added some new functions to ReflectionUtils.java.
+ Added an alternative way to Obtain Blizz rods, dust and Cryotheum dust if GalaxySpace is loaded. Closes #557.
$ Fixed bug in DecayableRecipeHandler.java.
$ Fixed instance where I was directly referencing forestry code.
$ Rewrote how canning/uncanning recipes are handled, hopefully fixes the corruption of the recipe map.
> I potentially broke some of my own canning recipes, so be aware of any missing and let me know.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech')
5 files changed, 161 insertions, 37 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java b/src/Java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java index 94ddda283d..94adb5a92c 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java @@ -216,8 +216,10 @@ public interface IGregtech_RecipeAdder { public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aDust, ItemStack aOutput); - public void addFluidExtractionRecipe(ItemStack input, Object input2, FluidStack output, int aTime, int aEu, int aSpecial); - + public boolean addFluidExtractionRecipe(ItemStack input, ItemStack input2, FluidStack output, int aTime, int aEu, int aSpecial); + + public boolean addFluidCannerRecipe(ItemStack aContainer, ItemStack aFullContainer, FluidStack rFluidIn, FluidStack rFluidOut); + /** * Adds a Fusion reactor Recipe * @@ -262,4 +264,5 @@ public interface IGregtech_RecipeAdder { public boolean addUvLaserRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput, int time, long eu); public boolean addIrLaserRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput, int time, long eu); + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_FluidCanning.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_FluidCanning.java index 7bc0eacd4f..0a20d9357c 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_FluidCanning.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_FluidCanning.java @@ -4,11 +4,17 @@ import java.util.HashSet; import java.util.Set; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; import gregtech.api.util.GT_Recipe; - +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.Recipe_GT; import gtPlusPlus.api.interfaces.RunnableWithInfo; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialGenerator; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; public class RecipeGen_FluidCanning extends RecipeGen_Base { @@ -18,13 +24,76 @@ public class RecipeGen_FluidCanning extends RecipeGen_Base { } private final GT_Recipe recipe; - public RecipeGen_FluidCanning(GT_Recipe g) { - this(g, true); - } - public RecipeGen_FluidCanning(GT_Recipe g, boolean extracting) { - recipe = g; - mRecipeGenMap.add(this); - disableOptional = extracting; + private final boolean isValid; + + // Alternative Constructor + public RecipeGen_FluidCanning(boolean aExtracting, ItemStack aEmpty, ItemStack aFull, FluidStack aFluid, Integer aDuration, Integer aEUt) { + ItemStack aInput; + ItemStack aOutput; + FluidStack aFluidInput; + FluidStack aFluidOutput; + + // Safety check on the duration + if (aDuration == null || aDuration <= 0) { + aDuration = (aFluid != null) ? (aFluid.amount / 62) : (1000 / 62); + } + + // Safety check on the EU + if (aEUt == null || aEUt <= 0) { + if (aExtracting) { + aEUt = 2; + } + else { + aEUt = 1; + } + } + + // Set Item stacks correctly, invert if extraction recipe. + if (aExtracting) { + aInput = aFull; + aOutput = aEmpty; + aFluidInput = null; + aFluidOutput = aFluid; + } + else { + aInput = aEmpty; + aOutput = aFull; + aFluidInput = aFluid; + aFluidOutput = null; + } + + //Check validity + + Recipe_GT aRecipe = new Recipe_GT( + true, + new ItemStack[] { aInput }, + new ItemStack[] { aOutput }, + null, + new int[] {}, + new FluidStack[] { aFluidInput }, + new FluidStack[] { aFluidOutput }, + aDuration, + 1, + 0); + + + // Not Valid + if ((aExtracting && (aInput == null || aOutput == null ||aFluidOutput == null)) || (!aExtracting && (aInput == null || aOutput == null || aFluidInput == null))) { + isValid = false; + disableOptional = aExtracting; + recipe = null; + } + else { + // Valid Recipe + recipe = aRecipe; + mRecipeGenMap.add(this); + disableOptional = aExtracting; + isValid = true; + } + + + + } @Override @@ -33,29 +102,79 @@ public class RecipeGen_FluidCanning extends RecipeGen_Base { } private void generateRecipes() { - if (recipe != null) { + if (isValid && recipe != null) { //Used to store Fluid extraction state if (this.disableOptional) { - GT_Values.RA.addFluidExtractionRecipe( - recipe.mInputs.length >= 1 ? recipe.mInputs[0] : null, //Input - recipe.mInputs.length == 2 ? recipe.mInputs[1] : null, //Input 2 - recipe.mFluidOutputs.length == 1 ? recipe.mFluidOutputs[0] : null, //Fluid Output - recipe.mSpecialValue, //Chance - recipe.mDuration, //Duration - recipe.mEUt //Eu Tick - ); + addFluidExtractionRecipe( + recipe.mInputs.length >= 1 ? recipe.mInputs[0] : null, //Input + recipe.mInputs.length == 2 ? recipe.mInputs[1] : null, //Input 2 + recipe.mFluidOutputs.length == 1 ? recipe.mFluidOutputs[0] : null, //Fluid Output + recipe.mDuration, //Duration + recipe.mEUt //Eu Tick + ); } else { - GT_Values.RA.addFluidCannerRecipe( - recipe.mInputs.length == 1 ? recipe.mInputs[0] : null, //Input - recipe.mOutputs.length == 1 ? recipe.mOutputs[0] : null, //Input 2 - recipe.mFluidInputs.length == 1 ? recipe.mFluidInputs[0] : null, //Fluid Input - recipe.mFluidOutputs.length == 1 ? recipe.mFluidOutputs[0] : null //Fluid Output - ); + addFluidCannerRecipe( + recipe.mInputs.length == 1 ? recipe.mInputs[0] : null, //Input + recipe.mOutputs.length == 1 ? recipe.mOutputs[0] : null, //Input 2 + recipe.mFluidInputs.length == 1 ? recipe.mFluidInputs[0] : null //Fluid Input + ); } } } + private final boolean addFluidExtractionRecipe(final ItemStack aInput, final ItemStack aRemains, FluidStack aOutput, int aDuration, final int aEUt) { + if (aInput == null || aOutput == null) { + return false; + } + if (aOutput.isFluidEqual(Materials.PhasedGold.getMolten(1L))) { + aOutput = Materials.VibrantAlloy.getMolten(aOutput.amount); + } + if (aOutput.isFluidEqual(Materials.PhasedIron.getMolten(1L))) { + aOutput = Materials.PulsatingIron.getMolten(aOutput.amount); + } + //Logger.INFO(buildLogString()); + boolean result = GT_Values.RA.addFluidExtractionRecipe(aInput, aRemains, aOutput, 10000, aDuration, aEUt); + //Logger.INFO(buildLogString()); + //dumpStack(); + return result; + } + + public final boolean addFluidCannerRecipe(final ItemStack aInput, final ItemStack aOutput, FluidStack aFluidInput) { + if (aInput == null || aOutput == null || aFluidInput == null) { + return false; + } + if (aFluidInput.isFluidEqual(Materials.PhasedGold.getMolten(1L))) { + aFluidInput = Materials.VibrantAlloy.getMolten(aFluidInput.amount); + } + if (aFluidInput.isFluidEqual(Materials.PhasedIron.getMolten(1L))) { + aFluidInput = Materials.PulsatingIron.getMolten(aFluidInput.amount); + } + //Logger.INFO(buildLogString()); + boolean result = GT_Values.RA.addFluidCannerRecipe(aInput, aOutput, aFluidInput, GT_Values.NF); + //Logger.INFO(buildLogString()); + //dumpStack(); + return result; + } + + private void dumpStack() { + int parents = 2; + for (int i=0;i<6;i++) { + Logger.INFO((disableOptional ? "EXTRACTING" : "CANNING")+" DEBUG | "+(i == 0 ? "Called from: " : "Parent: ")+ReflectionUtils.getMethodName(i+parents)); + } + + } + + private String buildLogString() { + int solidSize = getMapSize(GT_Recipe_Map.sCannerRecipes); + int fluidSize = getMapSize(GT_Recipe_Map.sFluidCannerRecipes); + return (disableOptional ? "EXTRACTING" : "CANNING")+" DEBUG | Solids: "+solidSize+" | Liquids: "+fluidSize+" | "; + } + + private final int getMapSize(GT_Recipe_Map aMap) { + return aMap.mRecipeList.size(); + } + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java index b2236fdd6c..b3b71c7587 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java @@ -48,7 +48,7 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // Ingot if (ItemUtils.checkForInvalidItems(material.getIngot(1))) - if (GT_Values.RA.addFluidExtractionRecipe(material.getIngot(1), // Input + if (CORE.RA.addFluidExtractionRecipe(material.getIngot(1), // Input null, // Input 2 material.getFluid(144), // Fluid Output 0, // Chance @@ -64,7 +64,7 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // Plate if (ItemUtils.checkForInvalidItems(material.getPlate(1))) - if (GT_Values.RA.addFluidExtractionRecipe(material.getPlate(1), // Input + if (CORE.RA.addFluidExtractionRecipe(material.getPlate(1), // Input null, // Input 2 material.getFluid(144), // Fluid Output 0, // Chance @@ -80,7 +80,7 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // Double Plate if (ItemUtils.checkForInvalidItems(material.getPlateDouble(1))) - if (GT_Values.RA.addFluidExtractionRecipe(material.getPlateDouble(1), // Input + if (CORE.RA.addFluidExtractionRecipe(material.getPlateDouble(1), // Input null, // Input 2 material.getFluid(288), // Fluid Output 0, // Chance @@ -96,7 +96,7 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // Nugget if (ItemUtils.checkForInvalidItems(material.getNugget(1))) - if (GT_Values.RA.addFluidExtractionRecipe(material.getNugget(1), // Input + if (CORE.RA.addFluidExtractionRecipe(material.getNugget(1), // Input null, // Input 2 material.getFluid(16), // Fluid Output 0, // Chance @@ -112,7 +112,7 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // Block if (ItemUtils.checkForInvalidItems(material.getBlock(1))) - if (GT_Values.RA.addFluidExtractionRecipe(material.getBlock(1), // Input + if (CORE.RA.addFluidExtractionRecipe(material.getBlock(1), // Input null, // Input 2 material.getFluid(144 * 9), // Fluid Output 0, // Chance diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Recycling.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Recycling.java index f0c2785e1b..3328b0894f 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Recycling.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Recycling.java @@ -139,7 +139,7 @@ public class RecipeGen_Recycling implements Runnable { //Fluid Extractor if (ItemUtils.checkForInvalidItems(tempStack)) { // mValidItems[mSlotIndex++] = tempStack; - if ((mDust != null) && GT_Values.RA.addFluidExtractionRecipe(tempStack, null, material.getFluid(mFluidAmount), 0, 30, material.vVoltageMultiplier)) { + if ((mDust != null) && CORE.RA.addFluidExtractionRecipe(tempStack, null, material.getFluid(mFluidAmount), 0, 30, material.vVoltageMultiplier)) { Logger.WARNING("Fluid Recycle Recipe: " + material.getLocalizedName() + " - Success - Recycle " + tempStack.getDisplayName() + " and obtain " + mFluidAmount+"mb of "+material.getFluid(1).getLocalizedName()+"."); } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java b/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java index 83704b6af9..3c996ef64f 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/recipes/GregtechRecipeAdder.java @@ -991,14 +991,16 @@ public class GregtechRecipeAdder implements IGregtech_RecipeAdder { } @Override - public void addFluidExtractionRecipe(ItemStack input, Object input2, FluidStack output, int aTime, int aEu, int aSpecial) { - MaterialGenerator.addFluidExtractionRecipe(input, input2, output, aSpecial, aTime, aEu); - + public boolean addFluidExtractionRecipe(ItemStack input, ItemStack input2, FluidStack output, int aTime, int aEu, int aSpecial) { + Method aExtractionMethod = ReflectionUtils.getMethod(MaterialGenerator.class, "addFluidExtractionRecipe", new Class[] {ItemStack.class, ItemStack.class, FluidStack.class, int.class, int.class}); + return ReflectionUtils.invoke(null, aExtractionMethod, new Object[] {input, input2, output, aSpecial, aTime, aEu}); } - - - + @Override + public boolean addFluidCannerRecipe(ItemStack aFullContainer, ItemStack container, FluidStack rFluidIn, FluidStack rFluidOut) { + Method aExtractionMethod = ReflectionUtils.getMethod(MaterialGenerator.class, "addFluidCannerRecipe", new Class[] {ItemStack.class, ItemStack.class, FluidStack.class}); + return ReflectionUtils.invoke(null, aExtractionMethod, new Object[] {aFullContainer, container, rFluidIn, rFluidOut}); + } /** * Adds a Fusion reactor Recipe |