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