Move stuff around
This commit is contained in:
parent
b595f9ca3f
commit
49bb695af2
@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
|
||||
import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import ru.dbotthepony.mc.otm.menu.BatteryBankMenu
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
@ -58,7 +58,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
|
||||
override val droppableContainer: Container
|
||||
get() = container
|
||||
private val itemHandler = container.handler(
|
||||
object : MatteryContainerFilter {
|
||||
object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(ForgeCapabilities.ENERGY).isPresent
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import net.minecraftforge.common.util.LazyOptional
|
||||
import ru.dbotthepony.mc.otm.block.CargoCrateBlock
|
||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.map
|
||||
import ru.dbotthepony.mc.otm.core.set
|
||||
@ -44,7 +44,7 @@ class CargoCrateBlockEntity(
|
||||
) : MatteryBlockEntity(MBlockEntities.CARGO_CRATE, p_155229_, p_155230_), IDroppableContainer {
|
||||
val container = MatteryContainer(this::setChanged, CAPACITY)
|
||||
private var interactingPlayers = 0
|
||||
val handler = container.handler(object : MatteryContainerFilter {
|
||||
val handler = container.handler(object : MatteryContainerHooks {
|
||||
override fun preInsert(slot: Int, stack: ItemStack, simulate: Boolean) {
|
||||
unpackLootTable()
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
|
||||
import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import ru.dbotthepony.mc.otm.menu.ChemicalGeneratorMenu
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
@ -129,7 +129,7 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl
|
||||
}
|
||||
}
|
||||
|
||||
val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
if (slot == SLOT_INPUT)
|
||||
return ForgeHooks.getBurnTime(stack, null) > 0
|
||||
|
@ -22,7 +22,7 @@ import ru.dbotthepony.mc.otm.capability.extractEnergy
|
||||
import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.map
|
||||
import ru.dbotthepony.mc.otm.core.set
|
||||
@ -39,7 +39,7 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
|
||||
override val droppableContainer: Container
|
||||
get() = container
|
||||
|
||||
val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return when (slot) {
|
||||
SLOT_DISCHARGE -> stack.isEmpty || stack.energy?.let { it.extractEnergy(Int.MAX_VALUE, true) > 0 } ?: false
|
||||
|
@ -18,7 +18,7 @@ import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.menu.PlatePressMenu
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
@ -35,7 +35,7 @@ class PlatePressBlockEntity(
|
||||
|
||||
override val droppableContainer: Container
|
||||
get() = container
|
||||
val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return slot != SLOT_OUTPUT
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterDirection
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||
@ -96,7 +96,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
override val droppableContainer: Container
|
||||
get() = container
|
||||
|
||||
val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
if (isBottling) {
|
||||
return slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent
|
||||
|
@ -27,7 +27,7 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterDirection
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||
@ -142,7 +142,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
||||
get() = container
|
||||
|
||||
private val itemHandler = LazyOptional.of<IItemHandler> {
|
||||
container.handler(object : MatteryContainerFilter {
|
||||
container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return slot == INPUT_SLOT && canDecompose(stack)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterDirection
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||
@ -64,7 +64,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
||||
return matter
|
||||
}
|
||||
|
||||
private val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
private val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.item is MatterDustItem
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilterOnlyOut
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHandler
|
||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||
@ -32,7 +32,6 @@ import ru.dbotthepony.mc.otm.matter.baselineComplexityReplicateTicks
|
||||
import ru.dbotthepony.mc.otm.matter.getMatterValue
|
||||
import ru.dbotthepony.mc.otm.menu.MatterReplicatorMenu
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
import ru.dbotthepony.mc.otm.container.set
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||
import ru.dbotthepony.mc.otm.registry.MNames
|
||||
@ -111,7 +110,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
)
|
||||
|
||||
val container = MatteryContainer(this::itemContainerUpdated, 5)
|
||||
private val itemHandler = container.handler(MatteryContainerFilterOnlyOut)
|
||||
private val itemHandler = container.handler(MatteryContainerHandler.OnlyOut)
|
||||
|
||||
override val defaultDisplayName: Component
|
||||
get() = MBlocks.MATTER_REPLICATOR.name
|
||||
|
@ -25,7 +25,7 @@ import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFractionConfigValue
|
||||
import ru.dbotthepony.mc.otm.core.defineImpreciseFraction
|
||||
@ -48,7 +48,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
val container = MatteryContainer(this::itemContainerUpdated, 1)
|
||||
override val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_VALUES)
|
||||
|
||||
private val itemHandler = container.handler(object : MatteryContainerFilter {
|
||||
private val itemHandler = container.handler(object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return canDecompose(stack)
|
||||
}
|
||||
|
@ -111,20 +111,20 @@ open class MatteryContainer(val watcher: Runnable, private val size: Int) : Cont
|
||||
insert_validator: (slot: Int, stack: ItemStack) -> Boolean,
|
||||
extract_validator: (slot: Int, amount: Int, stack: ItemStack) -> Boolean
|
||||
): MatteryContainerHandler {
|
||||
return MatteryContainerHandler(this, object : MatteryContainerFilter {
|
||||
return MatteryContainerHandler(this, object : MatteryContainerHooks {
|
||||
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: MatteryContainerFilter
|
||||
filter: MatteryContainerHooks
|
||||
): MatteryContainerHandler {
|
||||
return MatteryContainerHandler(this, filter)
|
||||
}
|
||||
|
||||
fun handler(insert_validator: (Int, ItemStack) -> Boolean): MatteryContainerHandler {
|
||||
return MatteryContainerHandler(this, object : MatteryContainerFilter {
|
||||
return MatteryContainerHandler(this, object : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack)
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = false
|
||||
})
|
||||
|
@ -4,7 +4,7 @@ import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import net.minecraftforge.items.IItemHandler
|
||||
|
||||
interface MatteryContainerFilter {
|
||||
interface MatteryContainerHooks {
|
||||
fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
@ -17,40 +17,32 @@ interface MatteryContainerFilter {
|
||||
fun preExtract(slot: Int, amount: Int, simulate: Boolean) {}
|
||||
}
|
||||
|
||||
object MatteryContainerFilterOnlyIn : MatteryContainerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
object MatteryContainerFilterOnlyOut : MatteryContainerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
object MatteryContainerFilterBoth : MatteryContainerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
class MatteryContainerHandler @JvmOverloads internal constructor(
|
||||
private val container: MatteryContainer,
|
||||
private val hooks: MatteryContainerFilter = MatteryContainerFilterBoth,
|
||||
private val hooks: MatteryContainerHooks = Both,
|
||||
) : IItemHandler {
|
||||
object OnlyIn : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
object OnlyOut : MatteryContainerHooks {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
object Both : MatteryContainerHooks
|
||||
|
||||
private var handler = LazyOptional.of<IItemHandler> { this }
|
||||
|
||||
fun get(): LazyOptional<IItemHandler> {
|
||||
|
Loading…
Reference in New Issue
Block a user