CombinedItemHandler no longer checks underlying handlers if they are mattery container handlers

This commit is contained in:
DBotThePony 2023-03-23 08:05:04 +07:00
parent d47e5b3d7a
commit 5b1d52489e
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.capability
import com.google.common.collect.ImmutableList
import net.minecraft.world.item.ItemStack
import net.minecraftforge.items.IItemHandler
import ru.dbotthepony.mc.otm.container.ContainerHandler
import java.util.stream.Stream
class CombinedItemHandler(val handlers: ImmutableList<IItemHandler>) : IItemHandler {
@ -10,12 +11,20 @@ class CombinedItemHandler(val handlers: ImmutableList<IItemHandler>) : IItemHand
constructor(handlers: Collection<IItemHandler>) : this(ImmutableList.copyOf(handlers))
constructor(vararg handlers: IItemHandler) : this(ImmutableList.copyOf(handlers))
private val needsChecking = handlers.any { it !is ContainerHandler }
private val lastSizes = IntArray(this.handlers.size)
private var totalSize = 0
private val mappings = ArrayList<Mapping>()
private data class Mapping(val handler: IItemHandler, val slot: Int)
private fun check() {
init {
check(true)
}
private fun check(force: Boolean = false) {
if (!needsChecking && !force)
return
for ((i, handler) in handlers.withIndex()) {
var oldSize = lastSizes[i]