Get rid of lambda container handler creation

This commit is contained in:
DBotThePony 2023-08-02 13:42:29 +07:00
parent 6f17ed2767
commit 716ccae94a
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 10 additions and 25 deletions

View File

@ -17,6 +17,7 @@ import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.capability.matter.* 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.container.stream
import ru.dbotthepony.mc.otm.core.collect.iterator import ru.dbotthepony.mc.otm.core.collect.iterator
import ru.dbotthepony.mc.otm.core.filterNotNull 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) { override fun setLevel(level: Level) {
super.setLevel(level) super.setLevel(level)

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.container
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraftforge.common.ForgeHooks import net.minecraftforge.common.ForgeHooks
import net.minecraftforge.common.capabilities.ForgeCapabilities 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.ifPresentK
import ru.dbotthepony.mc.otm.core.isNotEmpty import ru.dbotthepony.mc.otm.core.isNotEmpty
@ -107,4 +108,10 @@ interface HandlerFilter {
return ForgeHooks.getBurnTime(stack, null) > 0 return ForgeHooks.getBurnTime(stack, null) > 0
} }
} }
object IsPattern : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.PATTERN).isPresent
}
}
} }

View File

@ -211,33 +211,10 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I
return false return false
} }
fun handler( fun handler(filter: HandlerFilter = HandlerFilter.Both): ContainerHandler {
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 {
return ContainerHandler(this, filter) 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 getMaxStackSize(slot: Int) = maxStackSize
open fun getMaxStackSizeWithItem(slot: Int): Int { open fun getMaxStackSizeWithItem(slot: Int): Int {