Update Energy servo to use SlottedContainer, as well as make it behave better with automation

This commit is contained in:
DBotThePony 2025-03-07 19:53:09 +07:00
parent 54c2964deb
commit 101bf52113
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 13 additions and 24 deletions

View File

@ -17,13 +17,17 @@ 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.HandlerFilter
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.container.slotted.and
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.tech.EnergyServoMenu
import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_SERVO, blockPos, blockState) {
val discharge = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val charge = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val discharge = SlottedContainer.simple(1, AutomationFilters.DISCHARGABLE.filteredProvider, ::markDirtyFast).also(::addDroppableContainer)
val charge = SlottedContainer.simple(1, AutomationFilters.CHARGEABLE.filteredProvider, ::markDirtyFast).also(::addDroppableContainer)
val energy: ProfiledEnergyStorage<IMatteryEnergyStorage> = ProfiledEnergyStorage(object : IMatteryEnergyStorage {
override val energyFlow: FlowDirection get() {
@ -61,11 +65,7 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
})
val energyConfig = ConfigurableEnergy(energy, possibleModes = FlowDirection.BI_DIRECTIONAL)
val itemConfig = ConfigurableItemHandler(
input = charge.handler(HandlerFilter.OnlyIn.and(HandlerFilter.Chargeable)),
output = discharge.handler(HandlerFilter.OnlyOut.and(HandlerFilter.Dischargeable))
)
val itemConfig = ConfigurableItemHandler(input = charge, output = discharge)
init {
savetables.stateful(::charge)

View File

@ -1,36 +1,25 @@
package ru.dbotthepony.mc.otm.menu.tech
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
import ru.dbotthepony.mc.otm.capability.energy
import ru.dbotthepony.mc.otm.capability.FlowDirection
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.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
import ru.dbotthepony.mc.otm.registry.game.MMenus
class EnergyServoMenu @JvmOverloads constructor(
class EnergyServoMenu(
p_38852_: Int,
inventory: Inventory,
tile: EnergyServoBlockEntity? = null
) : MatteryMenu(MMenus.ENERGY_SERVO, p_38852_, inventory, tile) {
val dischargeSlot = object : MatteryMenuSlot(tile?.discharge ?: SimpleContainer(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return super.mayPlace(itemStack) && (itemStack.energy?.canExtract() ?: false)
}
}
val chargeSlot = object : MatteryMenuSlot(tile?.charge ?: SimpleContainer(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return super.mayPlace(itemStack) && (itemStack.energy?.canReceive() ?: false)
}
}
val dischargeSlot = BatteryMenuSlot(tile?.discharge ?: SlottedContainer.filtered(1), 0, direction = FlowDirection.OUTPUT)
val chargeSlot = BatteryMenuSlot(tile?.charge ?: SlottedContainer.filtered(1), 0, direction = FlowDirection.INPUT)
val equipment = makeEquipmentSlots(mapMoveToExternal = true)
val powerGauge = ProfiledLevelGaugeWidget(this, tile?.energy)