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 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,11 +98,16 @@ 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()
if (!lastTickCharged)
currentChangeSlot = (currentChangeSlot + 1) % container.containerSize
if (!lastTickDischarged)
currentDischangeSlot = (currentDischangeSlot + 1) % container.containerSize
lastTickCharged = false
lastTickDischarged = false
}
override val canSetBatteryLevel: Boolean