Remove inner/outer variants from IMatteryEnergyStorage
This commit is contained in:
parent
75211f068c
commit
9073ae1b08
@ -30,7 +30,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
|
|||||||
import ru.dbotthepony.mc.otm.android.AndroidActiveFeature
|
import ru.dbotthepony.mc.otm.android.AndroidActiveFeature
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.capability.matteryPlayer
|
||||||
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
|
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
|
||||||
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
||||||
@ -64,7 +64,7 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
get() = ServerConfig.EnderTeleporter.COOLDOWN
|
get() = ServerConfig.EnderTeleporter.COOLDOWN
|
||||||
|
|
||||||
private fun canUse(): Boolean {
|
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 {
|
private fun isValidGround(blockPos: BlockPos): Boolean {
|
||||||
@ -309,7 +309,7 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
|
|
||||||
putOnCooldown()
|
putOnCooldown()
|
||||||
lastTeleport = ply.server!!.tickCount
|
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.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)
|
ply.teleportTo(event.targetX, event.targetY, event.targetZ)
|
||||||
|
@ -13,7 +13,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
|
|||||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
||||||
import ru.dbotthepony.mc.otm.core.Vector
|
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 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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class ItemMagnetFeature(capability: MatteryPlayerCapability) : AndroidSwitchable
|
|||||||
if (data.position.distanceToSqr(ent.position) < 1.0) {
|
if (data.position.distanceToSqr(ent.position) < 1.0) {
|
||||||
data.ticksSinceActivity++
|
data.ticksSinceActivity++
|
||||||
} else {
|
} else {
|
||||||
if (!android.androidEnergy.extractEnergyInnerExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, false).isPositive) {
|
if (!android.androidEnergy.extractEnergyExact(ServerConfig.AndroidItemMagnet.POWER_DRAW, false)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class ItemMagnetFeature(capability: MatteryPlayerCapability) : AndroidSwitchable
|
|||||||
override fun tickClient() {
|
override fun tickClient() {
|
||||||
super.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)
|
doTick(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
|
|||||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.capability.matteryPlayer
|
||||||
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
||||||
import ru.dbotthepony.mc.otm.core.Vector
|
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
|
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()
|
feature.putOnCooldown()
|
||||||
|
|
||||||
context.sender?.let {
|
context.sender?.let {
|
||||||
@ -90,7 +90,7 @@ class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
|||||||
val old = lastGround
|
val old = lastGround
|
||||||
lastGround = ply.isOnGround
|
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)
|
ply.deltaMovement += Vector(0.0, ServerConfig.AndroidJumpBoost.POWER * (level + 1) / 20.0, 0.0)
|
||||||
putOnCooldown()
|
putOnCooldown()
|
||||||
MatteryPlayerNetworkChannel.sendToServer(TriggerJumpBoostPacket)
|
MatteryPlayerNetworkChannel.sendToServer(TriggerJumpBoostPacket)
|
||||||
|
@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
|||||||
import ru.dbotthepony.mc.otm.android.AndroidFeature
|
import ru.dbotthepony.mc.otm.android.AndroidFeature
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||||
import ru.dbotthepony.mc.otm.registry.StatNames
|
import ru.dbotthepony.mc.otm.registry.StatNames
|
||||||
@ -28,12 +28,12 @@ class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(An
|
|||||||
private var layers = 0
|
private var layers = 0
|
||||||
|
|
||||||
override fun tickServer() {
|
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++
|
ticksPassed++
|
||||||
|
|
||||||
if (ticksPassed >= TICKS[speed]) {
|
if (ticksPassed >= TICKS[speed]) {
|
||||||
layers++
|
layers++
|
||||||
android.androidEnergy.extractEnergyInner(ENERGY_PER_LAYER, false)
|
android.androidEnergy.extractEnergy(ENERGY_PER_LAYER, false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ticksPassed = 0
|
ticksPassed = 0
|
||||||
@ -48,7 +48,7 @@ class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(An
|
|||||||
|
|
||||||
if (absorbed > 0.1f) {
|
if (absorbed > 0.1f) {
|
||||||
val powerRequired = ENERGY_PER_HITPOINT * absorbed
|
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 realAbsorbed = (powerExtracted / ENERGY_PER_HITPOINT).toFloat()
|
||||||
|
|
||||||
val ply = ply
|
val ply = ply
|
||||||
|
@ -24,7 +24,7 @@ class NanobotsRegenerationFeature(android: MatteryPlayerCapability) : AndroidFea
|
|||||||
if (ticksPassed > waitTime) {
|
if (ticksPassed > waitTime) {
|
||||||
val missingHealth = (ply.maxHealth - ply.health).coerceAtMost(2f)
|
val missingHealth = (ply.maxHealth - ply.health).coerceAtMost(2f)
|
||||||
val power = ServerConfig.NanobotsRegeneration.ENERGY_PER_HITPOINT * missingHealth
|
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) {
|
if (extracted.isPositive) {
|
||||||
healTicks = (healTicks + 1).coerceAtMost(level)
|
healTicks = (healTicks + 1).coerceAtMost(level)
|
||||||
|
@ -6,7 +6,7 @@ import net.minecraft.world.effect.MobEffects
|
|||||||
import ru.dbotthepony.mc.otm.ServerConfig
|
import ru.dbotthepony.mc.otm.ServerConfig
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.client.render.ResearchIcons
|
||||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||||
|
|
||||||
@ -18,12 +18,8 @@ class NightVisionFeature(android: MatteryPlayerCapability) : AndroidSwitchableFe
|
|||||||
if (isActive) {
|
if (isActive) {
|
||||||
val effect = android.ply.activeEffectsMap[MobEffects.NIGHT_VISION]
|
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))
|
android.ply.addEffect(MobEffectInstance(MobEffects.NIGHT_VISION, 220, 0, false, false))
|
||||||
|
|
||||||
if (!ply.isSpectator) {
|
|
||||||
android.androidEnergy.extractEnergyInner(ServerConfig.NIGHT_VISION_POWER_DRAW, false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.ServerConfig
|
|||||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
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.client.render.ResearchIcons
|
||||||
import ru.dbotthepony.mc.otm.core.Vector
|
import ru.dbotthepony.mc.otm.core.Vector
|
||||||
import ru.dbotthepony.mc.otm.core.formatPower
|
import ru.dbotthepony.mc.otm.core.formatPower
|
||||||
@ -83,7 +83,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
|||||||
isActive &&
|
isActive &&
|
||||||
ply.isShiftKeyDown &&
|
ply.isShiftKeyDown &&
|
||||||
!isOnCooldown &&
|
!isOnCooldown &&
|
||||||
android.androidEnergy.extractEnergyInnerExact(ServerConfig.Shockwave.ENERGY_COST, true).isPositive &&
|
android.androidEnergy.extractEnergyExact(ServerConfig.Shockwave.ENERGY_COST, true) &&
|
||||||
ply.deltaMovement.y < -0.01 &&
|
ply.deltaMovement.y < -0.01 &&
|
||||||
creativeFlightTicks == 0
|
creativeFlightTicks == 0
|
||||||
) {
|
) {
|
||||||
@ -94,7 +94,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun shockwave() {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class ShockwaveFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
|||||||
!ply.isSpectator &&
|
!ply.isSpectator &&
|
||||||
isActive &&
|
isActive &&
|
||||||
!isOnCooldown &&
|
!isOnCooldown &&
|
||||||
android.androidEnergy.extractEnergyInnerExact(ServerConfig.Shockwave.ENERGY_COST, true).isPositive &&
|
android.androidEnergy.extractEnergyExact(ServerConfig.Shockwave.ENERGY_COST, true) &&
|
||||||
creativeFlightTicks == 0
|
creativeFlightTicks == 0
|
||||||
) {
|
) {
|
||||||
val old = wasMidair
|
val old = wasMidair
|
||||||
|
@ -88,7 +88,7 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
val extract = energy.extractEnergyInner(missing, true)
|
val extract = energy.extractEnergyInner(missing, true)
|
||||||
|
|
||||||
if (extract > Decimal.ZERO) {
|
if (extract > Decimal.ZERO) {
|
||||||
val received = it.androidEnergy.receiveEnergyOuter(extract, false)
|
val received = it.androidEnergy.receiveEnergy(extract, false)
|
||||||
energy.extractEnergyInner(received, false)
|
energy.extractEnergyInner(received, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
|
|||||||
override fun canExtract() = mode != BankMode.RECEIVE
|
override fun canExtract() = mode != BankMode.RECEIVE
|
||||||
override fun canReceive() = mode != BankMode.EXTRACT
|
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)
|
if (mode == BankMode.RECEIVE)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -157,18 +157,18 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
|
|||||||
return summ
|
return summ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return distributeEnergy(isReceiving = false, howMuch, simulate)
|
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)
|
if (mode == BankMode.EXTRACT)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
return receiveEnergyInner(howMuch, simulate)
|
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)
|
return distributeEnergy(isReceiving = true, howMuch, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +127,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inner class EnergyCounterCap(val isInput: Boolean) : IMatteryEnergyStorage {
|
private inner class EnergyCounterCap(val isInput: Boolean) : IMatteryEnergyStorage {
|
||||||
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (isInput)
|
if (isInput)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -159,11 +155,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
|
|||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (!isInput)
|
if (!isInput)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
|
@ -59,19 +59,11 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
|
|||||||
})
|
})
|
||||||
|
|
||||||
val energy = object : IMatteryEnergyStorage {
|
val energy = object : IMatteryEnergyStorage {
|
||||||
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
return container[SLOT_DISCHARGE].energy?.extractEnergy(howMuch, simulate) ?: Decimal.ZERO
|
return container[SLOT_DISCHARGE].energy?.extractEnergy(howMuch, simulate) ?: Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
return container[SLOT_CHARGE].energy?.receiveEnergy(howMuch, simulate) ?: Decimal.ZERO
|
return container[SLOT_CHARGE].energy?.receiveEnergy(howMuch, simulate) ?: Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ abstract class MatteryPoweredBlockEntity(p_155228_: BlockEntityType<*>, p_155229
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var demand = energy.receiveEnergyOuter(energy.missingPower, true)
|
var demand = energy.receiveEnergy(energy.missingPower, true)
|
||||||
if (demand.isZero) return
|
if (demand.isZero) return
|
||||||
|
|
||||||
for (stack in batteryContainer) {
|
for (stack in batteryContainer) {
|
||||||
if (!stack.isEmpty) {
|
if (!stack.isEmpty) {
|
||||||
stack.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
stack.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
||||||
if (it is IMatteryEnergyStorage) {
|
if (it is IMatteryEnergyStorage) {
|
||||||
val diff = it.extractEnergyOuter(demand, false)
|
val diff = it.extractEnergy(demand, false)
|
||||||
energy.receiveEnergyInner(diff, false)
|
energy.receiveEnergyInner(diff, false)
|
||||||
demand -= diff
|
demand -= diff
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,8 +23,6 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.*
|
import ru.dbotthepony.mc.otm.capability.*
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
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.container.ItemFilter
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
|
@ -18,7 +18,6 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
||||||
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.energy.transferInner
|
|
||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode
|
import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph
|
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)
|
val available = energy.batteryLevel.coerceAtMost(ServerConfig.STORAGE_POWER_SUPPLIER.throughput)
|
||||||
|
|
||||||
for (demanding in graph.powerDemandingNodes) {
|
for (demanding in graph.powerDemandingNodes) {
|
||||||
val received = demanding.receiveEnergyOuter(available, true)
|
val received = demanding.receiveEnergy(available, true)
|
||||||
|
|
||||||
if (received.isPositive) {
|
if (received.isPositive) {
|
||||||
demand += received
|
demand += received
|
||||||
|
@ -32,7 +32,7 @@ val ICapabilityProvider.matteryPlayer: MatteryPlayerCapability? get() = getCapab
|
|||||||
|
|
||||||
fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): Decimal {
|
fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): Decimal {
|
||||||
if (this is IMatteryEnergyStorage)
|
if (this is IMatteryEnergyStorage)
|
||||||
return receiveEnergyOuter(amount, simulate)
|
return receiveEnergy(amount, simulate)
|
||||||
|
|
||||||
if (!amount.isPositive)
|
if (!amount.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
@ -45,7 +45,7 @@ fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): Decimal {
|
|||||||
|
|
||||||
fun IEnergyStorage.extractEnergy(amount: Decimal, simulate: Boolean): Decimal {
|
fun IEnergyStorage.extractEnergy(amount: Decimal, simulate: Boolean): Decimal {
|
||||||
if (this is IMatteryEnergyStorage)
|
if (this is IMatteryEnergyStorage)
|
||||||
return extractEnergyOuter(amount, simulate)
|
return extractEnergy(amount, simulate)
|
||||||
|
|
||||||
if (!amount.isPositive)
|
if (!amount.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
@ -778,16 +778,16 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
|||||||
if (!ply.isSpectator) {
|
if (!ply.isSpectator) {
|
||||||
val stats = ply.foodData
|
val stats = ply.foodData
|
||||||
|
|
||||||
while (stats.foodLevel < 18 && androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
|
while (stats.foodLevel < 18 && androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
|
||||||
androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
|
androidEnergy.extractEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
|
||||||
stats.foodLevel = stats.foodLevel + 1
|
stats.foodLevel = stats.foodLevel + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// "block" quick regeneration
|
// "block" quick regeneration
|
||||||
// also cause power to generate while in peaceful
|
// also cause power to generate while in peaceful
|
||||||
if (ServerConfig.REGENERATE_ENERGY) {
|
if (ServerConfig.REGENERATE_ENERGY) {
|
||||||
while (stats.foodLevel > 18 && androidEnergy.receiveEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
|
while (stats.foodLevel > 18 && androidEnergy.receiveEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
|
||||||
androidEnergy.receiveEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
|
androidEnergy.receiveEnergy(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, false)
|
||||||
stats.foodLevel = stats.foodLevel - 1
|
stats.foodLevel = stats.foodLevel - 1
|
||||||
}
|
}
|
||||||
} else if (ply.level.server?.worldData?.difficulty != Difficulty.PEACEFUL) {
|
} 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()
|
val foodLevel = stats.foodLevel.toFloat()
|
||||||
|
|
||||||
if (stats.saturationLevel < foodLevel) {
|
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())
|
stats.setSaturation(stats.saturationLevel + (extracted / ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT).toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats.exhaustionLevel > 0f) {
|
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)
|
stats.setExhaustion(stats.exhaustionLevel - (extracted / ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT).toFloat() * 4f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,47 +51,29 @@ class AndroidPowerSource(
|
|||||||
fun tick() {
|
fun tick() {
|
||||||
if (!item.isEmpty && battery < maxBattery) {
|
if (!item.isEmpty && battery < maxBattery) {
|
||||||
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
||||||
if (it is IMatteryEnergyStorage) {
|
battery += it.extractEnergy(maxBattery - battery, false)
|
||||||
battery += it.extractEnergyInner(maxBattery - battery, false)
|
|
||||||
} else {
|
|
||||||
battery += it.extractEnergy(maxBattery - battery, false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(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 {
|
|
||||||
@Suppress("name_shadowing")
|
@Suppress("name_shadowing")
|
||||||
var howMuch = howMuch
|
var howMuch = howMuch
|
||||||
var drained = Decimal.ZERO
|
var drained = Decimal.ZERO
|
||||||
|
|
||||||
if (!item.isEmpty) {
|
if (!item.isEmpty) {
|
||||||
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
||||||
if (it is IMatteryEnergyStorage) {
|
val extracted = it.extractEnergy(howMuch, simulate)
|
||||||
val extracted = it.extractEnergyOuter(howMuch, simulate)
|
drained += extracted
|
||||||
drained += extracted
|
howMuch -= extracted
|
||||||
howMuch -= extracted
|
|
||||||
} else {
|
|
||||||
val extracted = it.extractEnergy(howMuch, simulate)
|
|
||||||
drained += extracted
|
|
||||||
howMuch -= extracted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (howMuch.isZero) {
|
if (howMuch.isZero) {
|
||||||
if (!simulate && ply is ServerPlayer) {
|
if (!simulate && ply is ServerPlayer) {
|
||||||
ply.awardStat(StatNames.POWER_CONSUMED, drained.toInt() * 10)
|
ply.awardStat(StatNames.POWER_CONSUMED, drained.toInt() * 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
return drained
|
return drained
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +91,7 @@ class AndroidPowerSource(
|
|||||||
return drained
|
return drained
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
@Suppress("name_shadowing")
|
@Suppress("name_shadowing")
|
||||||
var howMuch = howMuch
|
var howMuch = howMuch
|
||||||
var received = Decimal.ZERO
|
var received = Decimal.ZERO
|
||||||
@ -117,7 +99,7 @@ class AndroidPowerSource(
|
|||||||
if (!item.isEmpty) {
|
if (!item.isEmpty) {
|
||||||
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
item.getCapability(ForgeCapabilities.ENERGY).ifPresentK {
|
||||||
if (it is IMatteryEnergyStorage) {
|
if (it is IMatteryEnergyStorage) {
|
||||||
val extracted = it.receiveEnergyOuter(howMuch, simulate)
|
val extracted = it.receiveEnergy(howMuch, simulate)
|
||||||
received += extracted
|
received += extracted
|
||||||
howMuch -= extracted
|
howMuch -= extracted
|
||||||
} else {
|
} else {
|
||||||
|
@ -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)
|
if (direction == FlowDirection.INPUT)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
return extractEnergyInner(howMuch, simulate)
|
return extractEnergyInner(howMuch, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
if (direction == FlowDirection.OUTPUT)
|
if (direction == FlowDirection.OUTPUT)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
|
@ -7,11 +7,82 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|||||||
import ru.dbotthepony.mc.otm.core.Decimal
|
import ru.dbotthepony.mc.otm.core.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.formatPower
|
import ru.dbotthepony.mc.otm.core.formatPower
|
||||||
|
import java.math.BigInteger
|
||||||
|
|
||||||
sealed interface IEnergyStorageImpl {
|
sealed interface IEnergyStorageImpl {
|
||||||
val maxInput: Decimal?
|
val maxInput: Decimal?
|
||||||
val maxOutput: Decimal?
|
val maxOutput: Decimal?
|
||||||
val direction: FlowDirection
|
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>) {
|
internal fun batteryLevel(it: IEnergyStorage, tooltips: MutableList<Component>) {
|
||||||
@ -97,6 +168,8 @@ internal fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compo
|
|||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlowDirection.NONE -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,41 +6,23 @@ import ru.dbotthepony.mc.otm.core.RGBAColor
|
|||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import kotlin.math.roundToInt
|
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 {
|
interface IMatteryEnergyStorage : IEnergyStorage {
|
||||||
/**
|
/**
|
||||||
* Energy extraction by external interacts
|
* Energy extraction by external interacts
|
||||||
*
|
*
|
||||||
* @return energy extracted
|
* @return energy extracted
|
||||||
*/
|
*/
|
||||||
fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun extractEnergy(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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Energy insertion by external interacts
|
* Energy insertion by external interacts
|
||||||
*
|
*
|
||||||
* @return energy accepted
|
* @return energy accepted
|
||||||
*/
|
*/
|
||||||
fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun receiveEnergy(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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this is false, then [batteryLevel] will throw [UnsupportedOperationException] when trying to set it
|
* 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
|
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
|
* Implementations are free to throw [UnsupportedOperationException] if setting battery level is not supported
|
||||||
* due to technical complications (in this case, [canSetBatteryLevel] MUST be false)
|
* due to technical complications (in this case, [canSetBatteryLevel] MUST be false)
|
||||||
*
|
*
|
||||||
* @throws [UnsupportedOperationException]
|
* @throws [UnsupportedOperationException]
|
||||||
*/
|
*/
|
||||||
var batteryLevel: Decimal
|
var batteryLevel: Decimal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How much energy (estimated) can this energy storage hold. Why estimated? Because some objects can be bottomless.
|
||||||
|
*/
|
||||||
val maxBatteryLevel: Decimal
|
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
|
val missingPower: Decimal
|
||||||
get() = (maxBatteryLevel - batteryLevel).moreThanZero()
|
get() = (maxBatteryLevel - batteryLevel).moreThanZero()
|
||||||
|
|
||||||
@ -64,7 +58,7 @@ interface IMatteryEnergyStorage : IEnergyStorage {
|
|||||||
* @throws [UnsupportedOperationException]
|
* @throws [UnsupportedOperationException]
|
||||||
* @see batteryLevel
|
* @see batteryLevel
|
||||||
*/
|
*/
|
||||||
fun emptyBattery() {
|
fun drainBattery() {
|
||||||
batteryLevel = Decimal.ZERO
|
batteryLevel = Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,24 +72,26 @@ interface IMatteryEnergyStorage : IEnergyStorage {
|
|||||||
batteryLevel = maxBatteryLevel
|
batteryLevel = maxBatteryLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- Forge Energy stuff
|
||||||
|
|
||||||
override fun receiveEnergy(maxReceive: Int, simulate: Boolean): Int {
|
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
|
// Receiving only a fraction
|
||||||
if (received == 0)
|
if (received == 0)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return receiveEnergyOuter(Decimal(received), simulate).toInt()
|
return receiveEnergy(Decimal(received), simulate).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergy(maxReceive: Int, simulate: Boolean): Int {
|
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
|
// Extracting only a fraction
|
||||||
if (extracted == 0)
|
if (extracted == 0)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return extractEnergyOuter(Decimal(extracted), simulate).toInt()
|
return extractEnergy(Decimal(extracted), simulate).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEnergyStored(): Int {
|
override fun getEnergyStored(): Int {
|
||||||
@ -107,172 +103,82 @@ interface IMatteryEnergyStorage : IEnergyStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun canExtract(): Boolean {
|
override fun canExtract(): Boolean {
|
||||||
return extractEnergyOuter(Decimal.ONE, true) > Decimal.ZERO
|
return extractEnergy(Decimal.ONE, true) > Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canReceive(): Boolean {
|
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 {
|
fun IMatteryEnergyStorage.extractEnergyExact(howMuch: Decimal, simulate: Boolean): Boolean {
|
||||||
val extracted = receiveEnergyOuter(howMuch, true)
|
if (extractEnergy(howMuch, true) == howMuch) {
|
||||||
|
if (!simulate) {
|
||||||
|
return extractEnergy(howMuch, false) == howMuch
|
||||||
|
}
|
||||||
|
|
||||||
if (extracted != howMuch) {
|
return true
|
||||||
return Decimal.ZERO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!simulate) {
|
return false
|
||||||
receiveEnergyOuter(howMuch, false)
|
}
|
||||||
|
|
||||||
|
fun IMatteryEnergyStorage.receiveEnergyExact(howMuch: Decimal, simulate: Boolean): Boolean {
|
||||||
|
if (receiveEnergy(howMuch, true) == howMuch) {
|
||||||
|
if (!simulate) {
|
||||||
|
return receiveEnergy(howMuch, false) == howMuch
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return extracted
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!simulate) {
|
|
||||||
extractEnergyOuter(howMuch, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun IMatteryEnergyStorage.extractEnergyExact(howMuch: Decimal, times: Int, simulate: Boolean): Int {
|
||||||
* All or nothing
|
if (times == 0)
|
||||||
*
|
return 0
|
||||||
* @return energy accepted
|
|
||||||
*/
|
|
||||||
fun IMatteryEnergyStorage.receiveEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
val extracted = receiveEnergyInner(howMuch, true)
|
|
||||||
|
|
||||||
if (extracted != howMuch) {
|
require(times >= 0) { "times $times >= 0" }
|
||||||
return Decimal.ZERO
|
require(howMuch >= Decimal.ZERO) { "howMuch $howMuch >= 0" }
|
||||||
}
|
return (extractEnergy(howMuch * times, simulate) / times).toInt()
|
||||||
|
|
||||||
if (!simulate) {
|
|
||||||
receiveEnergyInner(howMuch, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun IMatteryEnergyStorage.extractEnergy(howMuch: Long, simulate: Boolean): Decimal {
|
||||||
* All or nothing
|
return extractEnergy(Decimal(howMuch), simulate)
|
||||||
*
|
|
||||||
* @return energy extracted
|
|
||||||
*/
|
|
||||||
fun IMatteryEnergyStorage.extractEnergyInnerExact(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
val extracted = extractEnergyInner(howMuch, true)
|
|
||||||
|
|
||||||
if (extracted != howMuch) {
|
|
||||||
return Decimal.ZERO
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!simulate) {
|
|
||||||
extractEnergyInner(howMuch, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IMatteryEnergyStorage.extractEnergyOuter(howMuch: Long, simulate: Boolean): Decimal {
|
fun IMatteryEnergyStorage.receiveEnergy(howMuch: Long, simulate: Boolean): Decimal {
|
||||||
return extractEnergyOuter(Decimal(howMuch), simulate)
|
return receiveEnergy(Decimal(howMuch), simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IMatteryEnergyStorage.extractEnergyOuter(howMuch: Int, simulate: Boolean): Decimal {
|
fun IMatteryEnergyStorage.transfer(other: IMatteryEnergyStorage, amount: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractEnergyOuter(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 {
|
|
||||||
if (!amount.isPositive)
|
if (!amount.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
val extracted = extractEnergyInner(amount, true)
|
val extracted = extractEnergy(amount, true)
|
||||||
val received = other.receiveEnergyOuter(extracted, simulate)
|
val received = other.receiveEnergy(extracted, simulate)
|
||||||
|
|
||||||
if (!simulate)
|
if (!simulate)
|
||||||
extractEnergyInner(received, false)
|
extractEnergy(received, false)
|
||||||
|
|
||||||
return received
|
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 {
|
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 {
|
fun IMatteryEnergyStorage.extractStepOuter(base: Decimal, multiplier: Int, simulate: Boolean): Int {
|
||||||
return (extractEnergyInner(base * multiplier, simulate) / base).whole
|
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 {
|
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 {
|
fun IMatteryEnergyStorage.getBarWidth(): Int {
|
||||||
|
@ -55,14 +55,14 @@ sealed class ItemEnergyStorageImpl(
|
|||||||
itemStack.tagNotNull[ENERGY_KEY] = value.serializeNBT()
|
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)
|
if (direction == FlowDirection.INPUT)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
return extractEnergyInner(howMuch, simulate)
|
return extractEnergyInner(howMuch, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
if (direction == FlowDirection.OUTPUT)
|
if (direction == FlowDirection.OUTPUT)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ interface IMatterStorage {
|
|||||||
val canSetMatterLevel: Boolean get() = true
|
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
|
* Implementations are free to throw [UnsupportedOperationException] if setting battery level is not supported
|
||||||
* due to technical complications (in this case, [canSetMatterLevel] MUST be false)
|
* due to technical complications (in this case, [canSetMatterLevel] MUST be false)
|
||||||
@ -30,7 +30,7 @@ interface IMatterStorage {
|
|||||||
var storedMatter: Decimal
|
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!**
|
* **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
|
fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract matter from this object
|
* Extract matter from this matter storage
|
||||||
*
|
*
|
||||||
* @return matter extracted
|
* @return matter extracted
|
||||||
*/
|
*/
|
||||||
fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal
|
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
|
val missingMatter: Decimal
|
||||||
get() = maxStoredMatter.minus(storedMatter).moreThanZero()
|
get() = maxStoredMatter.minus(storedMatter).moreThanZero()
|
||||||
|
@ -72,7 +72,7 @@ private val mtj2Mekanism by DoubleLazy lazy@{
|
|||||||
|
|
||||||
class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, private val forgePower: IEnergyStorage? = null) :
|
class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, private val forgePower: IEnergyStorage? = null) :
|
||||||
IMatteryEnergyStorage {
|
IMatteryEnergyStorage {
|
||||||
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
val action = when (simulate) {
|
val action = when (simulate) {
|
||||||
true -> Action.SIMULATE
|
true -> Action.SIMULATE
|
||||||
false -> Action.EXECUTE
|
false -> Action.EXECUTE
|
||||||
@ -81,11 +81,7 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
return power.extractEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
|
return power.extractEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractEnergyOuter(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
val action = when (simulate) {
|
val action = when (simulate) {
|
||||||
true -> Action.SIMULATE
|
true -> Action.SIMULATE
|
||||||
false -> Action.EXECUTE
|
false -> Action.EXECUTE
|
||||||
@ -94,10 +90,6 @@ class Mekanism2MatteryEnergyWrapper(private val power: IStrictEnergyHandler, pri
|
|||||||
return howMuch - power.insertEnergy((howMuch * mtj2Mekanism).toFloatingLong(), action).toDecimal() * mekanism2MtJ
|
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
|
override val canSetBatteryLevel: Boolean
|
||||||
get() = power.energyContainerCount == 1
|
get() = power.energyContainerCount == 1
|
||||||
|
|
||||||
@ -177,11 +169,11 @@ class Mattery2MekanismEnergyWrapper(private val power: IMatteryEnergyStorage) :
|
|||||||
|
|
||||||
override fun insertEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
override fun insertEnergy(container: Int, howMuch: FloatingLong, action: Action): FloatingLong {
|
||||||
val copy = howMuch.copy()
|
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 {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.EnergyConsumerItem
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
|
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
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.getBarColor
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.getBarWidth
|
import ru.dbotthepony.mc.otm.capability.energy.getBarWidth
|
||||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||||
@ -49,7 +49,7 @@ import ru.dbotthepony.mc.otm.core.WriteOnce
|
|||||||
* by coremod patch
|
* by coremod patch
|
||||||
*/
|
*/
|
||||||
fun getSweepingDamageRatioHook(ply: LivingEntity): Float? {
|
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
|
return 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,10 +122,10 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
|
|||||||
}
|
}
|
||||||
|
|
||||||
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
|
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
|
||||||
if (!it.extractEnergyInnerExact(ENERGY_PER_SWING, false).isZero) {
|
if (it.extractEnergyExact(ENERGY_PER_SWING, false)) {
|
||||||
victim.matteryPlayer?.let {
|
victim.matteryPlayer?.let {
|
||||||
if (it.isAndroid) {
|
if (it.isAndroid) {
|
||||||
it.androidEnergy.extractEnergyInner(ENERGY_ZAP, false)
|
it.androidEnergy.extractEnergy(ENERGY_ZAP, false)
|
||||||
victim.hurt(EMPDamageSource(attacker), 8f)
|
victim.hurt(EMPDamageSource(attacker), 8f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,11 +175,11 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
|
|||||||
|
|
||||||
when (blockState.material) {
|
when (blockState.material) {
|
||||||
Material.PLANT, Material.REPLACEABLE_PLANT, Material.VEGETABLE, Material.LEAVES ->
|
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)) {
|
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 {
|
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)
|
return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +90,7 @@ class QuantumBatteryItem : Item {
|
|||||||
return LazyOptional.empty()
|
return LazyOptional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (howMuch.isNegative) {
|
if (howMuch.isNegative) {
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
}
|
}
|
||||||
@ -130,11 +126,7 @@ class QuantumBatteryItem : Item {
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (howMuch.isNegative) {
|
if (howMuch.isNegative) {
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.item.weapon
|
|||||||
import net.minecraft.sounds.SoundSource
|
import net.minecraft.sounds.SoundSource
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.item.ItemStack
|
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.*
|
||||||
import ru.dbotthepony.mc.otm.core.Vector
|
import ru.dbotthepony.mc.otm.core.Vector
|
||||||
import ru.dbotthepony.mc.otm.entity.PlasmaProjectile
|
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 {
|
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 {
|
companion object {
|
||||||
|
@ -51,11 +51,11 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
|
|||||||
battery = ItemStack.of(nbt["battery"] as CompoundTag)
|
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
|
return Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
fun extractEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
if (!howMuch.isPositive)
|
if (!howMuch.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -86,11 +86,7 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
|
|||||||
return diff + totalExtracted
|
return diff + totalExtracted
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergyOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveEnergyInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveEnergyInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (!howMuch.isPositive)
|
if (!howMuch.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -141,7 +137,7 @@ class PlasmaWeaponEnergy(val itemStack: ItemStack, private val innerCapacity: De
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun emptyBattery() {
|
override fun drainBattery() {
|
||||||
innerBatteryLevel = Decimal.ZERO
|
innerBatteryLevel = Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.storage
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
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.isPositive
|
||||||
import ru.dbotthepony.mc.otm.core.isZero
|
import ru.dbotthepony.mc.otm.core.isZero
|
||||||
import java.math.BigInteger
|
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 {
|
override fun insertStack(stack: T, simulate: Boolean): T {
|
||||||
val required = storageType.energyPerOperation * stack.count
|
val required = storageType.energyPerOperation * stack.count
|
||||||
val energy = energyProvider.invoke()
|
val energy = energyProvider.invoke()
|
||||||
val extracted = energy.extractEnergyInner(required, true)
|
val extracted = energy.extractEnergy(required, true)
|
||||||
|
|
||||||
if (extracted.isZero) {
|
if (extracted.isZero) {
|
||||||
return stack.copy() as T
|
return stack.copy() as T
|
||||||
@ -296,7 +297,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
|
|||||||
|
|
||||||
if (leftover.isEmpty) {
|
if (leftover.isEmpty) {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
energy.extractEnergyInner(required, false)
|
energy.extractEnergy(required, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return leftover
|
return leftover
|
||||||
@ -304,7 +305,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
|
|||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
|
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
|
||||||
energy.extractEnergyInner(requiredNew, false)
|
energy.extractEnergy(requiredNew, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return leftover
|
return leftover
|
||||||
@ -316,14 +317,14 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
|
|||||||
stack.count = (extracted / storageType.energyPerOperation).whole
|
stack.count = (extracted / storageType.energyPerOperation).whole
|
||||||
val diff = oldCount - stack.count
|
val diff = oldCount - stack.count
|
||||||
val newRequired = storageType.energyPerOperation * stack.count
|
val newRequired = storageType.energyPerOperation * stack.count
|
||||||
val newExtracted = energy.extractEnergyInner(newRequired, true)
|
val newExtracted = energy.extractEnergy(newRequired, true)
|
||||||
|
|
||||||
if (newExtracted == newRequired) {
|
if (newExtracted == newRequired) {
|
||||||
val leftover = parent.insertStack(stack, simulate)
|
val leftover = parent.insertStack(stack, simulate)
|
||||||
|
|
||||||
if (leftover.isEmpty) {
|
if (leftover.isEmpty) {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
energy.extractEnergyInner(newRequired, false)
|
energy.extractEnergy(newRequired, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
leftover.count = diff
|
leftover.count = diff
|
||||||
@ -332,7 +333,7 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
|
|||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
|
val requiredNew = storageType.energyPerOperation * (stack.count - leftover.count)
|
||||||
energy.extractEnergyInner(requiredNew, false)
|
energy.extractEnergy(requiredNew, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
leftover.count += diff
|
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 {
|
override fun extractStack(id: UUID, amount: BigInteger, simulate: Boolean): T {
|
||||||
val required = storageType.energyPerOperation * amount
|
val required = storageType.energyPerOperation * amount
|
||||||
val energy = energyProvider.invoke()
|
val energy = energyProvider.invoke()
|
||||||
val extracted = energy.extractEnergyInner(required, true)
|
val extracted = energy.extractEnergy(required, true)
|
||||||
|
|
||||||
if (extracted.isZero) {
|
if (extracted.isZero) {
|
||||||
return storageType.empty
|
return storageType.empty
|
||||||
@ -362,9 +363,9 @@ open class PoweredComponent<T : IStorageStack>(open val parent: IStorageComponen
|
|||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
if (extractedStack.count == amount) {
|
if (extractedStack.count == amount) {
|
||||||
energy.extractEnergyInner(required, false)
|
energy.extractEnergy(required, false)
|
||||||
} else {
|
} 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) {
|
if (!simulate) {
|
||||||
energy.extractEnergyInner(storageType.energyPerOperation * extractedStack.count, false)
|
energy.extractEnergy(storageType.energyPerOperation * extractedStack.count, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractedStack
|
return extractedStack
|
||||||
|
Loading…
Reference in New Issue
Block a user