diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/CombinedItemHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/CombinedItemHandler.kt index b43fc9121..450e614cd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/CombinedItemHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/CombinedItemHandler.kt @@ -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 { @@ -10,12 +11,20 @@ class CombinedItemHandler(val handlers: ImmutableList) : IItemHand constructor(handlers: Collection) : 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() 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]