Weaken type argument in AutomationFilters
This commit is contained in:
parent
4db52b83c4
commit
c93fa7bb7a
@ -1,24 +1,25 @@
|
|||||||
package ru.dbotthepony.mc.otm.container.slotted
|
package ru.dbotthepony.mc.otm.container.slotted
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack
|
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 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 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 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
|
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 {
|
override fun modifyAutomationPlaceCount(self: S, itemStack: ItemStack): Int {
|
||||||
return itemStack.count
|
return itemStack.count
|
||||||
}
|
}
|
||||||
|
@ -4,118 +4,119 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.neoforged.neoforge.capabilities.Capabilities
|
import net.neoforged.neoforge.capabilities.Capabilities
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.fluid.stream
|
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.isNotEmpty
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
|
|
||||||
enum class AutomationFilters : AutomationFilter<ContainerSlot> {
|
enum class AutomationFilters : AutomationFilter<IContainerSlot> {
|
||||||
ONLY_OUT {
|
ONLY_OUT {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ONLY_IN {
|
ONLY_IN {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ALLOW {
|
ALLOW {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
DENY {
|
DENY {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
FLUID_CONTAINERS {
|
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
|
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
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
DRAINABLE_FLUID_CONTAINERS {
|
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
|
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)
|
return !canAutomationPlaceItem(self, self.item)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
DISCHARGABLE {
|
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
|
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
|
return self.item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canExtract() || it.extractEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
CHARGEABLE {
|
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
|
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
|
return self.item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canReceive() || it.receiveEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
CHEMICAL_FUEL {
|
CHEMICAL_FUEL {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return itemStack.getBurnTime(null) > 0
|
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
|
return self.item.getBurnTime(null) <= 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
IS_PATTERN {
|
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
|
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
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
MATTER_PROVIDERS {
|
MATTER_PROVIDERS {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
|
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||||
?.let { it.matterFlow.output && it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
?.let { it.matterFlow.output && it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
||||||
?: false
|
?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
|
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
|
||||||
?.let { !it.matterFlow.output || it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
?.let { !it.matterFlow.output || it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
||||||
?: true
|
?: true
|
||||||
@ -123,13 +124,13 @@ enum class AutomationFilters : AutomationFilter<ContainerSlot> {
|
|||||||
},
|
},
|
||||||
|
|
||||||
MATTER_CONSUMERS {
|
MATTER_CONSUMERS {
|
||||||
override fun canAutomationPlaceItem(self: ContainerSlot, itemStack: ItemStack): Boolean {
|
override fun canAutomationPlaceItem(self: IContainerSlot, itemStack: ItemStack): Boolean {
|
||||||
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
|
return itemStack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||||
?.let { it.matterFlow.input && it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
?.let { it.matterFlow.input && it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
||||||
?: false
|
?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canAutomationTakeItem(self: ContainerSlot, desired: Int): Boolean {
|
override fun canAutomationTakeItem(self: IContainerSlot, desired: Int): Boolean {
|
||||||
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
|
return self.item.getCapability(MatteryCapability.MATTER_ITEM)
|
||||||
?.let { !it.matterFlow.input || it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
?.let { !it.matterFlow.input || it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
||||||
?: true
|
?: true
|
||||||
|
Loading…
Reference in New Issue
Block a user