diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyHatchBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyHatchBlockEntity.kt index 4e6dfd6ca..d9a8c7517 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyHatchBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyHatchBlockEntity.kt @@ -18,6 +18,8 @@ import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters +import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.core.multiblock.BlockEntityTag import ru.dbotthepony.mc.otm.menu.tech.EnergyHatchMenu @@ -32,13 +34,12 @@ class EnergyHatchBlockEntity( ) : MatteryDeviceBlockEntity(type, blockPos, blockState) { val energy = ProfiledEnergyStorage(BlockEnergyStorageImpl(this::markDirtyFast, FlowDirection.input(isInput), capacity)) - val container = object : MatteryContainer(::markDirtyFast, CAPACITY) { - override fun getMaxStackSize(slot: Int, itemStack: ItemStack): Int { - return 1 - } - }.also(::addDroppableContainer) + val container = SlottedContainer.simple( + CAPACITY, + if (isInput) AutomationFilters.DISCHARGABLE.limitedFilteredProvider else AutomationFilters.CHARGEABLE.limitedFilteredProvider, + ::markDirtyFast + ).also(::addDroppableContainer) - val itemHandler = container.handler(if (isInput) HandlerFilter.Dischargeable else HandlerFilter.Chargeable) private val neighbours = ArrayList>() init { @@ -47,7 +48,7 @@ class EnergyHatchBlockEntity( // it would cause a lot of frustration if hatches accept stuff only though one face exposeEnergyGlobally(energy) - exposeGlobally(Capabilities.ItemHandler.BLOCK, itemHandler) + exposeGlobally(Capabilities.ItemHandler.BLOCK, container) if (!isInput) { for (side in RelativeSide.entries) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt index c657e90bc..9042393d5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt @@ -140,9 +140,13 @@ open class OutputMenuSlot(container: Container, index: Int, x: Int = 0, y: Int = } } -open class BatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int = 0) : UserFilteredMenuSlot(container, index, x, y) { +open class BatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int = 0, val direction: FlowDirection = FlowDirection.BI_DIRECTIONAL) : UserFilteredMenuSlot(container, index, x, y) { override fun mayPlace(itemStack: ItemStack): Boolean { - return super.mayPlace(itemStack) && (itemStack.energy?.canExtract() ?: false) + if (!super.mayPlace(itemStack)) + return false + + val energy = itemStack.energy ?: return false + return direction.test(FlowDirection.of(energy.canReceive(), energy.canExtract())) } } @@ -158,12 +162,6 @@ open class ChargeMenuSlot(container: Container, index: Int, x: Int = 0, y: Int = } } -open class EnergyContainerInputMenuSlot(container: Container, index: Int, x: Int = 0, y: Int = 0, val direction: FlowDirection = FlowDirection.BI_DIRECTIONAL) : MatteryMenuSlot(container, index, x, y) { - override fun mayPlace(itemStack: ItemStack): Boolean { - return super.mayPlace(itemStack) && (itemStack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { direction.test(FlowDirection.of(it.canReceive(), it.canExtract())) } ?: false) - } -} - open class MatterContainerInputMenuSlot( container: Container, index: Int, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyHatchMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyHatchMenu.kt index 4a97d460f..e4f8c4c0e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyHatchMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyHatchMenu.kt @@ -1,12 +1,12 @@ package ru.dbotthepony.mc.otm.menu.tech -import net.minecraft.world.Container -import net.minecraft.world.SimpleContainer import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting import ru.dbotthepony.mc.otm.block.entity.tech.EnergyHatchBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection -import ru.dbotthepony.mc.otm.menu.EnergyContainerInputMenuSlot +import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters +import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer +import ru.dbotthepony.mc.otm.menu.BatteryMenuSlot import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback import ru.dbotthepony.mc.otm.menu.makeSlots @@ -19,10 +19,13 @@ class EnergyHatchMenu( inventory: Inventory, tile: EnergyHatchBlockEntity? = null ) : MatteryMenu(if (isInput) MMenus.ENERGY_INPUT_HATCH else MMenus.ENERGY_OUTPUT_HATCH, containerId, inventory, tile) { - val container: Container = tile?.container ?: SimpleContainer(EnergyHatchBlockEntity.CAPACITY) + val container = tile?.container ?: SlottedContainer.simple( + EnergyHatchBlockEntity.CAPACITY, + if (isInput) AutomationFilters.DISCHARGABLE.limitedFilteredProvider else AutomationFilters.CHARGEABLE.limitedFilteredProvider + ) val inputSlots = makeSlots(container) { a, b -> - EnergyContainerInputMenuSlot(a, b, direction = FlowDirection.input(isInput)) + BatteryMenuSlot(a, b, direction = FlowDirection.input(isInput)) } val gauge = ProfiledLevelGaugeWidget(this, tile?.energy)