diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt index 222f0d67c..39365b5ea 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt @@ -17,6 +17,7 @@ import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.capability.matter.* +import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.stream import ru.dbotthepony.mc.otm.core.collect.iterator import ru.dbotthepony.mc.otm.core.filterNotNull @@ -75,7 +76,7 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } - val itemConfig = ConfigurableItemHandler(inputOutput = container.handler { _: Int, stack: ItemStack -> stack.getCapability(MatteryCapability.PATTERN).isPresent }) + val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(HandlerFilter.IsPattern.and(HandlerFilter.OnlyIn))) override fun setLevel(level: Level) { super.setLevel(level) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt index c36c8af12..ce8051302 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt @@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.container import net.minecraft.world.item.ItemStack import net.minecraftforge.common.ForgeHooks import net.minecraftforge.common.capabilities.ForgeCapabilities +import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.isNotEmpty @@ -107,4 +108,10 @@ interface HandlerFilter { return ForgeHooks.getBurnTime(stack, null) > 0 } } + + object IsPattern : HandlerFilter { + override fun canInsert(slot: Int, stack: ItemStack): Boolean { + return stack.getCapability(MatteryCapability.PATTERN).isPresent + } + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt index 186726e8a..060b8804b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt @@ -211,33 +211,10 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I return false } - fun handler( - insert_validator: (slot: Int, stack: ItemStack) -> Boolean, - extract_validator: (slot: Int, amount: Int, stack: ItemStack) -> Boolean - ): ContainerHandler { - return ContainerHandler(this, object : HandlerFilter { - override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack) - override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = extract_validator(slot, amount, stack) - }) - } - - fun handler( - filter: HandlerFilter - ): ContainerHandler { + fun handler(filter: HandlerFilter = HandlerFilter.Both): ContainerHandler { return ContainerHandler(this, filter) } - fun handler(insert_validator: (Int, ItemStack) -> Boolean): ContainerHandler { - return ContainerHandler(this, object : HandlerFilter { - override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack) - override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = false - }) - } - - fun handler(): ContainerHandler { - return ContainerHandler(this) - } - open fun getMaxStackSize(slot: Int) = maxStackSize open fun getMaxStackSizeWithItem(slot: Int): Int {