diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt index 76d18a1a8..cbb109b60 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt @@ -43,9 +43,10 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.set import ru.dbotthepony.mc.otm.storage.* import java.math.BigInteger -import java.util.IdentityHashMap -import java.util.UUID +import java.util.* import java.util.function.Supplier +import kotlin.collections.HashMap +import kotlin.collections.HashSet class ItemMonitorPlayerSettings : INBTSerializable { enum class RefillSource(val component: TranslatableComponent) { @@ -163,13 +164,11 @@ private fun takeOne(inventory: Inventory, item: ItemStack): Boolean { return false } -private fun takeOne(set: Set, view: IStorageProvider): Boolean { - for (id in set) { - val extracted = view.extractStack(id, BigInteger.ONE, false) +private fun takeOne(id: UUID?, view: IStorageProvider): Boolean { + val extracted = view.extractStack(id ?: return false, BigInteger.ONE, false) - if (!extracted.isEmpty) { - return true - } + if (!extracted.isEmpty) { + return true } return false @@ -230,9 +229,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val craftingRecipe = craftingRecipe if (oldRecipe != craftingRecipe) { - for (i in craftingGridTuples.indices) { - craftingGridTuples[i] = HashSet() - } + Arrays.fill(craftingGridTuples, null) val poweredView = poweredView @@ -241,14 +238,14 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val item = craftingGrid[i] if (!item.isEmpty) { - poweredView[ItemStackWrapper(item).key()]?.let(craftingGridTuples[i]::add) + craftingGridTuples[i] = poweredView[ItemStackWrapper(item).key()] } } } } } - private val craftingGridTuples = Array(3 * 3) { HashSet() } + private val craftingGridTuples = arrayOfNulls(3 * 3) private val craftingMenu = object : AbstractContainerMenu(null, Int.MIN_VALUE) { override fun stillValid(p_38874_: Player): Boolean { @@ -262,7 +259,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : get() = ITEM_STORAGE override fun addStack(stack: ItemStackWrapper, id: UUID, provider: IStorageProvider) { - // TODO("Not yet implemented") + // no op } override fun changeStack(stack: ItemStackWrapper, id: UUID, oldCount: BigInteger) { @@ -270,7 +267,11 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } override fun removeStack(stack: ItemStackWrapper, id: UUID) { - // TODO("Not yet implemented") + for (i in craftingGridTuples.indices) { + if (craftingGridTuples[i] == id) { + craftingGridTuples[i] = null + } + } } init {