From 49bb695af2a17d6dd3be5ab8bd4458f4975593b9 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 8 Oct 2022 17:38:45 +0700 Subject: [PATCH] Move stuff around --- .../block/entity/BatteryBankBlockEntity.kt | 4 +- .../otm/block/entity/CargoCrateBlockEntity.kt | 4 +- .../entity/ChemicalGeneratorBlockEntity.kt | 4 +- .../block/entity/EnergyServoBlockEntity.kt | 4 +- .../otm/block/entity/PlatePressBlockEntity.kt | 4 +- .../entity/matter/MatterBottlerBlockEntity.kt | 4 +- .../matter/MatterDecomposerBlockEntity.kt | 4 +- .../matter/MatterRecyclerBlockEntity.kt | 4 +- .../matter/MatterReplicatorBlockEntity.kt | 5 +- .../entity/matter/MatterScannerBlockEntity.kt | 4 +- .../mc/otm/container/MatteryContainer.kt | 6 +- .../otm/container/MatteryContainerHandler.kt | 56 ++++++++----------- 12 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt index 69e79dc4c..289899783 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt @@ -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 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt index 37c3b16b7..f8097ed6f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt @@ -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() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt index 7945be571..c3bff5c4e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyServoBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyServoBlockEntity.kt index 358cf545f..ee23dad42 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyServoBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyServoBlockEntity.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt index e28155c3f..c283f6a06 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt @@ -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 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index 5dbcb3478..963c52ee0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt index 32e3042dd..17757703f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt @@ -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 { - container.handler(object : MatteryContainerFilter { + container.handler(object : MatteryContainerHooks { override fun canInsert(slot: Int, stack: ItemStack): Boolean { return slot == INPUT_SLOT && canDecompose(stack) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index 6d88c8853..9c49a3041 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -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 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index bed287e47..1983fb99d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt index 564e3f8b3..8fe2f7fea 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt @@ -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) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt index f0b721bcd..0aa3974a0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt @@ -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 }) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainerHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainerHandler.kt index 2d8172003..f37e9a581 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainerHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainerHandler.kt @@ -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 { this } fun get(): LazyOptional {