diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt index f60c07021..ad1a054a4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt @@ -53,10 +53,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte private var currentChangeSlot = 0 private var currentDischangeSlot = 0 + private var lastTickCharged = false + private var lastTickDischarged = false + init { savetable(::container, INVENTORY_KEY) savetables.int(::currentChangeSlot) savetables.int(::currentDischangeSlot) + savetables.bool(::lastTickCharged) + savetables.bool(::lastTickDischarged) } private fun distributeEnergy(isReceiving: Boolean, howMuch: Decimal, simulate: Boolean): Decimal { @@ -93,10 +98,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte } if (!simulate) { - if (isReceiving) + if (isReceiving) { + this.lastTickCharged = true + if (currentSlot == this.currentChangeSlot) currentSlot = (currentSlot + 1) % container.containerSize this.currentChangeSlot = currentSlot - else + } else { + this.lastTickDischarged = true + if (currentSlot == this.currentDischangeSlot) currentSlot = (currentSlot + 1) % container.containerSize this.currentDischangeSlot = currentSlot + } } return summ @@ -112,8 +122,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte override fun tick() { super.tick() - currentChangeSlot = (currentChangeSlot + 1) % container.containerSize - currentDischangeSlot = (currentDischangeSlot + 1) % container.containerSize + + if (!lastTickCharged) + currentChangeSlot = (currentChangeSlot + 1) % container.containerSize + + if (!lastTickDischarged) + currentDischangeSlot = (currentDischangeSlot + 1) % container.containerSize + + lastTickCharged = false + lastTickDischarged = false } override val canSetBatteryLevel: Boolean