From 5b1d52489ea3413d2d4be091d029568bb741074f Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 23 Mar 2023 08:05:04 +0700 Subject: [PATCH] CombinedItemHandler no longer checks underlying handlers if they are mattery container handlers --- .../mc/otm/capability/CombinedItemHandler.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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]