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 12647683a..eadb8a8e0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/HandlerFilter.kt @@ -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) + } + } }