Stream'y
This commit is contained in:
parent
471ddb49e5
commit
3ca8f11c48
@ -967,6 +967,18 @@ object MatterManager {
|
|||||||
return get(value).hasMatterValue
|
return get(value).hasMatterValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun reduce(a: IMatterValue, b: IMatterValue): IMatterValue {
|
||||||
|
if (a.hasMatterValue && b.hasMatterValue) {
|
||||||
|
return MatterValue(a.matter + b.matter, a.complexity + b.complexity)
|
||||||
|
} else if (a.hasMatterValue) {
|
||||||
|
return a
|
||||||
|
} else if (b.hasMatterValue) {
|
||||||
|
return b
|
||||||
|
} else {
|
||||||
|
return IMatterValue.Companion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun get(value: ItemStack, level: Int, accountForStackSize: Boolean): IMatterValue {
|
private fun get(value: ItemStack, level: Int, accountForStackSize: Boolean): IMatterValue {
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
return IMatterValue.Companion
|
return IMatterValue.Companion
|
||||||
@ -997,29 +1009,20 @@ object MatterManager {
|
|||||||
|
|
||||||
val drive = value.getCapability(MatteryCapability.DRIVE).orNull()
|
val drive = value.getCapability(MatteryCapability.DRIVE).orNull()
|
||||||
|
|
||||||
if (drive != null && drive.storageType === OverdriveThatMatters.INSTANCE.ITEM_STORAGE()) {
|
if (drive != null && drive.storageType == OverdriveThatMatters.INSTANCE.ITEM_STORAGE()) {
|
||||||
for (item in (drive as IMatteryDrive<ItemStackWrapper>).stacks) {
|
(drive as IMatteryDrive<ItemStackWrapper>).stacks
|
||||||
val tuple = get(item.stack.stack, level + 1, true)
|
.map { it.stack.stack }
|
||||||
|
.filter { !it.isEmpty }
|
||||||
if (tuple.hasMatterValue) {
|
.map { get(it, level + 1, true) }
|
||||||
matter += tuple
|
.reduce(::reduce)
|
||||||
undamagedMatterValue += tuple
|
.ifPresent {
|
||||||
}
|
matter += it
|
||||||
|
undamagedMatterValue += it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresentK {
|
value.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresentK {
|
||||||
it.stream().filter { !it.isEmpty }.map { get(it, level + 1, true) }.reduce { a, b ->
|
it.stream().filter { !it.isEmpty }.map { get(it, level + 1, true) }.reduce(::reduce).ifPresent {
|
||||||
if (a.hasMatterValue && b.hasMatterValue) {
|
|
||||||
return@reduce MatterValue(a.matter + b.matter, a.complexity + b.complexity)
|
|
||||||
} else if (a.hasMatterValue) {
|
|
||||||
return@reduce a
|
|
||||||
} else if (b.hasMatterValue) {
|
|
||||||
return@reduce b
|
|
||||||
} else {
|
|
||||||
return@reduce IMatterValue.Companion
|
|
||||||
}
|
|
||||||
}.ifPresent {
|
|
||||||
matter += it
|
matter += it
|
||||||
undamagedMatterValue += it
|
undamagedMatterValue += it
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user