Matter reconstructor upgrades support

This commit is contained in:
DBotThePony 2023-07-19 21:26:22 +07:00
parent 9cd5bad152
commit ab51740ddf
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 31 additions and 16 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 {

View File

@ -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()