Optimize matter capacitor bank
This commit is contained in:
parent
7405989b97
commit
750f941525
@ -39,10 +39,9 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
||||
var summ = Decimal.ZERO
|
||||
|
||||
for (stack in container)
|
||||
if (!stack.isEmpty)
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
summ += it.storedMatter
|
||||
}
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
summ += it.storedMatter
|
||||
}
|
||||
|
||||
return summ
|
||||
}
|
||||
@ -50,19 +49,31 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val maxStoredMatter: Decimal
|
||||
get() {
|
||||
override val maxStoredMatter: Decimal get() {
|
||||
var summ = Decimal.ZERO
|
||||
|
||||
for (stack in container)
|
||||
if (!stack.isEmpty)
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
summ += it.maxStoredMatter
|
||||
}
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
summ += it.maxStoredMatter
|
||||
}
|
||||
|
||||
return summ
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
super.tick()
|
||||
var stored = Decimal.ZERO
|
||||
var maxStored = Decimal.ZERO
|
||||
|
||||
for (stack in container) {
|
||||
val cap = stack.getCapability(MatteryCapability.MATTER_ITEM) ?: continue
|
||||
stored += cap.storedMatter
|
||||
maxStored += cap.maxStoredMatter
|
||||
}
|
||||
|
||||
gaugeLevel = stored.percentage(maxStored)
|
||||
}
|
||||
|
||||
override fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||
if (!howMuch.isPositive)
|
||||
return Decimal.ZERO
|
||||
@ -72,23 +83,16 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
||||
var summ = Decimal.ZERO
|
||||
|
||||
for (stack in container) {
|
||||
if (!stack.isEmpty) {
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
val diff = it.receiveMatterChecked(howMuch, simulate)
|
||||
summ += diff
|
||||
howMuch -= diff
|
||||
}
|
||||
val it = stack.getCapability(MatteryCapability.MATTER_ITEM) ?: continue
|
||||
val diff = it.receiveMatterChecked(howMuch, simulate)
|
||||
summ += diff
|
||||
howMuch -= diff
|
||||
|
||||
if (howMuch.isZero) {
|
||||
break
|
||||
}
|
||||
if (howMuch.isZero) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (summ.isPositive && !simulate) {
|
||||
gaugeLevel = storedMatter.percentage(maxStoredMatter)
|
||||
}
|
||||
|
||||
return summ
|
||||
}
|
||||
|
||||
@ -101,23 +105,16 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
||||
var summ = Decimal.ZERO
|
||||
|
||||
for (stack in container) {
|
||||
if (!stack.isEmpty) {
|
||||
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
|
||||
val diff = it.extractMatterChecked(howMuch, simulate)
|
||||
summ += diff
|
||||
howMuch -= diff
|
||||
}
|
||||
val it = stack.getCapability(MatteryCapability.MATTER_ITEM) ?: continue
|
||||
val diff = it.extractMatterChecked(howMuch, simulate)
|
||||
summ += diff
|
||||
howMuch -= diff
|
||||
|
||||
if (howMuch.isZero) {
|
||||
break
|
||||
}
|
||||
if (howMuch.isZero) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (summ.isPositive && !simulate) {
|
||||
gaugeLevel = storedMatter.percentage(maxStoredMatter)
|
||||
}
|
||||
|
||||
return summ
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user