MatterProviders/MatterConsumers handler filter

This commit is contained in:
DBotThePony 2024-01-29 16:46:46 +07:00
parent c5b987c2de
commit 308240ac5b
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -6,6 +6,7 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.fluid.stream
import ru.dbotthepony.mc.otm.core.isNotEmpty
import ru.dbotthepony.mc.otm.core.math.Decimal
interface HandlerFilter {
fun canInsert(slot: Int, stack: ItemStack): Boolean {
@ -122,4 +123,32 @@ interface HandlerFilter {
return stack.getCapability(MatteryCapability.PATTERN).isPresent
}
}
object MatterProviders : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER)
.map { it.matterFlow.output && it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
.orElse(false)
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER)
.map { !it.matterFlow.output || it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
.orElse(true)
}
}
object MatterConsumers : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER)
.map { it.matterFlow.input && it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
.orElse(false)
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER)
.map { !it.matterFlow.input || it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
.orElse(true)
}
}
}