This commit is contained in:
DBotThePony 2023-02-25 18:37:44 +07:00
parent eb39675b15
commit f5840c4ca1
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 6 additions and 22 deletions

View File

@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.capability.moveEnergy
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal
@ -86,19 +87,8 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
for (ent in level.getEntitiesOfClass(ServerPlayer::class.java, AABB(x, y, z, x + 1.0, y + 2.0, z + 1.0))) { for (ent in level.getEntitiesOfClass(ServerPlayer::class.java, AABB(x, y, z, x + 1.0, y + 2.0, z + 1.0))) {
ent.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK { ent.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK {
if (!it.isAndroid) if (it.isAndroid)
return@ifPresentK moveEnergy(energy, it.androidEnergy, amount = energy.batteryLevel, simulate = false)
val missing = it.androidEnergy.missingPower
if (missing > Decimal.ZERO) {
val extract = energy.extractEnergy(missing, true)
if (extract > Decimal.ZERO) {
val received = it.androidEnergy.receiveEnergy(extract, false)
energy.extractEnergy(received, false)
}
}
} }
} }
} }

View File

@ -102,15 +102,9 @@ class AndroidPowerSource(
if (!item.isEmpty) { if (!item.isEmpty) {
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK { item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
if (it is IMatteryEnergyStorage) { val extracted = it.receiveEnergy(howMuch, simulate)
val extracted = it.receiveEnergy(howMuch, simulate) received += extracted
received += extracted howMuch -= extracted
howMuch -= extracted
} else {
val extracted = it.receiveEnergy(howMuch, simulate)
received += extracted
howMuch -= extracted
}
} }
if (howMuch.isZero) { if (howMuch.isZero) {