Remove inner/outer variants from IMatteryEnergyStorage

This commit is contained in:
DBotThePony 2023-01-14 13:02:25 +07:00
parent 75211f068c
commit 9073ae1b08
Signed by: DBot
GPG Key ID: DCC23B5715498507
28 changed files with 231 additions and 312 deletions

View File

@ -30,7 +30,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
import ru.dbotthepony.mc.otm.android.AndroidActiveFeature
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
@ -64,7 +64,7 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
get() = ServerConfig.EnderTeleporter.COOLDOWN
private fun canUse(): Boolean {
return !isOnCooldown && android.androidEnergy.extractEnergyInnerExact(ServerConfig.EnderTeleporter.ENERGY_COST, true).isPositive
return !isOnCooldown && android.androidEnergy.extractEnergyExact(ServerConfig.EnderTeleporter.ENERGY_COST, true)
}
private fun isValidGround(blockPos: BlockPos): Boolean {
@ -309,7 +309,7 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
putOnCooldown()
lastTeleport = ply.server!!.tickCount
android.androidEnergy.extractEnergyInner(ServerConfig.EnderTeleporter.ENERGY_COST, false)
android.androidEnergy.extractEnergy(ServerConfig.EnderTeleporter.ENERGY_COST, false)
ply.level.playSound(null, ply, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 0.3f, 0.8f + ply.level.random.nextFloat() * 0.4f)
ply.teleportTo(event.targetX, event.targetY, event.targetZ)

View File

@ -13,7 +13,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.core.Vector
@ -73,7 +73,7 @@ class ItemMagnetFeature(capability: MatteryPlayerCapability) : AndroidSwitchable
private val clientPredicate = Predicate<Entity> { it is ItemEntity && (datatable[it] ?: SharedItemEntityData.EMPTY).let { !it.hasPickupDelay && (it.owner == null || it.owner != ply.uuid || it.lifespan - it.age <= 200) } }
private fun doTick(server: Boolean) {
if (ply.isSpectator || server && !android.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, true).isPositive) {
if (ply.isSpectator || server && !android.androidEnergy.extractEnergyExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, true)) {
return
}
@ -98,7 +98,7 @@ class ItemMagnetFeature(capability: MatteryPlayerCapability) : AndroidSwitchable
if (data.position.distanceToSqr(ent.position) < 1.0) {
data.ticksSinceActivity++
} else {
if (!android.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, false).isPositive) {
if (!android.androidEnergy.extractEnergyExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, false)) {
return
}
@ -114,7 +114,7 @@ class ItemMagnetFeature(capability: MatteryPlayerCapability) : AndroidSwitchable
override fun tickClient() {
super.tickClient()
if (!ply.isSpectator && isActive && android.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, true).isPositive) {
if (!ply.isSpectator && isActive && android.androidEnergy.extractEnergyExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, true)) {
doTick(false)
}
}

View File

