From ab51740ddf612ea1b96d9e5d0eaa125d455a92f3 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 19 Jul 2023 21:26:22 +0700 Subject: [PATCH] Matter reconstructor upgrades support --- .../matter/MatterReconstructorBlockEntity.kt | 40 ++++++++++++------- .../dbotthepony/mc/otm/capability/Upgrades.kt | 3 ++ .../matter/MatterReconstructorScreen.kt | 2 +- .../menu/matter/MatterReconstructorMenu.kt | 2 + 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt index 0fcff8458..a2072e291 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt @@ -16,6 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.UpgradeType import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage @@ -26,6 +27,7 @@ import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage import ru.dbotthepony.mc.otm.config.ConciseBalanceValues import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal @@ -58,8 +60,9 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) var isUnableToProcess = false private set - val matter = ProfiledMatterStorage(MatterStorageImpl(::setChangedLight, FlowDirection.INPUT, ::CAPACITY)) - val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::setChangedLight, ENERGY_VALUES)) + val upgrades = UpgradeContainer(this::setChangedLight, 3, UpgradeType.REPLICATOR) + val matter = ProfiledMatterStorage(MatterStorageImpl(::setChangedLight, FlowDirection.INPUT, upgrades.matterCapacity(::CAPACITY))) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::setChangedLight, upgrades.transform(ENERGY_VALUES))) val matterNode = object : MatterNode() { override fun getMatterHandler(): IMatterStorage { @@ -86,6 +89,7 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) savetables.stateful(::repairContainer) savetables.stateful(::matter) savetables.stateful(::energy) + savetables.stateful(::upgrades) savetables.decimal(::matterPerTick) savetables.double(::progressPerTick) @@ -219,13 +223,17 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) val item = repairContainer[0] - if (!item.isEmpty && matterPerTick.isPositive && progressPerTick > 0.0 && item.isRepairable && item.isDamaged) { - var progressPerTick = (repairProgress + progressPerTick).coerceAtMost(item.damageValue.toDouble()) - repairProgress + val thisProgressPerTick = progressPerTick * (1.0 + upgrades.speedBonus) + val matterPerTick = matterPerTick * (1.0 + upgrades.speedBonus) + val energyConsumption = ENERGY_CONSUMPTION * (1.0 + upgrades.speedBonus) * (upgrades.energyConsumed + Decimal.ONE) + + if (!item.isEmpty && matterPerTick.isPositive && thisProgressPerTick > 0.0 && item.isRepairable && item.isDamaged) { + var progressPerTick = (repairProgress + thisProgressPerTick).coerceAtMost(item.damageValue.toDouble()) - repairProgress if (progressPerTick <= 0.0) return - if (ENERGY_CONSUMPTION.isPositive) { + if (energyConsumption.isPositive) { if (!energy.batteryLevel.isPositive) return - val multEnergy = ENERGY_CONSUMPTION * (progressPerTick / this.progressPerTick) + val multEnergy = energyConsumption * (progressPerTick / thisProgressPerTick) progressPerTick *= (energy.extractEnergy(multEnergy, true) / multEnergy).toDouble() if (progressPerTick <= 0.0) { @@ -235,32 +243,34 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) } if (matter.storedMatter < matterPerTick) { - val graph = matterNode.graph as MatterGraph? + val toDrain = (matterPerTick * EXTRACT_TICKS + .coerceAtMost(item.damageValue) - matter.storedMatter) + .coerceAtLeast(Decimal.ZERO) + .coerceAtMost(matter.missingMatter) - if (graph != null) { - val toDrain = (matterPerTick * EXTRACT_TICKS.coerceAtMost(item.damageValue) - matter.storedMatter).coerceAtLeast(Decimal.ZERO).coerceAtMost(matter.missingMatter) - matter.receiveMatter(graph.extractMatter(toDrain, false), false) - } + matter.receiveMatter(matterNode.graph.extractMatter(toDrain, false), false) } - val toDrain = matterPerTick * (progressPerTick / this.progressPerTick) + val toDrain = matterPerTick * (progressPerTick / thisProgressPerTick) val drain = matter.extractMatter(toDrain, true) + if (!drain.isPositive) { isUnableToProcess = true return } progressPerTick *= (drain / toDrain).toDouble() + if (progressPerTick <= 0.0) { isUnableToProcess = true return } - if (failureChance <= 0.0 || level!!.random.nextDouble() >= failureChance) + if (failureChance * upgrades.failureMultiplier <= 0.0 || level!!.random.nextDouble() >= failureChance * upgrades.failureMultiplier) repairProgress += progressPerTick - energy.extractEnergy(ENERGY_CONSUMPTION * (progressPerTick / this.progressPerTick), false) - matter.extractMatter(matterPerTick * (progressPerTick / this.progressPerTick), false) + energy.extractEnergy(energyConsumption * (progressPerTick / thisProgressPerTick), false) + matter.extractMatter(matterPerTick * (progressPerTick / thisProgressPerTick), false) if (repairProgress >= 1.0) { item.damageValue = (item.damageValue - repairProgress.toInt()).coerceAtLeast(0) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Upgrades.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Upgrades.kt index 510a2850e..9ae1d54fe 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Upgrades.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/Upgrades.kt @@ -186,6 +186,9 @@ enum class UpgradeType { @JvmField val BASIC_MATTER = set(SPEED, ENERGY_STORAGE, ENERGY_CONSUMPTION, ENERGY_THROUGHPUT, MATTER_STORAGE) + @JvmField + val REPLICATOR = set(SPEED, ENERGY_STORAGE, ENERGY_CONSUMPTION, ENERGY_THROUGHPUT, MATTER_STORAGE, FAILSAFE) + @JvmField val BASIC_PROCESSING = set(SPEED, ENERGY_STORAGE, ENERGY_CONSUMPTION, ENERGY_THROUGHPUT, PROCESSING) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt index d87f67aec..7d9d99dff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt @@ -30,7 +30,7 @@ class MatterReconstructorScreen(menu: MatterReconstructorMenu, inventory: Invent SlotPanel(this, frame, menu.slot, 66f, PROGRESS_SLOT_TOP) ProgressGaugePanel(this, frame, menu.progress, 37f, PROGRESS_ARROW_TOP) - makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, itemConfig = menu.itemConfig, energyConfig = menu.energyConfig) + makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, itemConfig = menu.itemConfig, energyConfig = menu.energyConfig, upgrades = menu.upgrades) makeCuriosPanel(this, frame, menu.equipment.curiosSlots, autoAlign = true) PlayerEquipmentPanel(this, frame, armorSlots = menu.equipment.armorSlots).also { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt index 8527bf717..f019cbbea 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt @@ -32,6 +32,8 @@ class MatterReconstructorMenu( val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget) + val upgrades = makeUpgradeSlots(3, tile?.upgrades) + init { addStorageSlot(slot) addInventorySlots()