Provide stream() method in enhanced container

This commit is contained in:
DBotThePony 2025-03-06 21:58:08 +07:00
parent 16d492073b
commit 6c42af9f30
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -15,6 +15,8 @@ import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.collect.map
import ru.dbotthepony.mc.otm.core.isNotEmpty
import java.util.function.Predicate
import java.util.stream.Stream
import java.util.stream.StreamSupport
/**
* "Backward-compatible" enhanced container interface, where all methods can be derived/emulated from existing [IContainer] ([Container]) code
@ -291,6 +293,10 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable<ItemStack>, Sta
return addItem(stack, false, slots, onlyIntoExisting, popTime).isEmpty
}
fun stream(): Stream<ItemStack> {
return StreamSupport.stream(spliterator(), false)
}
private class Wrapper(private val parent: Container) : IEnhancedContainer {
override fun clearContent() {
return parent.clearContent()