Get rid of lambda container handler creation
This commit is contained in:
parent
6f17ed2767
commit
716ccae94a
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user