toImpreciseFraction -> toDecimal
This commit is contained in:
parent
ce437d4e14
commit
0b316fe0fc
@ -20,7 +20,7 @@ fun Decimal.toFloatingLong(): FloatingLong {
|
|||||||
return FloatingLong.create(whole.toLong(), (decimal * 10_000.0).toInt().toShort())
|
return FloatingLong.create(whole.toLong(), (decimal * 10_000.0).toInt().toShort())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FloatingLong.toImpreciseFraction(): Decimal {
|
fun FloatingLong.toDecimal(): Decimal {
|
||||||
// Overflow
|
// Overflow
|
||||||
if (value < 0L) {
|
if (value < 0L) {
|
||||||
return Decimal(LONG_OVERFLOW + BigInteger.valueOf(value), decimal / 10_000.0)
|
return Decimal(LONG_OVERFLOW + BigInteger.valueOf(value), decimal / 10_000.0)
|
||||||
|
@ -51,7 +51,7 @@ private class DoubleLazy<T>(onion: () -> Lazy<T>) : Lazy<T> {
|
|||||||
private val mekanism2MtJ by DoubleLazy lazy@{
|
private val mekanism2MtJ by DoubleLazy lazy@{
|
||||||
try {
|
try {
|
||||||
val conf = MekanismConfig.general
|
val conf = MekanismConfig.general
|
||||||
return@lazy LazyCache(conf.forgeConversionRate::get) { Decimal.ONE / it.toImpreciseFraction() }
|
return@lazy LazyCache(conf.forgeConversionRate::get) { Decimal.ONE / it.toDecimal() }
|
||||||
} catch(err: Throwable) {
|
} catch(err: Throwable) {
|
||||||
LOGGER.error("Unable to get Forge Energy to Mekanism Joules's conversion rate! Expect issues", err)
|
LOGGER.error("Unable to get Forge Energy to Mekanism Joules's conversion rate! Expect issues", err)
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ private val mekanism2MtJ by DoubleLazy lazy@{
|
|||||||
private val mtj2Mekanism by DoubleLazy lazy@{
|
private val mtj2Mekanism by DoubleLazy lazy@{
|
||||||
try {
|
try {
|
||||||
val conf = MekanismConfig.general
|
val conf = MekanismConfig.general
|
||||||
return@lazy LazyCache(conf.forgeConversionRate::get) { it.toImpreciseFraction() }
|
return@lazy LazyCache(conf.forgeConversionRate::get) { it.toDecimal() }
|
||||||
} catch(err: Throwable) {
|
} catch(err: Throwable) {
|
||||||
LOGGER.error("Unable to get Mekanism Joules's to Forge Energy conversion rate! Expect issues", err)
|
LOGGER.error("Unable to get Mekanism Joules's to Forge Energy conversion rate! Expect issues", err)
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
false -> Action.EXECUTE
|
false -> Action.EXECUTE
|
||||||
}
|
}
|
||||||
|
|
||||||
return power.extractEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toImpreciseFraction() * mekanism2MtJ
|
return power.extractEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
@ -90,7 +90,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
false -> Action.EXECUTE
|
false -> Action.EXECUTE
|
||||||
}
|
}
|
||||||
|
|
||||||
return howMuch - power.insertEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toImpreciseFraction() * mekanism2MtJ
|
return howMuch - power.insertEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
@ -105,7 +105,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
var sum = Decimal.ZERO
|
var sum = Decimal.ZERO
|
||||||
|
|
||||||
for (i in 0 until power.energyContainerCount) {
|
for (i in 0 until power.energyContainerCount) {
|
||||||
sum += power.getEnergy(i).toImpreciseFraction()
|
sum += power.getEnergy(i).toDecimal()
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum * mekanism2MtJ
|
return sum * mekanism2MtJ
|
||||||
@ -122,7 +122,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
var sum = Decimal.ZERO
|
var sum = Decimal.ZERO
|
||||||
|
|
||||||
for (i in 0 until power.energyContainerCount) {
|
for (i in 0 until power.energyContainerCount) {
|
||||||
sum += power.getMaxEnergy(i).toImpreciseFraction()
|
sum += power.getMaxEnergy(i).toDecimal()
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum * mekanism2MtJ
|
return sum * mekanism2MtJ
|
||||||
@ -176,11 +176,11 @@ class Mattery2MekanismEnergyWrapper(private val power: IMatteryEnergyStorage) :
|
|||||||
|
|
||||||
override fun insertEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
override fun insertEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
||||||
val copy = howMuch.copy()
|
val copy = howMuch.copy()
|
||||||
return copy.minusEqual((power.receiveEnergyOuter(howMuch.toImpreciseFraction() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong())
|
return copy.minusEqual((power.receiveEnergyOuter(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
override fun extractEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
||||||
return (power.extractEnergyOuter(howMuch.toImpreciseFraction() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong()
|
return (power.extractEnergyOuter(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user