Fix compact minus of fractions were actually adding
This commit is contained in:
parent
26808f0ce8
commit
e58b5b725e
src
main
java/ru/dbotthepony/mc/otm/block/entity
kotlin/ru/dbotthepony/mc/otm/core
test/kotlin/ru/dbotthepony/mc/otm/tests
@ -147,7 +147,7 @@ public class BlockEntityMatterDecomposer extends BlockEntityMatteryWorker implem
|
||||
if (MatterRegistry.canDecompose(copy)) {
|
||||
var matter_value = MatterRegistry.getMatterValue(copy);
|
||||
|
||||
if (!matter_value.equals(BigDecimal.ZERO) && matter.canReceiveAll(matter_value)) {
|
||||
if (!matter_value.equals(Fraction.ZERO) && matter.canReceiveAll(matter_value)) {
|
||||
stack.shrink(1);
|
||||
return new MachineJob(copy, matter_value.toDouble() * 12_500d);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.core.Fraction;
|
||||
|
@ -30,7 +30,7 @@ public record MachineJob(ItemStack stack, double ticks_processing_time, Fraction
|
||||
store_job.put("data", data);
|
||||
store_job.put("stack", stack.serializeNBT());
|
||||
store_job.putDouble("ticks_processing_time", ticks_processing_time);
|
||||
store_job.putString("power_consumption_multiplier", power_consumption_multiplier.toString());
|
||||
store_job.put("power_consumption_multiplier", power_consumption_multiplier.serializeNBT());
|
||||
|
||||
return store_job;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ data class Fraction @JvmOverloads constructor(@JvmField val value: BigInteger, @
|
||||
fun minusCompact(other: Fraction): Fraction {
|
||||
if (divisor == other.divisor) {
|
||||
if (divisor == BigInteger.ONE)
|
||||
return Fraction(value + other.value)
|
||||
return Fraction(value - other.value)
|
||||
|
||||
val new = value - other.value
|
||||
val mod = new % divisor
|
||||
|
@ -118,4 +118,38 @@ object FractionTests {
|
||||
|
||||
assert(value.compareTo(Fraction.deserializeNBT(serialized)) == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Fraction inaccurate representation")
|
||||
fun inaccurate() {
|
||||
var value = 1.1
|
||||
var frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
|
||||
value = 1.45
|
||||
frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
|
||||
value = -1.0
|
||||
frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
|
||||
value = -254.66
|
||||
frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
|
||||
value = 94.949494
|
||||
frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
|
||||
value = 1.0 / 3
|
||||
frac = Fraction(value)
|
||||
|
||||
assert(frac.toDouble() == value) { "$value != $frac as (${frac.toDouble()})" }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user