Weaken type argument in AutomationFilters

This commit is contained in:
DBotThePony 2025-03-29 13:37:14 +07:00
parent 4db52b83c4
commit c93fa7bb7a
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 32 additions and 30 deletions

View File

@ -1,24 +1,25 @@
package ru.dbotthepony.mc.otm.container.slotted
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.container.IContainerSlot
fun interface AutomationPlaceItem<in S : ContainerSlot> {
fun interface AutomationPlaceItem<in S : IContainerSlot> {
fun canAutomationPlaceItem(self: S, itemStack: ItemStack): Boolean
}
fun interface AutomationTakeItem<in S : ContainerSlot> {
fun interface AutomationTakeItem<in S : IContainerSlot> {
fun canAutomationTakeItem(self: S, desired: Int): Boolean
}
fun interface AutomationModifyPlaceCount<in S : ContainerSlot> {
fun interface AutomationModifyPlaceCount<in S : IContainerSlot> {
fun modifyAutomationPlaceCount(self: S, itemStack: ItemStack): Int
}
fun interface AutomationModifyExtractionCount<in S : ContainerSlot> {
fun interface AutomationModifyExtractionCount<in S : IContainerSlot> {
fun modifyAutomationExtractionCount(self: S, desired: Int): Int
}
interface AutomationFilter<in S : ContainerSlot> : AutomationPlaceItem<S>, AutomationTakeItem<S>, AutomationModifyPlaceCount<S>, AutomationModifyExtractionCount<S> {
interface AutomationFilter<in S : IContainerSlot> : AutomationPlaceItem<S>, AutomationTakeItem<S>, AutomationModifyPlaceCount<S>, AutomationModifyExtractionCount<S> {
override fun modifyAutomationPlaceCount(self: S, itemStack: ItemStack): Int {
return itemStack.count
}

View File

@ -4,118 +4,119 @@ import net.minecraft.world.item.ItemStack
import net.neoforged.neoforge.capabilities.Capabilities
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.fluid.stream
import ru.dbotthepony.mc.otm.container.IContainerSlot
import ru.dbotthepony.mc.otm.core.isNotEmpty
import ru.dbotthepony.mc.otm.core.math.Decimal
enum class AutomationFilters : AutomationFilter<ContainerSlot> {
enum class AutomationFilters : AutomationFilter<IContainerSlot> {
ONLY_OUT {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return true
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return false
}
},
ONLY_IN {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return true
}
},
ALLOW {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return true
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return true
}
},
DENY {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return false
}
},
FLUID_CONTAINERS {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(Capabilities.FluidHandler.ITEM)?.let { it.tanks > 0 } ?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return true
}
},
DRAINABLE_FLUID_CONTAINERS {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(Capabilities.FluidHandler.ITEM)?.let { it.stream().anyMatch { it.isNotEmpty } } ?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return !canAutomationPlaceItem(self, self.item)
}
},
DISCHARGABLE {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { it.canExtract() && it.extractEnergy(Int.MAX_VALUE, true) > 0 } ?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return self.item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canExtract() || it.extractEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
}
},
CHARGEABLE {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { it.canReceive() && it.receiveEnergy(Int.MAX_VALUE, true) > 0 } ?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return self.item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canReceive() || it.receiveEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
}
},
CHEMICAL_FUEL {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getBurnTime(null) > 0
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return self.item.getBurnTime(null) <= 0
}
},
IS_PATTERN {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(MatteryCapability.PATTERN_ITEM) != null
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return true
}
},
MATTER_PROVIDERS {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
?.let { it.matterFlow.output && it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
?.let { !it.matterFlow.output || it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
?: true
@ -123,13 +124,13 @@ enum class AutomationFilters : AutomationFilter<ContainerSlot> {
},
MATTER_CONSUMERS {
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
?.let { it.matterFlow.input && it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
?: false
}
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
?.let { !it.matterFlow.input || it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
?: true