diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt index 8fd3a2514..fcfe6354d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityEnergyCounter.kt @@ -55,6 +55,7 @@ data class EnergyCounterPacket(val pos: BlockPos, val thisTick: ImpreciseFractio tile.lastTick = thisTick tile.passed = total tile[index] = value + tile.historyTick = index } } @@ -75,7 +76,8 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo internal set private val history = Array(10 * 20) { ImpreciseFraction.ZERO } - private var historyTick = 0 + var historyTick = 0 + internal set fun size() = history.size operator fun get(i: Int) = history[i] @@ -93,7 +95,7 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo for (i in 0 until ticks) { var index = (historyTick - i) % this.history.size - if (index < 0) index += this.history.size + if (index < 0) index = this.history.size - 1 history[i] = this.history[index] } @@ -111,7 +113,7 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo for (i in 0 until ticks) { var index = (historyTick - i) % history.size - if (index < 0) index += history.size + if (index < 0) index = history.size - 1 value += history[index] } @@ -422,8 +424,8 @@ class BlockEntityEnergyCounter(p_155229_: BlockPos, p_155230_: BlockState) : Blo fun tick() { lastTick = history[historyTick] val index = historyTick - historyTick = (historyTick + 1) % history.size val accumulated = history[historyTick] + historyTick = (historyTick + 1) % history.size history[historyTick] = ImpreciseFraction.ZERO MatteryNetworking.CHANNEL.send(PacketDistributor.NEAR.with(this::distributor), EnergyCounterPacket(blockPos, lastTick, passed, index, accumulated))