Add ignoreFlowRestrictions to moveEnergy
This commit is contained in:
parent
5adbcdb7b1
commit
2ab3ccdf02
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user