diff options
author | BlueWeabo <76872108+BlueWeabo@users.noreply.github.com> | 2023-01-25 20:27:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 19:27:59 +0100 |
commit | fb8ff7c903da0ef48073a4ace10a673f4a1ceed9 (patch) | |
tree | 030937b98e4f84308202c1339338b7e5e11d9c6a /src | |
parent | 7faaa550b1f1c17fe35e9e59831270c8f863de02 (diff) | |
download | GT5-Unofficial-fb8ff7c903da0ef48073a4ace10a673f4a1ceed9.tar.gz GT5-Unofficial-fb8ff7c903da0ef48073a4ace10a673f4a1ceed9.tar.bz2 GT5-Unofficial-fb8ff7c903da0ef48073a4ace10a673f4a1ceed9.zip |
Fixes OC Calculation not accounting eut discount for low eut recipes (#1685)
* fix
* typo fixes
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
* fixTyposInParallelHelper
* sa
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src')
3 files changed, 62 insertions, 25 deletions
diff --git a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java index 71b6c8e37f..6ea873e6b4 100644 --- a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java +++ b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java @@ -10,7 +10,7 @@ public class GT_OverclockCalculator { private long mAmps = 1, mEUt = 0, mRecipeEUt = 0, mRecipeAmps = 1; /** * @mEUtDiscount - Discount for EUt at the beginning of calculating overclocks, like GT++ machines - * @mSpeedBoost - Speeding/Slowing up/down the duration of a recipe at the beginnign of calculating overclocks, like GT++ machines + * @mSpeedBoost - Speeding/Slowing up/down the duration of a recipe at the beginning of calculating overclocks, like GT++ machines * @mHeatDiscountAmont - The value used for discount final eut per 900 heat */ private float mEUtDiscount = 1, mSpeedBoost = 1, mHeatDiscountAmount = 0.95f; @@ -23,7 +23,7 @@ public class GT_OverclockCalculator { * @mMultiHeat - The heat the multi has when starting the recipe * @mHeatPerfectOC - How much the bits should be moved to the right for each 1800 above recipe heat (Used for duration) */ - private int mEUtIncrasePerOC = 2, + private int mEUtIncreasePerOC = 2, mDurationDecreasePerOC = 1, mDuration = 0, mParallel = 1, @@ -31,10 +31,10 @@ public class GT_OverclockCalculator { mMultiHeat = 0, mHeatPerfectOC = 2; /** - * @mHeatOC - Wheather to enable overlcocking with heat like the EBF every 1800 heat difference - * @mOneTickDiscount - Wheather to give EUt Discount when the duration goes below one tick - * @calculates - variable to check wheater the overclocks have been calculated - * @mHeatDiscount - Wheather to enable heat discounts every 900 heat difference + * @mHeatOC - Whether to enable overclocking with heat like the EBF every 1800 heat difference + * @mOneTickDiscount - Whether to give EUt Discount when the duration goes below one tick + * @calculates - variable to check whether the overclocks have been calculated + * @mHeatDiscount - Whether to enable heat discounts every 900 heat difference */ private boolean mHeatOC, mOneTickDiscount, calculated, mHeatDiscount; @@ -134,7 +134,7 @@ public class GT_OverclockCalculator { } /** - * Sets a Speed Boost for the multiblock. 0.9 is 10% faser. 1.1 is 10% slower + * Sets a Speed Boost for the multiblock. 0.9 is 10% faster. 1.1 is 10% slower */ public GT_OverclockCalculator setSpeedBoost(float aSpeedBoost) { mSpeedBoost = aSpeedBoost; @@ -170,7 +170,7 @@ public class GT_OverclockCalculator { * Sets the amount that the EUt increases per overclock. This uses BitShifting! Default is 2, which is a 4x increase */ public GT_OverclockCalculator setEUtIncreasePerOC(int aEUtIncreasePerOC) { - mEUtIncrasePerOC = aEUtIncreasePerOC; + mEUtIncreasePerOC = aEUtIncreasePerOC; return this; } @@ -206,7 +206,6 @@ public class GT_OverclockCalculator { return; } int heatDiscounts = (mMultiHeat - mRecipeHeat) / HEAT_DISCOUNT_THRESHOLD; - mRecipeEUt = (long) Math.ceil(mRecipeEUt * mEUtDiscount); mDuration = (int) Math.ceil(mDuration * mSpeedBoost); if (mHeatOC) { while (mRecipeHeat + HEAT_PERFECT_OVERCLOCK_THRESHOLD <= mMultiHeat @@ -214,7 +213,7 @@ public class GT_OverclockCalculator { if (mDuration < 1) { break; } - mRecipeEUt <<= mEUtIncrasePerOC; + mRecipeEUt <<= mEUtIncreasePerOC; mDuration >>= mHeatPerfectOC; mRecipeHeat += HEAT_PERFECT_OVERCLOCK_THRESHOLD; } @@ -223,15 +222,25 @@ public class GT_OverclockCalculator { int tRecipeTier = GT_Utility.getTier(mRecipeEUt); if (tRecipeTier == 0) { int tTier = GT_Utility.getTier(mEUt); - mRecipeEUt = (mRecipeEUt * (1L << tTier - 1) * (1L << tTier - 1)); - mDuration = (mDuration / (1 << tTier - 1)); + int tTierDifference = tTier - 1; + long tNextConsumption = + ((long) Math.ceil(mRecipeEUt * mParallel * mRecipeAmps * mEUtDiscount)) << mEUtIncreasePerOC; + while (tTierDifference > 0 && tNextConsumption < mEUt * mAmps) { + mRecipeEUt <<= mEUtIncreasePerOC; + mDuration >>= mDurationDecreasePerOC; + tNextConsumption <<= mEUtIncreasePerOC; + tTierDifference--; + } } else { - while ((mRecipeEUt * mParallel * mRecipeAmps) << mEUtIncrasePerOC < mEUt * mAmps) { + long tNextConsumption = + ((long) Math.ceil(mRecipeEUt * mParallel * mRecipeAmps * mEUtDiscount)) << mEUtIncreasePerOC; + while (tNextConsumption < mEUt * mAmps) { if (mDuration <= 1) { break; } - mRecipeEUt <<= mEUtIncrasePerOC; + mRecipeEUt <<= mEUtIncreasePerOC; mDuration >>= mDurationDecreasePerOC; + tNextConsumption <<= mEUtIncreasePerOC; } } @@ -244,18 +253,18 @@ public class GT_OverclockCalculator { } if (mOneTickDiscount) { - int voltageDifferece = GT_Utility.getTier(mEUt) - GT_Utility.getTier(mRecipeEUt); - mRecipeEUt >>= voltageDifferece * mDurationDecreasePerOC; + int voltageDifference = GT_Utility.getTier(mEUt) - GT_Utility.getTier(mRecipeEUt); + mRecipeEUt >>= voltageDifference * mDurationDecreasePerOC; if (mRecipeEUt < 1) { mRecipeEUt = 1; } } - mRecipeEUt *= mParallel * mRecipeAmps; + mRecipeEUt = (long) Math.ceil(mRecipeEUt * mParallel * mRecipeAmps * mEUtDiscount); } /** - * @return The consumtipn after overclock has been calculated + * @return The consumption after overclock has been calculated */ public long getConsumption() { if (!calculated) { diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index c320a5bd12..7f32d95d1e 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -33,7 +33,7 @@ public class GT_ParallelHelper { */ private GT_Recipe mRecipe; /** - * @mAvailtableEUt EUt available to the multiblock (This should be the total eut available) + * @mAvailableEUt EUt available to the multiblock (This should be the total eut available) */ private long mAvailableEUt; /** @@ -53,7 +53,7 @@ public class GT_ParallelHelper { */ private FluidStack[] mFluidInputs, mFluidOutputs; /** - * @mVoidProtection Does the multi have void protectio enabled + * @mVoidProtection Does the multi have void protection enabled * @mConsume Should the Parallel Helper automatically consume for the multi * @mBatchMode Is batch mode turned on? * @mCalculateOutputs Should the Parallel Helper automatically calculate the outputs of the recipe with current parallel @@ -62,9 +62,9 @@ public class GT_ParallelHelper { private boolean mVoidProtection, mConsume, mBatchMode, mCalculateOutputs, mBuilt; /** * @mDurationMultiplier What is the duration multiplier with batch mode enabled - * @mEUtModifer Modifier which is applied on the recipe eut. Usefull for GT++ machines + * @mEUtModifier Modifier which is applied on the recipe eut. Useful for GT++ machines */ - private float mDurationMultiplier, mEUtModifer = 1; + private float mDurationMultiplier, mEUtModifier = 1; public GT_ParallelHelper() {} @@ -122,7 +122,7 @@ public class GT_ParallelHelper { * Sets the modifier for recipe eut. 1 does nothing 0.9 is 10% less. 1.1 is 10% more */ public GT_ParallelHelper setEUtModifier(float aEUtModifier) { - mEUtModifer = aEUtModifier; + mEUtModifier = aEUtModifier; return this; } @@ -276,7 +276,7 @@ public class GT_ParallelHelper { } } - float tRecipeEUt = mRecipe.mEUt * mEUtModifer; + float tRecipeEUt = mRecipe.mEUt * mEUtModifier; // Consume inputs to determine normal parallel for (; mCurrentParallel < mMaxParallel / mBatchModifier && tCurrentUsage < (mAvailableEUt - tRecipeEUt); @@ -329,7 +329,8 @@ public class GT_ParallelHelper { private int calculateMaxParallelsForHatches() { // For now we are gonna ignore MuTEs existence as there are no recipes for them if (mMachineMeta != null && mMachineMeta.mOutputHatches.size() >= mRecipe.mFluidOutputs.length) { - // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the + // A map to hold the items we will be 'inputting' into the output hatches. These fluidstacks are actually + // the // recipe outputs. Map<FluidStack, Integer> tFluidOutputMap = new HashMap<>(); diff --git a/src/test/java/gregtech/overclock/GT_OverclockCalculator_UnitTest.java b/src/test/java/gregtech/overclock/GT_OverclockCalculator_UnitTest.java index 91be53cf3f..cc641f96e5 100644 --- a/src/test/java/gregtech/overclock/GT_OverclockCalculator_UnitTest.java +++ b/src/test/java/gregtech/overclock/GT_OverclockCalculator_UnitTest.java @@ -331,4 +331,31 @@ class GT_OverclockCalculator_UnitTest { assertEquals(1, calculator.getDuration(), messageDuration); assertEquals(480 >> 6, calculator.getConsumption(), messageEUt); } + + @Test + void ulvRecipeWithDiscount_Test() { + long correctConsumption = (long) Math.ceil((VP[0] << 10) * 0.9f); + GT_OverclockCalculator calculator = new GT_OverclockCalculator() + .setRecipeEUt(VP[0]) + .setEUt(V[6]) + .setEUtDiscount(0.9f) + .setDuration(1024) + .calculate(); + assertEquals(1024 >> 5, calculator.getDuration(), messageDuration); + assertEquals(correctConsumption, calculator.getConsumption(), messageEUt); + } + + @Test + void ulvRecipeWithDiscountWithParallel_Test() { + long correctConsumption = (long) Math.ceil((VP[0] << 6) * 14 * 0.9f); + GT_OverclockCalculator calculator = new GT_OverclockCalculator() + .setRecipeEUt(VP[0]) + .setEUt(V[5]) + .setEUtDiscount(0.9f) + .setParallel(14) + .setDuration(1024) + .calculate(); + assertEquals(1024 >> 3, calculator.getDuration(), messageDuration); + assertEquals(correctConsumption, calculator.getConsumption(), messageEUt); + } } |