aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authoriamblackornot <nkzshinnik@gmail.com>2023-10-07 10:02:28 +0300
committerGitHub <noreply@github.com>2023-10-07 09:02:28 +0200
commit312f902598dcc8cb3422df0ac997e78fb073f3bb (patch)
tree5e76100a5d9e6c6aa31d237348f230504ff2a7cc /src/main/java
parent7feb23037362ffcf07ab3e58ff818aa79e448ec4 (diff)
downloadGT5-Unofficial-312f902598dcc8cb3422df0ac997e78fb073f3bb.tar.gz
GT5-Unofficial-312f902598dcc8cb3422df0ac997e78fb073f3bb.tar.bz2
GT5-Unofficial-312f902598dcc8cb3422df0ac997e78fb073f3bb.zip
- fixes https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/14559 (#2325)
- had to change 2 unit test to address the mentioned above OC calculation fix Co-authored-by: iamblackornot <nkzshinnnik@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/gregtech/api/util/GT_OverclockCalculator.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java
index f721ffc225..582b65e7ec 100644
--- a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java
+++ b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java
@@ -398,7 +398,7 @@ public class GT_OverclockCalculator {
double recipePowerTier = calculateRecipePowerTier(heatDiscountMultiplier);
double machinePowerTier = calculateMachinePowerTier();
- // Math.log(a) / Math.log(b) equals to log_b (a)
+
overclockCount = calculateAmountOfNeededOverclocks(machinePowerTier, recipePowerTier);
if (recipeVoltage <= GT_Values.V[0]) {
overclockCount = Math.min(overclockCount, calculateRecipeToMachineVoltageDifference());
@@ -470,11 +470,26 @@ public class GT_OverclockCalculator {
/**
* Calculates the amount of overclocks needed to reach 1 ticking
+ *
+ * Here we limit "the tier difference overclock" amount to a number
+ * of overclocks needed to reach 1 tick duration, for example:
+ *
+ * recipe initial duration = 250 ticks (12,5 seconds LV(1))
+ * we have LCR with IV(5) energy hatch, which overclocks at 4/4 rate
+ *
+ * log_4 (250) ~ 3,98 is the number of overclocks needed to reach 1 tick
+ *
+ * to calculate log_a(b) we can use the log property:
+ * log_a(b) = log_c(b) / log_c(a)
+ * in our case we use natural log base as 'c'
+ *
+ * as a final step we apply Math.ceil(),
+ * otherwise for fractional nums like 3,98 we will never reach 1 tick
*/
private int calculateAmountOfNeededOverclocks(double machinePowerTier, double recipePowerTier) {
return (int) Math.min(
calculateAmountOfOverclocks(machinePowerTier, recipePowerTier),
- Math.log(duration) / Math.log(1 << durationDecreasePerOC));
+ Math.ceil(Math.log(duration) / Math.log(1 << durationDecreasePerOC)));
}
private double calculateHeatDiscountMultiplier() {