From 2ab3ccdf0251e099c338bcff554a72c4420fbf69 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 25 Feb 2023 22:13:17 +0700 Subject: [PATCH] Add ignoreFlowRestrictions to moveEnergy --- .../otm/block/entity/tech/AndroidStationBlockEntity.kt | 2 +- .../kotlin/ru/dbotthepony/mc/otm/capability/Helpers.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt index 96d029eac..212084307 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt @@ -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) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Helpers.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Helpers.kt index dafd77dfc..1d48ca885 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Helpers.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Helpers.kt @@ -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) } } }