Make energy counter be more consistent with lastTick

This commit is contained in:
DBotThePony 2022-01-04 20:05:35 +07:00
parent 6c6f22c2a1
commit c689098253
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -37,7 +37,8 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo
fun size() = history.size fun size() = history.size
operator fun get(i: Int) = history[i] operator fun get(i: Int) = history[i]
val lastTick: Fraction get() = history[historyTick] var lastTick: Fraction = Fraction.ZERO
private set
fun getHistory(ticks: Int): Array<Fraction> { fun getHistory(ticks: Int): Array<Fraction> {
require(!(ticks < 1 || ticks >= history.size)) { "Invalid history length provided" } require(!(ticks < 1 || ticks >= history.size)) { "Invalid history length provided" }
@ -339,6 +340,7 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo
} }
fun tick() { fun tick() {
lastTick = history[historyTick]
historyTick = (historyTick + 1) % history.size historyTick = (historyTick + 1) % history.size
history[historyTick] = Fraction.ZERO history[historyTick] = Fraction.ZERO
} }