From 9b922212219be449e4353387274a73b60f3912ff Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 14 Mar 2023 20:56:46 +0700 Subject: [PATCH 1/3] HOLY SHIT --- .../mc/otm/block/entity/tech/BatteryBankBlockEntity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt index 2c5d49e64..5d64f1744 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt @@ -102,7 +102,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte var summ2 = Decimal.ZERO for ((i, energy) in energies.withIndex()) { - val diff = energy.transcieveEnergy(howMuch, isReceiving, simulate) + val diff = energy.transcieveEnergy(howMuch, isReceiving, true) distribution[i] = diff summ2 += distribution[i] } From 9b270b6891ec152ceefa1c99a054aaeb5015959b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 14 Mar 2023 21:38:05 +0700 Subject: [PATCH 2/3] Division free energy distribution in battery bank --- .../entity/tech/BatteryBankBlockEntity.kt | 111 ++++++------------ 1 file changed, 38 insertions(+), 73 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt index 5d64f1744..21a3300ec 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt @@ -7,16 +7,13 @@ import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.item.ItemStack import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.ForgeCapabilities -import net.minecraftforge.energy.IEnergyStorage import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.energy import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage import ru.dbotthepony.mc.otm.capability.energyStoredMattery -import ru.dbotthepony.mc.otm.capability.extractEnergy import ru.dbotthepony.mc.otm.capability.matteryEnergy import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery -import ru.dbotthepony.mc.otm.capability.receiveEnergy import ru.dbotthepony.mc.otm.capability.transcieveEnergy import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer @@ -53,94 +50,56 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte bottomDefault = ItemHandlerMode.INPUT_OUTPUT, ) + private var currentChangeSlot = 0 + private var currentDischangeSlot = 0 + init { savetable(::container, INVENTORY_KEY) + savetables.int(::currentChangeSlot) + savetables.int(::currentDischangeSlot) } private fun distributeEnergy(isReceiving: Boolean, howMuch: Decimal, simulate: Boolean): Decimal { if (!howMuch.isPositive) return Decimal.ZERO - val energies = ArrayList() + var summ = Decimal.ZERO + var remaining = howMuch + var currentSlot = if (isReceiving) currentChangeSlot else currentDischangeSlot + + for (i in 0 until container.containerSize - 1) { + val item = container[currentSlot] - for (item in container) { if (!item.isEmpty) { val energy = item.matteryEnergy ?: item.energy if (energy != null) { - energies.add(energy) + val diff = energy.transcieveEnergy(remaining, isReceiving, simulate) + summ += diff + remaining -= diff + + if (!remaining.isPositive) { + break + } } } + + currentSlot = (currentSlot + 1) % container.containerSize } - if (energies.isEmpty()) - return Decimal.ZERO - - if (howMuch.toInt() < energies.size || !energies.any { it is IMatteryEnergyStorage && it.transcieveEnergy(Decimal.ONE, isReceiving, true) == Decimal.ONE }) { - // sequential - var summ = Decimal.ZERO - var remaining = howMuch - - for (energy in energies) { - val diff = energy.transcieveEnergy(remaining, isReceiving, simulate) - summ += diff - remaining -= diff - - if (!remaining.isPositive) { - break - } - } - - if (!simulate && !summ.isZero) { - setChangedLight() - gaugeLevel = (batteryLevel / maxBatteryLevel).toFloat() - } - - return summ - } else { - val distribution = Array(energies.size) { Decimal.ZERO } - var summ2 = Decimal.ZERO - - for ((i, energy) in energies.withIndex()) { - val diff = energy.transcieveEnergy(howMuch, isReceiving, true) - distribution[i] = diff - summ2 += distribution[i] - } - - if (summ2.isPositive) { - for (i in distribution.indices) { - distribution[i] = distribution[i] / summ2 - } - } else { - return Decimal.ZERO - } - - var summ = Decimal.ZERO - var remaining = howMuch - - for ((i, energy) in energies.withIndex()) { - val diff = energy.transcieveEnergy((howMuch * distribution[i]).coerceAtMost(remaining), isReceiving, simulate) - summ += diff - remaining -= diff - - if (!remaining.isPositive) { - break - } - } - - if (remaining.isPositive) { - val diff = energies.first { it is IMatteryEnergyStorage }.transcieveEnergy(remaining, isReceiving, simulate) - summ += diff - remaining -= diff - } - - if (!simulate && !summ.isZero) { - setChangedLight() - gaugeLevel = (batteryLevel / maxBatteryLevel).toFloat() - } - - return summ + if (!simulate && !summ.isZero) { + setChangedLight() + gaugeLevel = (batteryLevel / maxBatteryLevel).toFloat() } + + if (!simulate) { + if (isReceiving) + this.currentChangeSlot = currentSlot + else + this.currentDischangeSlot = currentSlot + } + + return summ } override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal { @@ -151,6 +110,12 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte return distributeEnergy(isReceiving = true, howMuch, simulate) } + override fun tick() { + super.tick() + currentChangeSlot = (currentChangeSlot + 1) % container.containerSize + currentDischangeSlot = (currentDischangeSlot + 1) % container.containerSize + } + override val canSetBatteryLevel: Boolean get() = false From 5ecfc99533eadef673455c78a75970b2a734b5ef Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Tue, 14 Mar 2023 18:09:46 +0300 Subject: [PATCH 3/3] =?UTF-8?q?DBotThePony=20=E2=80=94=20=D0=A1=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=D0=B4=D0=BD=D1=8F,=20=D0=B2=2017:11=20=D0=B0=D1=85?= =?UTF-8?q?=20=D0=B4=D0=B0=20=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=B8=D0=B7=D1=83=D0=B0=D0=BB=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B1=D1=80=D0=BE=D0=BD=D0=B8=20=D0=BD=D0=B0=D0=BD=D0=BE=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=20=D1=82=D0=B0=D0=BA=20=D1=82=D1=8B?= =?UTF-8?q?=D0=B6=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BE=D1=81=D0=BA=D1=83=20=D1=85=D0=BF,=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=20=D1=82=D1=83=D0=B4=D0=B0=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B1=D0=BE=D1=82=D0=BE=D0=B2=20=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BF=D0=B8=D1=82=D1=8C=20:Pogomega:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/feature/NanobotsArmorFeature.kt | 9 ++++--- .../dbotthepony/mc/otm/client/MatteryGUI.kt | 25 +++++++++++++----- .../textures/gui/player_bars_health.png | Bin 292 -> 325 bytes 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/NanobotsArmorFeature.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/NanobotsArmorFeature.kt index 4ecedb8c3..168b402a8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/NanobotsArmorFeature.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/NanobotsArmorFeature.kt @@ -18,14 +18,17 @@ import ru.dbotthepony.mc.otm.triggers.NanobotsArmorTrigger import kotlin.math.roundToInt class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.NANOBOTS_ARMOR, android) { - var strength: Int = 0 - set(value) { field = value.coerceIn(0 .. 3) } + var strength by synchronizer.int( + setter = setter@{ + value, access, _ -> access.write(value.coerceIn(0 .. 3)) + } + ) var speed: Int = 0 set(value) { field = value.coerceIn(0 .. 3) } private var ticksPassed = 0 - private var layers = 0 + var layers by synchronizer.int() override fun tickServer() { if (layers < strength + 1 && android.androidEnergy.extractEnergyExact(ENERGY_PER_LAYER, true)) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt index 73e5a3a36..0d7607c15 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt @@ -16,6 +16,7 @@ import net.minecraftforge.client.event.ScreenEvent import net.minecraftforge.client.gui.overlay.ForgeGui import net.minecraftforge.client.gui.overlay.GuiOverlayManager import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.android.feature.NanobotsArmorFeature import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability @@ -25,6 +26,7 @@ import ru.dbotthepony.mc.otm.config.ClientConfig import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.util.formatPower import ru.dbotthepony.mc.otm.core.ifPresentK +import ru.dbotthepony.mc.otm.registry.AndroidFeatures import java.util.* import kotlin.math.ceil @@ -36,15 +38,16 @@ object MatteryGUI { val CHARGE_HUNGER = BARS.sprite(y = 18f, height = 9f) val CHARGE_HUNGER_BG = BARS.sprite(y = 27f, height = 9f) - private val BARS_HP = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_bars_health.png"), 81f, 54f) + private val BARS_HP = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_bars_health.png"), 81f, 63f) val HEALTH = BARS_HP.sprite(height = 9f) val HEALTH_BG = BARS_HP.sprite(y = 9f, height = 9f) + val HEALTH_BG_NANOBOTS = BARS_HP.sprite(y = 18f, height = 9f) - val HEALTH_POISON = BARS_HP.sprite(y = 18f, height = 9f) - val HEALTH_WITHER = BARS_HP.sprite(y = 27f, height = 9f) - val HEALTH_ABSORB = BARS_HP.sprite(y = 36f, height = 9f) - val HEALTH_FROZEN = BARS_HP.sprite(y = 45f, height = 9f) + val HEALTH_POISON = BARS_HP.sprite(y = 27f, height = 9f) + val HEALTH_WITHER = BARS_HP.sprite(y = 36f, height = 9f) + val HEALTH_ABSORB = BARS_HP.sprite(y = 45f, height = 9f) + val HEALTH_FROZEN = BARS_HP.sprite(y = 54f, height = 9f) private var originalBedButtonX = -1 private var originalBedButtonY = -1 @@ -308,8 +311,8 @@ object MatteryGUI { if (!gui.shouldDrawSurvivalElements()) return - val level: Float = (ply.health / ply.maxHealth).coerceIn(0.0f, 1.0f) - val levelAbsorb: Float = (ply.absorptionAmount / ply.maxHealth).coerceIn(0.0f, 1.0f) + val level: Float = (ply.health / ply.maxHealth).coerceIn(0.0f .. 1.0f) + val levelAbsorb: Float = (ply.absorptionAmount / ply.maxHealth).coerceIn(0.0f .. 1.0f) gui.setupOverlayRenderState(true, false) RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f) @@ -321,6 +324,14 @@ object MatteryGUI { gui.leftHeight += 10 HEALTH_BG.render(event.poseStack, left.toFloat(), top.toFloat()) + + if (mattery.hasFeature(AndroidFeatures.NANOBOTS_ARMOR)) { + val featArmor = mattery.getFeature(AndroidFeatures.NANOBOTS_ARMOR) as NanobotsArmorFeature + val levelArmor: Float = (featArmor.layers.toFloat() / (featArmor.strength + 1).toFloat()).coerceIn(0.0f .. 1.0f) + + HEALTH_BG_NANOBOTS.renderPartial(event.poseStack, left.toFloat(), top.toFloat(), width = ceil(levelArmor * 81f)) + } + getSpriteForPlayer(ply).renderPartial(event.poseStack, left.toFloat(), top.toFloat(), width = ceil(level * 80f - 0.5f)) if (levelAbsorb > 0) { HEALTH_ABSORB.renderPartial(event.poseStack, left.toFloat(), top.toFloat(), width = ceil(levelAbsorb * 80f - 0.5f)) diff --git a/src/main/resources/assets/overdrive_that_matters/textures/gui/player_bars_health.png b/src/main/resources/assets/overdrive_that_matters/textures/gui/player_bars_health.png index abf4b1d3a4372b2fe23b8ae3a5aa23d84defd11e..91269787329a435ef2bde45c6ec3bac8b43d86a4 100644 GIT binary patch delta 283 zcmZ3&bd+g=IF~&KGXn#|`t?`zCMqh_TL$=qxc(Ow-YqN)6xGnsVEF%^VgG&xeSHQ8 zhba{j8NnP^u3Wi)|Gt8Pg0{BymG$OV7BMtDeb2b>6Hq-9@16rdO1LD*FZe$OVAxc9 zhXW|hS>O>_%)r36AA}h#Sc6r7f@PjAjv*2C?r*PY3LP-uVL90Q_|EqK|8K~guu)#1 z_4b3B(FQJCQPT`XBTK=Tniqq!ZnmB{)9K;AvpM)3`xb$jb2`38D{cC*v`09q!^h91 zO6<{|1$!UuYHU66rSt33f8RU4=p6a$z&-I~r^k6G8-1{jH(om#H)|ZbTG!e&59kC2 NPggcSmvv4FO#tOqd}{yz delta 220 zcmX@gw1jDbIF}g*GXn!d$AZ>p6BQK%bpw1tT>lFT?-mvYifU+ROpH^km#-As2juaW z1o;L3M*$31?#x&Sl;SM#h%9Dc;5z`qj9J$@Ie~(yo-U3d5$QNp*GOE{F%lJgnc8u==Uc~V zt~8^GFGcrH|8-yY(rJP1vS1ByZ54Ae#AbGNyiwBAIMbS^@iwIgXd{ECtDnm{r-UW| D!TMOH