From c31549792e3dcc841a1e7b999cd547ff11cce6c3 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 6 Mar 2025 16:37:30 +0700 Subject: [PATCH] More specific methods in enhanced container interface --- .../mc/otm/container/IEnhancedContainer.kt | 20 +++++++++++++++---- .../mc/otm/container/ISlottedContainer.kt | 6 +----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt index 1a4cb4267..30509ab3a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt @@ -88,15 +88,27 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta } } - fun emptySlotIterator(allowedSlots: IntCollection = slotRange): IntIterator { + fun emptySlotIndexIterator(): IntIterator { + return emptySlotIndexIterator(slotRange) + } + + fun nonEmptySlotIndexIterator(): IntIterator { + return nonEmptySlotIndexIterator(slotRange) + } + + fun emptySlotIndexIterator(allowedSlots: IntCollection): IntIterator { return slotIterator(allowedSlots) { it.isEmpty } } - fun nonEmptySlotIterator(allowedSlots: IntCollection = slotRange): IntIterator { + fun nonEmptySlotIndexIterator(allowedSlots: IntCollection): IntIterator { return slotIterator(allowedSlots) { it.isNotEmpty } } - fun slotWithItemIterator(item: Item, allowedSlots: IntCollection = slotRange): IntIterator { + fun slotWithItemIterator(item: Item): IntIterator { + return slotWithItemIterator(item, slotRange) + } + + fun slotWithItemIterator(item: Item, allowedSlots: IntCollection): IntIterator { return slotIterator(allowedSlots) { it.isNotEmpty && it.item === item } } @@ -234,7 +246,7 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta if (!onlyIntoExisting) { // двигаем в пустые слоты - for (slot in emptySlotIterator(slots)) { + for (slot in emptySlotIndexIterator(slots)) { val diff = copy.count.coerceAtMost(getMaxStackSize(slot, stack)) if (!simulate) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt index 58430a103..92530f6a3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt @@ -2,12 +2,8 @@ package ru.dbotthepony.mc.otm.container import it.unimi.dsi.fastutil.ints.IntCollection import it.unimi.dsi.fastutil.ints.IntSet -import net.minecraft.world.Container import net.minecraft.world.item.ItemStack -import net.neoforged.neoforge.items.IItemHandler import ru.dbotthepony.kommons.collect.any -import ru.dbotthepony.mc.otm.core.collect.filter -import ru.dbotthepony.mc.otm.core.collect.map /** * Skeletal implementation for containers which revolve around [IContainerSlot] @@ -80,7 +76,7 @@ interface ISlottedContainer : IEnhancedContainer { } if (!onlyIntoExisting) { - for (i in emptySlotIterator(slots)) { + for (i in emptySlotIndexIterator(slots)) { val slot = containerSlot(i) val condition: Boolean