@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.core.Vector
@ -46,7 +46,7 @@ object TriggerJumpBoostPacket : MatteryPacket {
val feature = mattery.getFeature(AndroidFeatures.JUMP_BOOST) as JumpBoostFeature? ?: return@enqueueWork
if (feature.isActive && feature.cooldown <= 4 && mattery.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidJumpBoost.ENERGY_COST, false).isPositive) {
if (feature.isActive && feature.cooldown <= 4 && mattery.androidEnergy.extractEnergyExact(ServerConfig.AndroidJumpBoost.ENERGY_COST, false)) {
feature.putOnCooldown()
context.sender?.let {
@ -90,7 +90,7 @@ class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
val old = lastGround
lastGround = ply.isOnGround
if (isActive && cooldown <= 0 && old != lastGround && !lastGround && isJumping && isShifting && ply.xRot <= ClientConfig.JUMP_BOOST_LOOK_ANGLE && android.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidJumpBoost.ENERGY_COST, true).isPositive) {
if (isActive && cooldown <= 0 && old != lastGround && !lastGround && isJumping && isShifting && ply.xRot <= ClientConfig.JUMP_BOOST_LOOK_ANGLE && android.androidEnergy.extractEnergyExact(ServerConfig.AndroidJumpBoost.ENERGY_COST, true)) {
ply.deltaMovement += Vector(0.0, ServerConfig.AndroidJumpBoost.POWER * (level + 1) / 20.0, 0.0)
putOnCooldown()
MatteryPlayerNetworkChannel.sendToServer(TriggerJumpBoostPacket)

View File

@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.core.Decimal
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import ru.dbotthepony.mc.otm.registry.StatNames
@ -28,12 +28,12 @@ class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(An
private var layers = 0
override fun tickServer() {
if (layers < strength + 1 && android.androidEnergy.extractEnergyInnerExact(ENERGY_PER_LAYER, true).isPositive) {
if (layers < strength + 1 && android.androidEnergy.extractEnergyExact(ENERGY_PER_LAYER, true)) {
ticksPassed++
if (ticksPassed >= TICKS[speed]) {
layers++
android.androidEnergy.extractEnergyInner(ENERGY_PER_LAYER, false)
android.androidEnergy.extractEnergy(ENERGY_PER_LAYER, false)
}
} else {
ticksPassed = 0
@ -48,7 +48,7 @@ class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(An
if (absorbed > 0.1f) {
val powerRequired = ENERGY_PER_HITPOINT * absorbed
val powerExtracted = android.androidEnergy.extractEnergyInner(powerRequired, false)
val powerExtracted = android.androidEnergy.extractEnergy(powerRequired, false)
val realAbsorbed = (powerExtracted / ENERGY_PER_HITPOINT).toFloat()
val ply = ply

View File

@ -24,7 +24,7 @@ class NanobotsRegenerationFeature(android: MatteryPlayerCapability) : AndroidFea
if (ticksPassed > waitTime) {
val missingHealth = (ply.maxHealth - ply.health).coerceAtMost(2f)
val power = ServerConfig.NanobotsRegeneration.ENERGY_PER_HITPOINT * missingHealth
val extracted = android.androidEnergy.extractEnergyInner(power, false)
val extracted = android.androidEnergy.extractEnergy(power, false)
if (extracted.isPositive) {
healTicks = (healTicks + 1).coerceAtMost(level)

View File

@ -6,7 +6,7 @@ import net.minecraft.world.effect.MobEffects
import ru.dbotthepony.mc.otm.ServerConfig
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
@ -18,12 +18,8 @@ class NightVisionFeature(android: MatteryPlayerCapability) : AndroidSwitchableFe
if (isActive) {
val effect = android.ply.activeEffectsMap[MobEffects.NIGHT_VISION]
if ((effect == null || effect.duration < 220) && (ply.isSpectator || android.androidEnergy.extractEnergyInnerExact(ServerConfig.NIGHT_VISION_POWER_DRAW, true).isPositive)) {
if ((effect == null || effect.duration < 220) && (ply.isSpectator || android.androidEnergy.extractEnergyExact(ServerConfig.NIGHT_VISION_POWER_DRAW, false))) {
android.ply.addEffect(MobEffectInstance(MobEffects.NIGHT_VISION, 220, 0, false, false))
if (!ply.isSpectator) {
android.androidEnergy.extractEnergyInner(ServerConfig.NIGHT_VISION_POWER_DRAW, false)
}
}
}
}

View File

@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.core.Vector
import ru.dbotthepony.mc.otm.core.formatPower
@ -83,7 +83,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
isActive &&
ply.isShiftKeyDown &&
!isOnCooldown &&
android.androidEnergy.extractEnergyInnerExact(ServerConfig.Shockwave.ENERGY_COST, true).isPositive &&
android.androidEnergy.extractEnergyExact(ServerConfig.Shockwave.ENERGY_COST, true) &&
ply.deltaMovement.y < -0.01 &&
creativeFlightTicks == 0
) {
@ -94,7 +94,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
}
fun shockwave() {
if (ply.isSpectator || isOnCooldown || !android.androidEnergy.extractEnergyInnerExact(ServerConfig.Shockwave.ENERGY_COST, false).isPositive) {
if (ply.isSpectator || isOnCooldown || !android.androidEnergy.extractEnergyExact(ServerConfig.Shockwave.ENERGY_COST, false)) {
return
}
@ -199,7 +199,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
!ply.isSpectator &&
isActive &&
!isOnCooldown &&
android.androidEnergy.extractEnergyInnerExact(ServerConfig.Shockwave.ENERGY_COST, true).isPositive &&
android.androidEnergy.extractEnergyExact(ServerConfig.Shockwave.ENERGY_COST, true) &&
creativeFlightTicks == 0
) {
val old = wasMidair

View File

@ -88,7 +88,7 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
val extract = energy.extractEnergyInner(missing, true)
if (extract > Decimal.ZERO) {
val received = it.androidEnergy.receiveEnergyOuter(extract, false)
val received = it.androidEnergy.receiveEnergy(extract, false)
energy.extractEnergyInner(received, false)
}
}

View File

@ -78,7 +78,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
override fun canExtract() = mode != BankMode.RECEIVE
override fun canReceive() = mode != BankMode.EXTRACT
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (mode == BankMode.RECEIVE)
return Decimal.ZERO
@ -157,18 +157,18 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
return summ
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
return distributeEnergy(isReceiving = false, howMuch, simulate)
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (mode == BankMode.EXTRACT)
return Decimal.ZERO
return receiveEnergyInner(howMuch, simulate)
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
return distributeEnergy(isReceiving = true, howMuch, simulate)
}

View File

@ -127,11 +127,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
}
private inner class EnergyCounterCap(val isInput: Boolean) : IMatteryEnergyStorage {
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return extractEnergyInner(howMuch, simulate)
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (isInput)
return Decimal.ZERO
@ -159,11 +155,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
return Decimal.ZERO
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyInner(howMuch, simulate)
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (!isInput)
return Decimal.ZERO

View File

@ -59,19 +59,11 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
})
val energy = object : IMatteryEnergyStorage {
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return extractEnergyInner(howMuch, simulate)
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
return container[SLOT_DISCHARGE].energy?.extractEnergy(howMuch, simulate) ?: Decimal.ZERO
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyInner(howMuch, simulate)
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
return container[SLOT_CHARGE].energy?.receiveEnergy(howMuch, simulate) ?: Decimal.ZERO
}

View File

@ -45,14 +45,14 @@ abstract class MatteryPoweredBlockEntity(p_155228_: BlockEntityType<*>, p_155229
return
}
var demand = energy.receiveEnergyOuter(energy.missingPower, true)
var demand = energy.receiveEnergy(energy.missingPower, true)
if (demand.isZero) return
for (stack in batteryContainer) {
if (!stack.isEmpty) {
stack.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
if (it is IMatteryEnergyStorage) {
val diff = it.extractEnergyOuter(demand, false)
val diff = it.extractEnergy(demand, false)
energy.receiveEnergyInner(diff, false)
demand -= diff
} else {

View File

@ -23,8 +23,6 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.capability.*
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.extractStepInner
import ru.dbotthepony.mc.otm.capability.energy.extractStepInnerBi
import ru.dbotthepony.mc.otm.container.ItemFilter
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.graph.Graph6Node

View File

@ -18,7 +18,6 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.transferInner
import ru.dbotthepony.mc.otm.core.Decimal
import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode
import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph
@ -92,7 +91,7 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState
val available = energy.batteryLevel.coerceAtMost(ServerConfig.STORAGE_POWER_SUPPLIER.throughput)
for (demanding in graph.powerDemandingNodes) {
val received = demanding.receiveEnergyOuter(available, true)
val received = demanding.receiveEnergy(available, true)
if (received.isPositive) {
demand += received

View File

@ -32,7 +32,7 @@ val ICapabilityProvider.matteryPlayer: MatteryPlayerCapability? get() = getCapab
fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): Decimal {
if (this is IMatteryEnergyStorage)
return receiveEnergyOuter(amount, simulate)
return receiveEnergy(amount, simulate)
if (!amount.isPositive)
return Decimal.ZERO
@ -45,7 +45,7 @@ fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): Decimal {
fun IEnergyStorage.extractEnergy(amount: Decimal, simulate: Boolean): Decimal {
if (this is IMatteryEnergyStorage)
return extractEnergyOuter(amount, simulate)
return extractEnergy(amount, simulate)
if (!amount.isPositive)
return Decimal.ZERO

View File

@ -778,16 +778,16 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
if (!ply.isSpectator) {
val stats = ply.foodData
while (stats.foodLevel < 18 && androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
while (stats.foodLevel < 18 && androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
stats.foodLevel = stats.foodLevel + 1
}
// "block" quick regeneration
// also cause power to generate while in peaceful
if (ServerConfig.REGENERATE_ENERGY) {
while (stats.foodLevel > 18 && androidEnergy.receiveEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
androidEnergy.receiveEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
while (stats.foodLevel > 18 && androidEnergy.receiveEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
androidEnergy.receiveEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
stats.foodLevel = stats.foodLevel - 1
}
} else if (ply.level.server?.worldData?.difficulty != Difficulty.PEACEFUL) {
@ -797,12 +797,12 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
val foodLevel = stats.foodLevel.toFloat()
if (stats.saturationLevel < foodLevel) {
val extracted = androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT * (foodLevel - stats.saturationLevel), false)
val extracted = androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT * (foodLevel - stats.saturationLevel), false)
stats.setSaturation(stats.saturationLevel + (extracted / ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT).toFloat())
}
if (stats.exhaustionLevel > 0f) {
val extracted = androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT * (stats.exhaustionLevel / 4f), false)
val extracted = androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT * (stats.exhaustionLevel / 4f), false)
stats.setExhaustion(stats.exhaustionLevel - (extracted / ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT).toFloat() * 4f)
}
}

View File

@ -51,40 +51,21 @@ class AndroidPowerSource(
fun tick() {
if (!item.isEmpty && battery < maxBattery) {
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
if (it is IMatteryEnergyStorage) {
battery += it.extractEnergyInner(maxBattery - battery, false)
} else {
battery += it.extractEnergy(maxBattery - battery, false)
}
}
}
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyOuter(howMuch, simulate)
}
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return Decimal.ZERO
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
@Suppress("name_shadowing")
var howMuch = howMuch
var drained = Decimal.ZERO
if (!item.isEmpty) {
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
if (it is IMatteryEnergyStorage) {
val extracted = it.extractEnergyOuter(howMuch, simulate)
drained += extracted
howMuch -= extracted
} else {
val extracted = it.extractEnergy(howMuch, simulate)
drained += extracted
howMuch -= extracted
}
}
if (howMuch.isZero) {
if (!simulate && ply is ServerPlayer) {
@ -94,6 +75,7 @@ class AndroidPowerSource(
return drained
}
}
}
val new = (battery - howMuch).moreThanZero()
drained += battery - new
@ -109,7 +91,7 @@ class AndroidPowerSource(
return drained
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
@Suppress("name_shadowing")
var howMuch = howMuch
var received = Decimal.ZERO
@ -117,7 +99,7 @@ class AndroidPowerSource(
if (!item.isEmpty) {
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
if (it is IMatteryEnergyStorage) {
val extracted = it.receiveEnergyOuter(howMuch, simulate)
val extracted = it.receiveEnergy(howMuch, simulate)
received += extracted
howMuch -= extracted
} else {

View File

@ -77,14 +77,14 @@ sealed class BlockEnergyStorageImpl(
}
}
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (direction == FlowDirection.INPUT)
return Decimal.ZERO
return extractEnergyInner(howMuch, simulate)
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (direction == FlowDirection.OUTPUT)
return Decimal.ZERO

View File

@ -7,11 +7,82 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.core.Decimal
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.formatPower
import java.math.BigInteger
sealed interface IEnergyStorageImpl {
val maxInput: Decimal?
val maxOutput: Decimal?
val direction: FlowDirection
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
fun extractStepInner(base: Decimal, multiplier: Int, simulate: Boolean): Int {
return (extractEnergyInner(base * multiplier, simulate) / base).toInt()
}
fun extractStepInnerBi(base: Decimal, multiplier: Int, simulate: Boolean): BigInteger {
return (extractEnergyInner(base * multiplier, simulate) / base).whole
}
fun extractStepInner(base: Decimal, multiplier: BigInteger, simulate: Boolean): Int {
return (extractEnergyInner(base * multiplier, simulate) / base).toInt()
}
fun extractStepInnerBi(base: Decimal, multiplier: BigInteger, simulate: Boolean): BigInteger {
return (extractEnergyInner(base * multiplier, simulate) / base).whole
}
fun transferInner(other: IMatteryEnergyStorage, amount: Decimal, simulate: Boolean): Decimal {
if (!amount.isPositive)
return Decimal.ZERO
val extracted = extractEnergyInner(amount, true)
val received = other.receiveEnergy(extracted, simulate)
if (!simulate)
extractEnergyInner(received, false)
return received
}
/**
* All or nothing
*
* @return energy accepted
*/
fun extractEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = extractEnergyInner(howMuch, true)
if (extracted != howMuch) {
return Decimal.ZERO
}
if (!simulate) {
extractEnergyInner(howMuch, false)
}
return extracted
}
/**
* All or nothing
*
* @return energy accepted
*/
fun receiveEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = receiveEnergyInner(howMuch, true)
if (extracted != howMuch) {
return Decimal.ZERO
}
if (!simulate) {
receiveEnergyInner(howMuch, false)
}
return extracted
}
}
internal fun batteryLevel(it: IEnergyStorage, tooltips: MutableList<Component>) {
@ -97,6 +168,8 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
).withStyle(ChatFormatting.GRAY))
}
}
FlowDirection.NONE -> {}
}
}
}

View File

@ -6,41 +6,23 @@ import ru.dbotthepony.mc.otm.core.RGBAColor
import java.math.BigInteger
import kotlin.math.roundToInt
// IEnergyStorage for direct compat with Forge Energy
/**
* Energy interface in Overdrive That Matters, which is backward compatible with [IEnergyStorage]
*/
interface IMatteryEnergyStorage : IEnergyStorage {
/**
* Energy extraction by external interacts
*
* @return energy extracted
*/
fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal
/**
* Energy extraction by internal processes
*
* Nothing stops you from calling this directly, not on yours capability,
* but you really should think before doing this on not own capability.
*
* @return energy extracted
*/
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal
/**
* Energy insertion by external interacts
*
* @return energy accepted
*/
fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal
/**
* Energy insertion by internal processes
*
* Nothing stops you from calling this directly, not on yours capability,
* but you really should think before doing this on not own capability.
*
* @return energy accepted
*/
fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal
fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal
/**
* If this is false, then [batteryLevel] will throw [UnsupportedOperationException] when trying to set it
@ -48,13 +30,25 @@ interface IMatteryEnergyStorage : IEnergyStorage {
val canSetBatteryLevel: Boolean get() = true
/**
* How much energy (estimated) is stored in this energy storage. Why estimated? Because some objects can be bottomless.
*
* Implementations are free to throw [UnsupportedOperationException] if setting battery level is not supported
* due to technical complications (in this case, [canSetBatteryLevel] MUST be false)
*
* @throws [UnsupportedOperationException]
*/
var batteryLevel: Decimal
/**
* How much energy (estimated) can this energy storage hold. Why estimated? Because some objects can be bottomless.
*/
val maxBatteryLevel: Decimal
/**
* How much energy (estimated) is missing in this energy storage. Why estimated? Because some objects can be bottomless.
*
* Use this to determine whenever you need an estimate on how much energy this storage can accept, **and do not implement [maxBatteryLevel] - [batteryLevel] logic by yourself**.
*/
val missingPower: Decimal
get() = (maxBatteryLevel - batteryLevel).moreThanZero()
@ -64,7 +58,7 @@ interface IMatteryEnergyStorage : IEnergyStorage {
* @throws [UnsupportedOperationException]
* @see batteryLevel
*/
fun emptyBattery() {
fun drainBattery() {
batteryLevel = Decimal.ZERO
}
@ -78,24 +72,26 @@ interface IMatteryEnergyStorage : IEnergyStorage {
batteryLevel = maxBatteryLevel
}
// -------- Forge Energy stuff
override fun receiveEnergy(maxReceive: Int, simulate: Boolean): Int {
val received = receiveEnergyOuter(maxReceive, true).toInt()
val received = receiveEnergy(Decimal(maxReceive), true).toInt()
// Receiving only a fraction
if (received == 0)
return 0
return receiveEnergyOuter(Decimal(received), simulate).toInt()
return receiveEnergy(Decimal(received), simulate).toInt()
}
override fun extractEnergy(maxReceive: Int, simulate: Boolean): Int {
val extracted = extractEnergyOuter(maxReceive, true).toInt()
val extracted = extractEnergy(Decimal(maxReceive), true).toInt()
// Extracting only a fraction
if (extracted == 0)
return 0
return extractEnergyOuter(Decimal(extracted), simulate).toInt()
return extractEnergy(Decimal(extracted), simulate).toInt()
}
override fun getEnergyStored(): Int {
@ -107,172 +103,82 @@ interface IMatteryEnergyStorage : IEnergyStorage {
}
override fun canExtract(): Boolean {
return extractEnergyOuter(Decimal.ONE, true) > Decimal.ZERO
return extractEnergy(Decimal.ONE, true) > Decimal.ZERO
}
override fun canReceive(): Boolean {
return receiveEnergyOuter(Decimal.ONE, true) > Decimal.ZERO
return receiveEnergy(Decimal.ONE, true) > Decimal.ZERO
}
}
fun IMatteryEnergyStorage.receiveEnergyOuterExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = receiveEnergyOuter(howMuch, true)
if (extracted != howMuch) {
return Decimal.ZERO
}
fun IMatteryEnergyStorage.extractEnergyExact(howMuch: Decimal, simulate: Boolean): Boolean {
if (extractEnergy(howMuch, true) == howMuch) {
if (!simulate) {
receiveEnergyOuter(howMuch, false)
return extractEnergy(howMuch, false) == howMuch
}
return extracted
return true
}
return false
}
/**
* All or nothing
*
* @return energy extracted
*/
fun IMatteryEnergyStorage.extractEnergyOuterExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = extractEnergyOuter(howMuch, true)
if (extracted != howMuch) {
return Decimal.ZERO
}
fun IMatteryEnergyStorage.receiveEnergyExact(howMuch: Decimal, simulate: Boolean): Boolean {
if (receiveEnergy(howMuch, true) == howMuch) {
if (!simulate) {
extractEnergyOuter(howMuch, false)
return receiveEnergy(howMuch, false) == howMuch
}
return extracted
}
/**
* All or nothing
*
* @return energy accepted
*/
fun IMatteryEnergyStorage.receiveEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = receiveEnergyInner(howMuch, true)
if (extracted != howMuch) {
return Decimal.ZERO
return true
}
if (!simulate) {
receiveEnergyInner(howMuch, false)
}
return extracted
return false
}
/**
* All or nothing
*
* @return energy extracted
*/
fun IMatteryEnergyStorage.extractEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
val extracted = extractEnergyInner(howMuch, true)
fun IMatteryEnergyStorage.extractEnergyExact(howMuch: Decimal, times: Int, simulate: Boolean): Int {
if (times == 0)
return 0
if (extracted != howMuch) {
return Decimal.ZERO
}
if (!simulate) {
extractEnergyInner(howMuch, false)
}
return extracted
require(times >= 0) { "times $times >= 0" }
require(howMuch >= Decimal.ZERO) { "howMuch $howMuch >= 0" }
return (extractEnergy(howMuch * times, simulate) / times).toInt()
}
fun IMatteryEnergyStorage.extractEnergyOuter(howMuch: Long, simulate: Boolean): Decimal {
return extractEnergyOuter(Decimal(howMuch), simulate)
fun IMatteryEnergyStorage.extractEnergy(howMuch: Long, simulate: Boolean): Decimal {
return extractEnergy(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.extractEnergyOuter(howMuch: Int, simulate: Boolean): Decimal {
return extractEnergyOuter(Decimal(howMuch), simulate)
fun IMatteryEnergyStorage.receiveEnergy(howMuch: Long, simulate: Boolean): Decimal {
return receiveEnergy(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.receiveEnergyOuter(howMuch: Long, simulate: Boolean): Decimal {
return receiveEnergyOuter(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.receiveEnergyOuter(howMuch: Int, simulate: Boolean): Decimal {
return receiveEnergyOuter(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.extractEnergyInner(howMuch: Long, simulate: Boolean): Decimal {
return extractEnergyInner(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.extractEnergyInner(howMuch: Int, simulate: Boolean): Decimal {
return extractEnergyInner(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.receiveEnergyInner(howMuch: Long, simulate: Boolean): Decimal {
return receiveEnergyInner(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.receiveEnergyInner(howMuch: Int, simulate: Boolean): Decimal {
return receiveEnergyInner(Decimal(howMuch), simulate)
}
fun IMatteryEnergyStorage.transferInner(other: IMatteryEnergyStorage, amount: Decimal, simulate: Boolean): Decimal {
fun IMatteryEnergyStorage.transfer(other: IMatteryEnergyStorage, amount: Decimal, simulate: Boolean): Decimal {
if (!amount.isPositive)
return Decimal.ZERO
val extracted = extractEnergyInner(amount, true)
val received = other.receiveEnergyOuter(extracted, simulate)
val extracted = extractEnergy(amount, true)
val received = other.receiveEnergy(extracted, simulate)
if (!simulate)
extractEnergyInner(received, false)
extractEnergy(received, false)
return received
}
fun IMatteryEnergyStorage.transferOuter(other: IMatteryEnergyStorage, amount: Decimal, simulate: Boolean): Decimal {
if (!amount.isPositive)
return Decimal.ZERO
val extracted = extractEnergyOuter(amount, true)
val received = other.receiveEnergyOuter(extracted, simulate)
if (!simulate)
extractEnergyInner(received, false)
return received
}
fun IMatteryEnergyStorage.extractStepInner(base: Decimal, multiplier: Int, simulate: Boolean): Int {
return (extractEnergyInner(base * multiplier, simulate) / base).toInt()
}
fun IMatteryEnergyStorage.extractStepOuter(base: Decimal, multiplier: Int, simulate: Boolean): Int {
return (extractEnergyOuter(base * multiplier, simulate) / base).toInt()
}
fun IMatteryEnergyStorage.extractStepInnerBi(base: Decimal, multiplier: Int, simulate: Boolean): BigInteger {
return (extractEnergyInner(base * multiplier, simulate) / base).whole
}
fun IMatteryEnergyStorage.extractStepOuterBi(base: Decimal, multiplier: Int, simulate: Boolean): BigInteger {
return (extractEnergyOuter(base * multiplier, simulate) / base).whole
}
fun IMatteryEnergyStorage.extractStepInner(base: Decimal, multiplier: BigInteger, simulate: Boolean): Int {
return (extractEnergyInner(base * multiplier, simulate) / base).toInt()
}
fun IMatteryEnergyStorage.extractStepOuter(base: Decimal, multiplier: BigInteger, simulate: Boolean): Int {
return (extractEnergyOuter(base * multiplier, simulate) / base).toInt()
return (extractEnergy(base * multiplier, simulate) / base).toInt()
}
fun IMatteryEnergyStorage.extractStepInnerBi(base: Decimal, multiplier: BigInteger, simulate: Boolean): BigInteger {
return (extractEnergyInner(base * multiplier, simulate) / base).whole
fun IMatteryEnergyStorage.extractStepOuter(base: Decimal, multiplier: Int, simulate: Boolean): Int {
return (extractEnergy(base * multiplier, simulate) / base).toInt()
}
fun IMatteryEnergyStorage.extractStepOuterBi(base: Decimal, multiplier: Int, simulate: Boolean): BigInteger {
return (extractEnergy(base * multiplier, simulate) / base).whole
}
fun IMatteryEnergyStorage.extractStepOuterBi(base: Decimal, multiplier: BigInteger, simulate: Boolean): BigInteger {
return (extractEnergyOuter(base * multiplier, simulate) / base).whole
return (extractEnergy(base * multiplier, simulate) / base).whole
}
fun IMatteryEnergyStorage.getBarWidth(): Int {

View File

@ -55,14 +55,14 @@ sealed class ItemEnergyStorageImpl(
itemStack.tagNotNull[ENERGY_KEY] = value.serializeNBT()
}
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (direction == FlowDirection.INPUT)
return Decimal.ZERO
return extractEnergyInner(howMuch, simulate)
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (direction == FlowDirection.OUTPUT)
return Decimal.ZERO

View File

@ -18,7 +18,7 @@ interface IMatterStorage {
val canSetMatterLevel: Boolean get() = true
/**
* How much matter (estimated) is stored in this object. Why estimated? Because some objects can be bottomless.
* How much matter (estimated) is stored in this matter storage. Why estimated? Because some objects can be bottomless.
*
* Implementations are free to throw [UnsupportedOperationException] if setting battery level is not supported
* due to technical complications (in this case, [canSetMatterLevel] MUST be false)
@ -30,7 +30,7 @@ interface IMatterStorage {
var storedMatter: Decimal
/**
* How much matter (estimated) can this object hold. Why estimated? Because some objects can be bottomless.
* How much matter (estimated) can this matter storage hold. Why estimated? Because some objects can be bottomless.
*
* **DO NOT use this to determine "how much stuff is missing", use [missingMatter] instead!**
*/
@ -64,16 +64,16 @@ interface IMatterStorage {
fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal
/**
* Extract matter from this object
* Extract matter from this matter storage
*
* @return matter extracted
*/
fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal
/**
* How much matter (estimated) is missing in this object. Why estimated? Because some objects can be bottomless.
* How much matter (estimated) is missing in this matter storage. Why estimated? Because some objects can be bottomless.
*
* Use this to determine whenever you need an estimate on how much matter this object can accept, **and do not implement [maxStoredMatter] - [storedMatter] logic by yourself**.
* Use this to determine whenever you need an estimate on how much matter this storage can accept, **and do not implement [maxStoredMatter] - [storedMatter] logic by yourself**.
*/
val missingMatter: Decimal
get() = maxStoredMatter.minus(storedMatter).moreThanZero()

View File

@ -72,7 +72,7 @@ private val mtj2Mekanism by DoubleLazy lazy@{
class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, private val forgePower: IEnergyStorage? = null) :
IMatteryEnergyStorage {
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
val action = when (simulate) {
true -> Action.SIMULATE
false -> Action.EXECUTE
@ -81,11 +81,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
return power.extractEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
return extractEnergyOuter(howMuch, simulate)
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
val action = when (simulate) {
true -> Action.SIMULATE
false -> Action.EXECUTE
@ -94,10 +90,6 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
return howMuch - power.insertEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyOuter(howMuch, simulate)
}
override val canSetBatteryLevel: Boolean
get() = power.energyContainerCount == 1
@ -177,11 +169,11 @@ class Mattery2MekanismEnergyWrapper(private val power: IMatteryEnergyStorage) :
override fun insertEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
val copy = howMuch.copy()
return copy.minusEqual((power.receiveEnergyOuter(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong())
return copy.minusEqual((power.receiveEnergy(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong())
}
override fun extractEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
return (power.extractEnergyOuter(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong()
return (power.extractEnergy(howMuch.toDecimal() * mekanism2MtJ, action.simulate()) * mtj2Mekanism).toFloatingLong()
}
}

View File

@ -30,7 +30,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider
import ru.dbotthepony.mc.otm.capability.energy.EnergyConsumerItem
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.capability.energy.getBarColor
import ru.dbotthepony.mc.otm.capability.energy.getBarWidth
import ru.dbotthepony.mc.otm.capability.matteryEnergy
@ -49,7 +49,7 @@ import ru.dbotthepony.mc.otm.core.WriteOnce
* by coremod patch
*/
fun getSweepingDamageRatioHook(ply: LivingEntity): Float? {
if (ply.mainHandItem.item is EnergySwordItem && ply.mainHandItem.matteryEnergy?.extractEnergyInnerExact(EnergySwordItem.ENERGY_PER_SWING, true)?.isPositive == true) {
if (ply.mainHandItem.item is EnergySwordItem && ply.mainHandItem.matteryEnergy?.extractEnergyExact(EnergySwordItem.ENERGY_PER_SWING, true) == true) {
return 1f
}
@ -122,10 +122,10 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
}
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
if (!it.extractEnergyInnerExact(ENERGY_PER_SWING, false).isZero) {
if (it.extractEnergyExact(ENERGY_PER_SWING, false)) {
victim.matteryPlayer?.let {
if (it.isAndroid) {
it.androidEnergy.extractEnergyInner(ENERGY_ZAP, false)
it.androidEnergy.extractEnergy(ENERGY_ZAP, false)
victim.hurt(EMPDamageSource(attacker), 8f)
}
}
@ -175,11 +175,11 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
when (blockState.material) {
Material.PLANT, Material.REPLACEABLE_PLANT, Material.VEGETABLE, Material.LEAVES ->
energy?.extractEnergyInnerExact(PLANT_POWER_COST, false)
energy?.extractEnergyExact(PLANT_POWER_COST, false)
}
if (blockState.`is`(Blocks.COBWEB)) {
energy?.extractEnergyInnerExact(COBWEB_POWER_COST, false)
energy?.extractEnergyExact(COBWEB_POWER_COST, false)
}
}
@ -208,7 +208,7 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
}
override fun canPerformAction(stack: ItemStack, toolAction: ToolAction): Boolean {
if (stack.matteryEnergy?.extractEnergyInnerExact(ENERGY_PER_SWING, true)?.isPositive == true) {
if (stack.matteryEnergy?.extractEnergyExact(ENERGY_PER_SWING, true) == true) {
return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction)
}

View File

@ -90,11 +90,7 @@ class QuantumBatteryItem : Item {
return LazyOptional.empty()
}
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return extractEnergyInner(howMuch, simulate)
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (howMuch.isNegative) {
return Decimal.ZERO
}
@ -130,11 +126,7 @@ class QuantumBatteryItem : Item {
return diff
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyInner(howMuch, simulate)
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (howMuch.isNegative) {
return Decimal.ZERO
}

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.item.weapon
import net.minecraft.sounds.SoundSource
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.Vector
import ru.dbotthepony.mc.otm.entity.PlasmaProjectile
@ -56,7 +56,7 @@ class PlasmaRifleItem : PlasmaWeaponItem<PlasmaWeaponDataTable>(PlasmaWeaponData
}
override fun canPrimaryFire(itemStack: ItemStack, player: Player, dt: PlasmaWeaponDataTable): Boolean {
return super.canPrimaryFire(itemStack, player, dt) && (player.abilities.instabuild || energyData(itemStack).extractEnergyInnerExact(ENERGY_PER_SHOT, true).isPositive)
return super.canPrimaryFire(itemStack, player, dt) && (player.abilities.instabuild || energyData(itemStack).extractEnergyExact(ENERGY_PER_SHOT, true))
}
companion object {

View File

@ -51,11 +51,11 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
battery = ItemStack.of(nbt["battery"] as CompoundTag)
}
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
return Decimal.ZERO
}
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
if (!howMuch.isPositive)
return Decimal.ZERO
@ -86,11 +86,7 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
return diff + totalExtracted
}
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
return receiveEnergyInner(howMuch, simulate)
}
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
if (!howMuch.isPositive)
return Decimal.ZERO
@ -141,7 +137,7 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
return true
}
override fun emptyBattery() {
override fun drainBattery() {
innerBatteryLevel = Decimal.ZERO
}

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.storage
import it.unimi.dsi.fastutil.objects.ObjectArraySet
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.extractEnergy
import ru.dbotthepony.mc.otm.core.isPositive
import ru.dbotthepony.mc.otm.core.isZero
import java.math.BigInteger
@ -285,7 +286,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
override fun insertStack(stack: T, simulate: Boolean): T {
val required = storageType.energyPerOperation * stack.count
val energy = energyProvider.invoke()
val extracted = energy.extractEnergyInner(required, true)
val extracted = energy.extractEnergy(required, true)
if (extracted.isZero) {
return stack.copy() as T
@ -296,7 +297,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
if (leftover.isEmpty) {
if (!simulate) {
energy.extractEnergyInner(required, false)
energy.extractEnergy(required, false)
}
return leftover
@ -304,7 +305,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
if (!simulate) {
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
energy.extractEnergyInner(requiredNew, false)
energy.extractEnergy(requiredNew, false)
}
return leftover
@ -316,14 +317,14 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
stack.count = (extracted / storageType.energyPerOperation).whole
val diff = oldCount - stack.count
val newRequired = storageType.energyPerOperation * stack.count
val newExtracted = energy.extractEnergyInner(newRequired, true)
val newExtracted = energy.extractEnergy(newRequired, true)
if (newExtracted == newRequired) {
val leftover = parent.insertStack(stack, simulate)
if (leftover.isEmpty) {
if (!simulate) {
energy.extractEnergyInner(newRequired, false)
energy.extractEnergy(newRequired, false)
}
leftover.count = diff
@ -332,7 +333,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
if (!simulate) {
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
energy.extractEnergyInner(requiredNew, false)
energy.extractEnergy(requiredNew, false)
}
leftover.count += diff
@ -347,7 +348,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
override fun extractStack(id: UUID, amount: BigInteger, simulate: Boolean): T {
val required = storageType.energyPerOperation * amount
val energy = energyProvider.invoke()
val extracted = energy.extractEnergyInner(required, true)
val extracted = energy.extractEnergy(required, true)
if (extracted.isZero) {
return storageType.empty
@ -362,9 +363,9 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
if (!simulate) {
if (extractedStack.count == amount) {
energy.extractEnergyInner(required, false)
energy.extractEnergy(required, false)
} else {
energy.extractEnergyInner(storageType.energyPerOperation * extractedStack.count, false)
energy.extractEnergy(storageType.energyPerOperation * extractedStack.count, false)
}
}
@ -380,7 +381,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
}
if (!simulate) {
energy.extractEnergyInner(storageType.energyPerOperation * extractedStack.count, false)
energy.extractEnergy(storageType.energyPerOperation * extractedStack.count, false)
}
return extractedStack