Battery bank a bit smarter distribution

This commit is contained in:
DBotThePony 2023-03-20 18:03:45 +07:00
parent ec99243b15
commit 0481507217
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -53,10 +53,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
private var currentChangeSlot = 0 private var currentChangeSlot = 0
private var currentDischangeSlot = 0 private var currentDischangeSlot = 0
private var lastTickCharged = false
private var lastTickDischarged = false
init { init {
savetable(::container, INVENTORY_KEY) savetable(::container, INVENTORY_KEY)
savetables.int(::currentChangeSlot) savetables.int(::currentChangeSlot)
savetables.int(::currentDischangeSlot) savetables.int(::currentDischangeSlot)
savetables.bool(::lastTickCharged)
savetables.bool(::lastTickDischarged)
} }
private fun distributeEnergy(isReceiving: Boolean, howMuch: Decimal, simulate: Boolean): Decimal { 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 (!simulate) {
if (isReceiving) if (isReceiving) {
this.lastTickCharged = true
if (currentSlot == this.currentChangeSlot) currentSlot = (currentSlot + 1) % container.containerSize
this.currentChangeSlot = currentSlot this.currentChangeSlot = currentSlot
else } else {
this.lastTickDischarged = true
if (currentSlot == this.currentDischangeSlot) currentSlot = (currentSlot + 1) % container.containerSize
this.currentDischangeSlot = currentSlot this.currentDischangeSlot = currentSlot
}
} }
return summ return summ
@ -112,8 +122,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
override fun tick() { override fun tick() {
super.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 override val canSetBatteryLevel: Boolean