Actually fix matter bottler bottling when transferring very little amount of matter
This commit is contained in:
parent
2453c60d76
commit
9a6cc53189
@ -190,23 +190,32 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
|||||||
if (matter.storedMatter < rate) {
|
if (matter.storedMatter < rate) {
|
||||||
val toExtract = matter.missingMatter
|
val toExtract = matter.missingMatter
|
||||||
.coerceAtMost(rate * 200)
|
.coerceAtMost(rate * 200)
|
||||||
.coerceAtMost((capability.missingMatter - matter.storedMatter).coerceAtLeast(Decimal.ONE))
|
.coerceAtMost(capability.missingMatter - matter.storedMatter)
|
||||||
|
|
||||||
matter.receiveMatter(matterNode.graph.extractMatter(toExtract, false), false)
|
matter.receiveMatter(matterNode.graph.extractMatter(toExtract, false), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matter.storedMatter.isPositive) {
|
if (matter.storedMatter.isPositive) {
|
||||||
val energyRatio = if (energyRate <= Decimal.ZERO) Decimal.ONE else energy.extractEnergy(energyRate, true) / energyRate
|
val energyRatio = if (energyRate <= Decimal.ZERO) Decimal.ONE else energy.extractEnergy(energyRate, true) / energyRate
|
||||||
val matterRatio = matter.extractMatter(capability.receiveMatter(rate.coerceAtMost(matter.storedMatter), true), true) / rate
|
val matterTransferred = matter.extractMatter(capability.receiveMatter(rate.coerceAtMost(matter.storedMatter), true), true)
|
||||||
|
val matterRatio = matterTransferred / rate
|
||||||
|
|
||||||
val minRatio = minOf(matterRatio, energyRatio)
|
if (matterRatio == Decimal.ZERO && matterTransferred > Decimal.ZERO) {
|
||||||
|
// transferring very little matter, transfer this time for free
|
||||||
if (minRatio > Decimal.ZERO) {
|
|
||||||
isWorking = true
|
isWorking = true
|
||||||
energy.extractEnergy(energyRate * minRatio, false)
|
matter.extractMatter(capability.receiveMatter(matter.storedMatter, false), false)
|
||||||
matter.extractMatter(capability.receiveMatter(rate * minRatio, false), false)
|
|
||||||
workProgress = ((capability.storedMatter - initialCapacity!!) / capability.maxStoredMatter).toFloat()
|
workProgress = ((capability.storedMatter - initialCapacity!!) / capability.maxStoredMatter).toFloat()
|
||||||
slot.setChanged()
|
slot.setChanged()
|
||||||
|
} else {
|
||||||
|
val minRatio = minOf(matterRatio, energyRatio)
|
||||||
|
|
||||||
|
if (minRatio > Decimal.ZERO) {
|
||||||
|
isWorking = true
|
||||||
|
energy.extractEnergy(energyRate * minRatio, false)
|
||||||
|
matter.extractMatter(capability.receiveMatter(rate * minRatio, false), false)
|
||||||
|
workProgress = ((capability.storedMatter - initialCapacity!!) / capability.maxStoredMatter).toFloat()
|
||||||
|
slot.setChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (spitItemsWhenCantWork) {
|
if (spitItemsWhenCantWork) {
|
||||||
@ -266,16 +275,24 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
|||||||
val energyRate = MachinesConfig.MatterBottler.VALUES.energyConsumption * (1.0 + upgrades.speedBonus)
|
val energyRate = MachinesConfig.MatterBottler.VALUES.energyConsumption * (1.0 + upgrades.speedBonus)
|
||||||
|
|
||||||
val energyRatio = if (energyRate <= Decimal.ZERO) Decimal.ONE else energy.extractEnergy(energyRate, true) / energyRate
|
val energyRatio = if (energyRate <= Decimal.ZERO) Decimal.ONE else energy.extractEnergy(energyRate, true) / energyRate
|
||||||
val matterRatio = matter.receiveMatter(it.extractMatterChecked(rate, true), true) / rate
|
val matterExtracted = matter.receiveMatter(it.extractMatterChecked(rate, true), true)
|
||||||
|
val matterRatio = matterExtracted / rate
|
||||||
|
|
||||||
val minRatio = minOf(energyRatio, matterRatio)
|
if (matterRatio == Decimal.ZERO && matterExtracted > Decimal.ZERO) {
|
||||||
|
// very little matter extracted, extract this one for free
|
||||||
if (minRatio > Decimal.ZERO) {
|
|
||||||
any = true
|
any = true
|
||||||
energy.extractEnergy(energyRate * energyRatio, false)
|
matter.receiveMatter(it.extractMatterChecked(matterExtracted, false), false)
|
||||||
matter.receiveMatter(it.extractMatterChecked(rate * minRatio, false), false)
|
|
||||||
|
|
||||||
workProgress = 1f - (it.storedMatter / initialCapacity!!).toFloat()
|
workProgress = 1f - (it.storedMatter / initialCapacity!!).toFloat()
|
||||||
|
} else {
|
||||||
|
val minRatio = minOf(energyRatio, matterRatio)
|
||||||
|
|
||||||
|
if (minRatio > Decimal.ZERO) {
|
||||||
|
any = true
|
||||||
|
energy.extractEnergy(energyRate * energyRatio, false)
|
||||||
|
matter.receiveMatter(it.extractMatterChecked(rate * minRatio, false), false)
|
||||||
|
|
||||||
|
workProgress = 1f - (it.storedMatter / initialCapacity!!).toFloat()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user