Get rid of receive/extract matter separation
This commit is contained in:
parent
f68ce78bf9
commit
e4dc6f60e7
@ -274,7 +274,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (extracted > Decimal.ZERO) {
|
if (extracted > Decimal.ZERO) {
|
||||||
val received = matter.receiveMatterOuter(extracted, false)
|
val received = matter.receiveMatter(extracted, false)
|
||||||
graph.extractMatter(received, false)
|
graph.extractMatter(received, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,12 +283,12 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
val energyExtracted = energy.extractEnergyInner(ENERGY_CONSUMPTION, true)
|
val energyExtracted = energy.extractEnergyInner(ENERGY_CONSUMPTION, true)
|
||||||
|
|
||||||
if (!energyExtracted.isZero) {
|
if (!energyExtracted.isZero) {
|
||||||
val matter = capability.receiveMatterOuter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.storedMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
val matter = capability.receiveMatter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.storedMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
||||||
|
|
||||||
if (!matter.isZero) {
|
if (!matter.isZero) {
|
||||||
energy.extractEnergyInner(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE, false)
|
energy.extractEnergyInner(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE, false)
|
||||||
|
|
||||||
capability.receiveMatterOuter(matter, false)
|
capability.receiveMatter(matter, false)
|
||||||
this.matter.extractMatterInner(matter, false)
|
this.matter.extractMatterInner(matter, false)
|
||||||
|
|
||||||
if (capability.missingMatter.isZero) {
|
if (capability.missingMatter.isZero) {
|
||||||
@ -307,12 +307,12 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
val energyExtracted = energy.extractEnergyInner(ENERGY_CONSUMPTION, true)
|
val energyExtracted = energy.extractEnergyInner(ENERGY_CONSUMPTION, true)
|
||||||
|
|
||||||
if (!energyExtracted.isZero) {
|
if (!energyExtracted.isZero) {
|
||||||
val matter = capability.extractMatterOuter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.missingMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
val matter = capability.extractMatter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.missingMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
||||||
|
|
||||||
if (!matter.isZero) {
|
if (!matter.isZero) {
|
||||||
this.energy.extractEnergyInner(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE,false)
|
this.energy.extractEnergyInner(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE,false)
|
||||||
|
|
||||||
capability.extractMatterOuter(matter, false)
|
capability.extractMatter(matter, false)
|
||||||
this.matter.receiveMatterInner(matter, false)
|
this.matter.receiveMatterInner(matter, false)
|
||||||
|
|
||||||
if (capability.storedMatter.isZero) {
|
if (capability.storedMatter.isZero) {
|
||||||
|
@ -70,11 +70,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
|||||||
return summ
|
return summ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveMatterInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (!howMuch.isPositive)
|
if (!howMuch.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -85,7 +81,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
|||||||
for (stack in container) {
|
for (stack in container) {
|
||||||
if (!stack.isEmpty) {
|
if (!stack.isEmpty) {
|
||||||
stack.getCapability(MatteryCapability.MATTER).ifPresent {
|
stack.getCapability(MatteryCapability.MATTER).ifPresent {
|
||||||
val diff = it.receiveMatterOuter(howMuch, simulate)
|
val diff = it.receiveMatter(howMuch, simulate)
|
||||||
summ += diff
|
summ += diff
|
||||||
howMuch -= diff
|
howMuch -= diff
|
||||||
}
|
}
|
||||||
@ -103,11 +99,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
|||||||
return summ
|
return summ
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractMatterInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (!howMuch.isPositive)
|
if (!howMuch.isPositive)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
@ -118,7 +110,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
|
|||||||
for (stack in container) {
|
for (stack in container) {
|
||||||
if (!stack.isEmpty) {
|
if (!stack.isEmpty) {
|
||||||
stack.getCapability(MatteryCapability.MATTER).ifPresent {
|
stack.getCapability(MatteryCapability.MATTER).ifPresent {
|
||||||
val diff = it.extractMatterOuter(howMuch, simulate)
|
val diff = it.extractMatter(howMuch, simulate)
|
||||||
summ += diff
|
summ += diff
|
||||||
howMuch -= diff
|
howMuch -= diff
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
return Status.FAILURE_MATTER
|
return Status.FAILURE_MATTER
|
||||||
}
|
}
|
||||||
|
|
||||||
val received = matter.receiveMatterOuter(drain, false)
|
val received = matter.receiveMatter(drain, false)
|
||||||
graph.extractMatter(received, false)
|
graph.extractMatter(received, false)
|
||||||
|
|
||||||
// получили материю, проверяем возможность работы
|
// получили материю, проверяем возможность работы
|
||||||
|
@ -20,6 +20,8 @@ interface IMatterHandler {
|
|||||||
* 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)
|
||||||
*
|
*
|
||||||
|
* If you need to fully fill matter value, DO call [fillMatter], or, in case if you want to fully drain, call [drainMatter]
|
||||||
|
*
|
||||||
* @throws [UnsupportedOperationException]
|
* @throws [UnsupportedOperationException]
|
||||||
*/
|
*/
|
||||||
var storedMatter: Decimal
|
var storedMatter: Decimal
|
||||||
@ -37,7 +39,7 @@ interface IMatterHandler {
|
|||||||
* @throws [UnsupportedOperationException]
|
* @throws [UnsupportedOperationException]
|
||||||
* @see storedMatter
|
* @see storedMatter
|
||||||
*/
|
*/
|
||||||
fun emptyMatter() {
|
fun drainMatter() {
|
||||||
storedMatter = Decimal.ZERO
|
storedMatter = Decimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,50 +54,18 @@ interface IMatterHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make this object receive matter, from outside world.
|
* Fill matter into this object
|
||||||
*
|
|
||||||
* Call this if you don't own the object in question.
|
|
||||||
*
|
*
|
||||||
* @return matter accepted
|
* @return matter accepted
|
||||||
*/
|
*/
|
||||||
fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make this object receive matter, from inside world.
|
* Extract matter from this object
|
||||||
*
|
|
||||||
* Call this if you DO own the object in question.
|
|
||||||
*
|
|
||||||
* Nothing stops you from calling this from outside world, however, this will most likely
|
|
||||||
* lead to bugs, use [receiveMatterOuter] in this case instead. Methods were separated (and inside interface) for ease of use.
|
|
||||||
*
|
|
||||||
* Don't try to hammer nails with a screwdriver.
|
|
||||||
*
|
|
||||||
* @return matter accepted
|
|
||||||
*/
|
|
||||||
fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make this object extract matter from itself, from outside world.
|
|
||||||
*
|
|
||||||
* Call this if you don't own the object in question.
|
|
||||||
*
|
*
|
||||||
* @return matter extracted
|
* @return matter extracted
|
||||||
*/
|
*/
|
||||||
fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal
|
fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal
|
||||||
|
|
||||||
/**
|
|
||||||
* Make this object extract matter from itself, from inside world.
|
|
||||||
*
|
|
||||||
* Call this if you DO own the object in question.
|
|
||||||
*
|
|
||||||
* Nothing stops you from calling this from outside world, however, this will most likely
|
|
||||||
* lead to bugs, use [extractMatterOuter] in this case instead. Methods were separated (and inside interface) for ease of use.
|
|
||||||
*
|
|
||||||
* Don't try to hammer nails with a screwdriver.
|
|
||||||
*
|
|
||||||
* @return matter extracted
|
|
||||||
*/
|
|
||||||
fun extractMatterInner(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 object. Why estimated? Because some objects can be bottomless.
|
||||||
|
@ -62,14 +62,14 @@ open class MatterHandlerImpl @JvmOverloads constructor(
|
|||||||
return maxStoredMatter >= value && storedMatter + value <= maxStoredMatter
|
return maxStoredMatter >= value && storedMatter + value <= maxStoredMatter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
if (!canReceiveMatter)
|
if (!canReceiveMatter)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
return receiveMatterInner(howMuch, simulate)
|
return receiveMatterInner(howMuch, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
val new: Decimal
|
val new: Decimal
|
||||||
|
|
||||||
if (maxReceive == null) {
|
if (maxReceive == null) {
|
||||||
@ -88,14 +88,14 @@ open class MatterHandlerImpl @JvmOverloads constructor(
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
if (canExtractMatter)
|
if (canExtractMatter)
|
||||||
return Decimal.ZERO
|
return Decimal.ZERO
|
||||||
|
|
||||||
return extractMatterInner(howMuch, simulate)
|
return extractMatterInner(howMuch, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
fun extractMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
val new: Decimal
|
val new: Decimal
|
||||||
|
|
||||||
if (maxExtract == null) {
|
if (maxExtract == null) {
|
||||||
|
@ -114,7 +114,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null) {
|
if (matter != null) {
|
||||||
val value = matter.extractMatterOuter(howMuch, simulate)
|
val value = matter.extractMatter(howMuch, simulate)
|
||||||
howMuch -= value
|
howMuch -= value
|
||||||
extracted += value
|
extracted += value
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.matterDirection == FlowDirection.BI_DIRECTIONAL) {
|
if (matter != null && matter.matterDirection == FlowDirection.BI_DIRECTIONAL) {
|
||||||
val value = matter.receiveMatterOuter(howMuch, simulate)
|
val value = matter.receiveMatter(howMuch, simulate)
|
||||||
howMuch -= value
|
howMuch -= value
|
||||||
received += value
|
received += value
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.matterDirection != FlowDirection.OUTPUT) {
|
if (matter != null && matter.matterDirection != FlowDirection.OUTPUT) {
|
||||||
val value = matter.receiveMatterOuter(howMuch, simulate)
|
val value = matter.receiveMatter(howMuch, simulate)
|
||||||
howMuch -= value
|
howMuch -= value
|
||||||
received += value
|
received += value
|
||||||
|
|
||||||
|
@ -52,11 +52,7 @@ class MatterCapacitorItem : Item {
|
|||||||
return if (isCreative) Decimal.LONG_MAX_VALUE else super.missingMatter
|
return if (isCreative) Decimal.LONG_MAX_VALUE else super.missingMatter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return receiveMatterInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receiveMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (isCreative) return howMuch
|
if (isCreative) return howMuch
|
||||||
val new = storedMatter.plus(howMuch.coerceAtMost(maxInput)).coerceAtMost(capacity)
|
val new = storedMatter.plus(howMuch.coerceAtMost(maxInput)).coerceAtMost(capacity)
|
||||||
val diff = new.minus(storedMatter)
|
val diff = new.minus(storedMatter)
|
||||||
@ -68,11 +64,7 @@ class MatterCapacitorItem : Item {
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun extractMatterOuter(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
return extractMatterInner(howMuch, simulate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractMatterInner(howMuch: Decimal, simulate: Boolean): Decimal {
|
|
||||||
if (isCreative) return howMuch
|
if (isCreative) return howMuch
|
||||||
val new = storedMatter.minus(howMuch.coerceAtMost(maxOutput)).moreThanZero()
|
val new = storedMatter.minus(howMuch.coerceAtMost(maxOutput)).moreThanZero()
|
||||||
val diff = storedMatter.minus(new)
|
val diff = storedMatter.minus(new)
|
||||||
|
Loading…
Reference in New Issue
Block a user