Add ignoreFlowRestrictions to moveEnergy

This commit is contained in:
DBotThePony 2023-02-25 22:13:17 +07:00
parent 5adbcdb7b1
commit 2ab3ccdf02
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 6 additions and 5 deletions

View File

@ -88,7 +88,7 @@ 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))) {
ent.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK {
if (it.isAndroid)
moveEnergy(energy, it.androidEnergy, amount = energy.batteryLevel, simulate = false)
moveEnergy(energy, it.androidEnergy, amount = energy.batteryLevel, simulate = false, ignoreFlowRestrictions = true)
}
}
}

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.capability
import net.minecraftforge.energy.IEnergyStorage
import net.minecraftforge.items.IItemHandler
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.core.math.Decimal
/**
@ -45,14 +46,14 @@ fun moveBetweenSlots(source: IItemHandler, sourceSlot: Int, destination: IItemHa
}
@Suppress("name_shadowing")
fun moveEnergy(source: IEnergyStorage, destination: IEnergyStorage, amount: Decimal = Decimal.LONG_MAX_VALUE, simulate: Boolean): Decimal {
val extracted = source.extractEnergy(amount, true)
fun moveEnergy(source: IEnergyStorage, destination: IEnergyStorage, amount: Decimal = Decimal.LONG_MAX_VALUE, simulate: Boolean, ignoreFlowRestrictions: Boolean = false): Decimal {
val extracted = if (ignoreFlowRestrictions && source is IMatteryEnergyStorage) source.extractEnergy(amount, true) else source.extractEnergy(amount, true)
if (extracted.isPositive) {
val received = destination.receiveEnergy(extracted, true)
if (received.isPositive) {
val extracted = source.extractEnergy(received, true)
val extracted = if (ignoreFlowRestrictions && source is IMatteryEnergyStorage) source.extractEnergy(received, true) else source.extractEnergy(received, true)
if (extracted.isPositive) {
if (simulate) {
@ -60,7 +61,7 @@ fun moveEnergy(source: IEnergyStorage, destination: IEnergyStorage, amount: Deci
}
val received = destination.receiveEnergy(extracted, false)
return source.extractEnergy(received, false)
return if (ignoreFlowRestrictions && source is IMatteryEnergyStorage) source.extractEnergy(received, false) else source.extractEnergy(received, false)
}
}
}