diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-10-24 02:39:52 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-10-24 02:39:52 +1000 |
commit | e76f9156bea6c2f17d7e2a06744f475de7252da9 (patch) | |
tree | 39b21e7bf9ef8545155713f34aee8b1206417cd8 /src/Java | |
parent | 4c30de81baeb39872215a5af47feab8378e9b627 (diff) | |
download | GT5-Unofficial-e76f9156bea6c2f17d7e2a06744f475de7252da9.tar.gz GT5-Unofficial-e76f9156bea6c2f17d7e2a06744f475de7252da9.tar.bz2 GT5-Unofficial-e76f9156bea6c2f17d7e2a06744f475de7252da9.zip |
+ Finally finished the Chemical Compound Tooltips. Still needs formatting improvements, but the figures and compound should be correct.
☼ Broke Mixer recipes.
Diffstat (limited to 'src/Java')
-rw-r--r-- | src/Java/gtPlusPlus/core/material/ALLOY.java | 16 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/material/Material.java | 148 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/material/MaterialStack.java | 100 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/math/MathUtils.java | 32 |
4 files changed, 244 insertions, 52 deletions
diff --git a/src/Java/gtPlusPlus/core/material/ALLOY.java b/src/Java/gtPlusPlus/core/material/ALLOY.java index 89ea7ec2ff..0aa819ee48 100644 --- a/src/Java/gtPlusPlus/core/material/ALLOY.java +++ b/src/Java/gtPlusPlus/core/material/ALLOY.java @@ -309,6 +309,22 @@ public final class ALLOY { new MaterialStack(ELEMENT.NICKEL, 65) }); + /*public static final Material HASTELLOY_X = new Material( + "Hastelloy-X", //Material Name + new short[]{255, 193, 37, 0}, //Material Colour + 1350, //Melting Point in C + ((ELEMENT.IRON.getBoilingPoint_C()*18)+(ELEMENT.MOLYBDENUM.getBoilingPoint_C()*9)+(ELEMENT.CHROMIUM.getBoilingPoint_C()*22)+(ELEMENT.NICKEL.getBoilingPoint_C()*51))/100, //Boiling Point in C + ((ELEMENT.IRON.getProtons()*18)+(ELEMENT.MOLYBDENUM.getProtons()*9)+(ELEMENT.CHROMIUM.getProtons()*22)+(ELEMENT.NICKEL.getProtons()*51))/100, //Protons + ((ELEMENT.IRON.getNeutrons()*18)+(ELEMENT.MOLYBDENUM.getNeutrons()*9)+(ELEMENT.CHROMIUM.getNeutrons()*22)+(ELEMENT.NICKEL.getNeutrons()*51))/100, //Neutrons + false, //Uses Blast furnace? + //Material Stacks with Percentage of required elements. + new MaterialStack[]{ + new MaterialStack(ELEMENT.IRON, 18), + new MaterialStack(ELEMENT.MOLYBDENUM, 9), + new MaterialStack(ELEMENT.CHROMIUM, 22), + new MaterialStack(ELEMENT.NICKEL, 51) + });*/ + public static final Material HASTELLOY_X = new Material( "Hastelloy-X", //Material Name new short[]{255, 193, 37, 0}, //Material Colour diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index db83799039..16cccc9660 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -34,6 +34,7 @@ public class Material { final long vProtons; final long vNeutrons; final long vMass; + final int smallestStackSizeWhenProcessing; //Add a check for <=0 || > 64 public final int vTier; public final int vVoltageMultiplier; public final String vChemicalFormula; @@ -64,17 +65,15 @@ public class Material { this.vMass = getMass(); //List<MaterialStack> inputArray = Arrays.asList(inputs); - if (inputs != null){ - if (inputs.length != 0){ - for (int x=0;x<inputs.length;x++) - this.mMaterialList.add(inputs[x]); - } + int tempSmallestSize = getSmallestStackForCrafting(inputs); + if (tempSmallestSize <= 64 && tempSmallestSize >= 1){ + this.smallestStackSizeWhenProcessing = tempSmallestSize; //Valid stacksizes + } + else { + this.smallestStackSizeWhenProcessing = 50; //Can divide my math by 1/2 and round it~ } - - this.vChemicalSymbol = chemicalSymbol; - this.vChemicalFormula = getToolTip(chemicalSymbol, OrePrefixes.dust.mMaterialAmount / M, true); - + //Sets the Rad level if (radiationLevel != 0){ this.isRadioactive = true; this.vRadioationLevel = (byte) radiationLevel; @@ -84,6 +83,7 @@ public class Material { this.vRadioationLevel = (byte) radiationLevel; } + //Sets the materials 'tier'. Will probably replace this logic. if (getMeltingPoint_K() >= 0 && getMeltingPoint_K() <= 750){ this.vTier = 1; } @@ -134,6 +134,20 @@ public class Material { } } + //Makes a Fancy Chemical Tooltip + this.vChemicalSymbol = chemicalSymbol; + if (materialInput != null){ + this.vChemicalFormula = getToolTip(chemicalSymbol, OrePrefixes.dust.mMaterialAmount / M, true); + } + else if (!this.vChemicalSymbol.equals("")){ + Utils.LOG_INFO("materialInput is null, using a valid chemical symbol."); + this.vChemicalFormula = this.vChemicalSymbol; + } + else{ + Utils.LOG_INFO("MaterialInput == null && chemicalSymbol probably equals nothing"); + this.vChemicalFormula = "??"; + } + dataVar = MathUtils.generateSingularRandomHexValue(); Utils.LOG_INFO("Creating a Material instance for "+materialName); @@ -346,32 +360,108 @@ public class Material { } + public long[] getSmallestRatio(MaterialStack[] inputs){ + if (inputs != null){ + if (inputs.length > 0){ + Utils.LOG_INFO("length: "+inputs.length); + Utils.LOG_INFO("(inputs != null): "+(inputs != null)); + //Utils.LOG_INFO("length: "+inputs.length); + double tempPercentage=0; + long[] tempRatio = new long[inputs.length]; + for (int x=0;x<inputs.length;x++){ + //tempPercentage = tempPercentage+inputs[x].percentageToUse; + //this.mMaterialList.add(inputs[x]); + if (inputs[x] != null){ + tempRatio[x] = inputs[x].getPartsPerOneHundred(); + } + } + //Check if % of added materials equals roughly 100% + /*if (tempPercentage <= 95 || tempPercentage >= 101){ + Utils.LOG_INFO("The compound for "+localizedName+" doesn't equal 98-100%, this isn't good."); + }*/ + + long[] smallestRatio = MathUtils.simplifyNumbersToSmallestForm(tempRatio); + + if (smallestRatio.length > 0){ + String tempRatioStringThing1 = ""; + for (int r=0;r<tempRatio.length;r++){ + tempRatioStringThing1 = tempRatioStringThing1 + tempRatio[r] +" : "; + } + Utils.LOG_INFO("Default Ratio: "+tempRatioStringThing1); + + String tempRatioStringThing = ""; + int tempSmallestCraftingUseSize = 0; + for (int r=0;r<smallestRatio.length;r++){ + tempRatioStringThing = tempRatioStringThing + smallestRatio[r] +" : "; + tempSmallestCraftingUseSize = (int) (tempSmallestCraftingUseSize + smallestRatio[r]); + } + //this.smallestStackSizeWhenProcessing = tempSmallestCraftingUseSize; + Utils.LOG_INFO("Smallest Ratio: "+tempRatioStringThing); + return smallestRatio; + } + } + } + return null; + } + + public int getSmallestStackForCrafting(MaterialStack[] inputs){ + if (inputs != null){ + if (inputs.length != 0){ + long[] smallestRatio = getSmallestRatio(inputs); + if (smallestRatio.length > 0){ + int tempSmallestCraftingUseSize = 0; + for (int r=0;r<smallestRatio.length;r++){ + tempSmallestCraftingUseSize = (int) (tempSmallestCraftingUseSize + smallestRatio[r]); + } + return tempSmallestCraftingUseSize; + } + } + } + return 1; + } + public String getToolTip(String chemSymbol, long aMultiplier, boolean aShowQuestionMarks) { if (!aShowQuestionMarks && (vChemicalFormula.equals("?")||vChemicalFormula.equals("??"))) return ""; - Utils.LOG_INFO("===============| Calculating Atomic Formula for "+this.localizedName+" |==============="); - Utils.LOG_INFO("aMultiplier: "+aMultiplier); - Utils.LOG_INFO("aMultiplier >= M * 2: "+aMultiplier+" >= "+M * 2); - Utils.LOG_INFO("aMultiplier >= M * 2: "+(aMultiplier >= M * 2)); - Utils.LOG_INFO("!mMaterialList.isEmpty(): "+!mMaterialList.isEmpty()); - Utils.LOG_INFO("mMaterialList.size(): "+mMaterialList.size()); - Utils.LOG_INFO("mMaterialList.size() < 2: "+(mMaterialList.size() < 2)); - if (mMaterialList.size() != 0) - Utils.LOG_INFO("mMaterialList.get(0).vAmount: "+mMaterialList.get(0).vAmount); - if (mMaterialList.size() != 0) - Utils.LOG_INFO("mMaterialList.get(0).vAmount == 1: "+(mMaterialList.get(0).vAmount==1)); - Utils.LOG_INFO("===============| Finished Calculating data for "+this.localizedName+" |==============="); - Utils.LOG_INFO(""); - - if (aMultiplier >= M * 2 && !mMaterialList.isEmpty()) { - if(((chemSymbol != null && !chemSymbol.equals("")) || (mMaterialList.size() < 2 && mMaterialList.get(0).vAmount == 1))){ - return vChemicalFormula + aMultiplier; - } - return "(" + vChemicalFormula + ")" + aMultiplier; - } if (!chemSymbol.equals("")) return chemSymbol; + MaterialStack[] tempInput = materialInput; + if (tempInput != null){ + if (tempInput.length >= 1){ + String dummyFormula = ""; + long[] dummyFormulaArray = getSmallestRatio(tempInput); + if (dummyFormulaArray != null){ + if (dummyFormulaArray.length >= 1){ + for (int e=0;e<tempInput.length;e++){ + if (tempInput[e] != null){ + if (!tempInput[e].stackMaterial.vChemicalSymbol.equals("??")){ + if (dummyFormulaArray[e] > 1){ + dummyFormula = dummyFormula + tempInput[e].stackMaterial.vChemicalSymbol + dummyFormulaArray[e]; + } + else if (dummyFormulaArray[e] == 1){ + dummyFormula = dummyFormula + tempInput[e].stackMaterial.vChemicalSymbol; + } + else if (dummyFormulaArray[e] <= 0){ + dummyFormula = dummyFormula+""; + } + + }else + dummyFormula = dummyFormula + "??"; + } + else { + dummyFormula = dummyFormula+""; + } + } + return dummyFormula; + } + Utils.LOG_INFO("dummyFormulaArray <= 0"); + } + Utils.LOG_INFO("dummyFormulaArray == null"); + } + Utils.LOG_INFO("tempInput.length <= 0"); + } + Utils.LOG_INFO("tempInput == null"); return "??"; } diff --git a/src/Java/gtPlusPlus/core/material/MaterialStack.java b/src/Java/gtPlusPlus/core/material/MaterialStack.java index 5e076e6e70..8d9de3faf4 100644 --- a/src/Java/gtPlusPlus/core/material/MaterialStack.java +++ b/src/Java/gtPlusPlus/core/material/MaterialStack.java @@ -1,24 +1,67 @@ package gtPlusPlus.core.material; import gtPlusPlus.core.util.item.UtilsItems; + +import java.math.BigDecimal; +import java.math.RoundingMode; + import net.minecraft.item.ItemStack; public class MaterialStack { - - final int vAmount; + + final int[] vAmount; final Material stackMaterial; final double percentageToUse; - - public MaterialStack(Material inputs, double percentage){ + + public MaterialStack(Material inputs, double partOutOf100){ this.stackMaterial = inputs; - this.percentageToUse = percentage; - this.vAmount = getDustCount(); - - + this.percentageToUse = partOutOf100; + this.vAmount = math(partOutOf100); + + + } + + private int[] math(double val){ + //Cast to a BigDecimal to round it. + BigDecimal bd = new BigDecimal(val).setScale(2, RoundingMode.HALF_EVEN); + val = bd.doubleValue(); + //Split the string into xx.xx + String[] arr=String.valueOf(val).split("\\."); + int[] intArr=new int[2]; + intArr[0]=Integer.parseInt(arr[0]); + intArr[1]=Integer.parseInt(arr[1]); + return intArr; } - + public ItemStack getDustStack(){ + return this.stackMaterial.getDust(this.vAmount[0]); + } + public int getPartsPerOneHundred(){ + if (this.vAmount != null){ + if (this.vAmount[0] >= 1 && this.vAmount[0] <= 100){ + return this.vAmount[0]; + } + } + return 100; + } + public ItemStack getLeftOverStacksFromDecimalValue(){ + int temp = this.vAmount[1]; + int getCount; + if (temp >= 25 && temp <=99){ + getCount = temp/25; + return this.stackMaterial.getSmallDust(getCount); + } + else if (temp >= 11 && temp <= 24){ + getCount = temp/11; + return this.stackMaterial.getTinyDust(getCount); + } + else { + return null; + } + } + + /*public ItemStack getDustStack(){ int caseStatus = 0; int amount = 0; if (percentageToUse >= 0 && percentageToUse <= 0.99){ @@ -59,36 +102,47 @@ public class MaterialStack { default: return null; } - - } - - public int getDustCount(){ + + }*/ + + /*public int getDustCount(){ int amount = 0; - if (percentageToUse >= 0 && percentageToUse <= 0.99){ - amount = (int) (1/percentageToUse); + + //No Dust + if (percentageToUse >= 0 && percentageToUse <= 11.1111111111111111111111110){ + //amount = (int) (1/percentageToUse); + amount = 0; //Less than a tiny dust. } - else if (percentageToUse >= 1 && percentageToUse <= 9.99){ + + //Tiny Dust + else if (percentageToUse >= 11.1111111111111111111111111 && percentageToUse <= 25){ amount = (int) (percentageToUse); } + + //Small Dust else if (percentageToUse >= 10 && percentageToUse <= 99.99){ amount = (int) (percentageToUse/10); } + + //Dust else if (percentageToUse == 100){ amount = 10; } + + //Error - Nothing else { amount = 0; } return amount; - } - + }*/ + public ItemStack[] getValidItemStacks(){ return UtilsItems.validItemsForOreDict(stackMaterial.unlocalizedName); } - - - - - + + + + + } diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java index b4aec5a8bf..8fab1341d3 100644 --- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java @@ -222,5 +222,37 @@ public class MathUtils { Utils.LOG_WARNING("It will decode into "+Integer.decode(temp)+"."); return Integer.decode(temp); } + + public static long[] simplifyNumbersToSmallestForm(long[] inputArray){ + long GCD = gcd(inputArray); + long[] outputArray = new long[inputArray.length]; + for (int i=0;i<inputArray.length;i++){ + if (GCD != 0) + outputArray[i] = (inputArray[i]/GCD); + else + outputArray[i] = inputArray[i]; + } + if (outputArray.length > 0) + return outputArray; + return null; + } + + private static long gcd(long a, long b){ + while (b > 0) + { + long temp = b; + b = a % b; // % is remainder + a = temp; + } + return a; + } + + private static long gcd(long[] input){ + long result = input[0]; + for(int i = 1; i < input.length; i++) result = gcd(result, input[i]); + return result; + } + + } |