Update Driver Rack to use SlottedContainer

This commit is contained in:
DBotThePony 2025-03-11 20:50:59 +07:00
parent 1f8cd2cfe3
commit c08ea8a43d
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 11 additions and 6 deletions

View File

@ -15,6 +15,8 @@ import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.config.MachinesConfig
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.menu.storage.DriveRackMenu
import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
import ru.dbotthepony.mc.otm.storage.optics.priority
@ -45,19 +47,21 @@ class DriveRackBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
markDirtyFast()
}
val container: MatteryContainer = object : MatteryContainer(::markDirtyFast, 4) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
super.setChanged(slot, new, old)
private inner class Slot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
override fun notifyChanged(old: ItemStack) {
super.notifyChanged(old)
old.getCapability(MatteryCapability.CONDENSATION_DRIVE)?.let {
cell.removeStorageComponent(it.priority(::insertPriority, ::extractPriority).powered(energy).flow(::mode))
}
new.getCapability(MatteryCapability.CONDENSATION_DRIVE)?.let {
item.getCapability(MatteryCapability.CONDENSATION_DRIVE)?.let {
cell.addStorageComponent(it.priority(::insertPriority, ::extractPriority).powered(energy).flow(::mode))
}
}
}.also(::addDroppableContainer)
}
val container = SlottedContainer.simple(4, ::Slot, ::markDirtyFast).also(::addDroppableContainer)
init {
savetables.stateful(::energy, ENERGY_KEY)

View File

@ -4,6 +4,7 @@ import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity
import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.menu.DriveMenuSlot
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
@ -18,7 +19,7 @@ class DriveRackMenu @JvmOverloads constructor(
inventory: Inventory,
tile: DriveRackBlockEntity? = null
) : MatteryPoweredMenu(MMenus.DRIVE_RACK, containerId, inventory, tile) {
val storageSlots = makeSlots(tile?.container ?: SimpleContainer(4), ::DriveMenuSlot)
val storageSlots = makeSlots(tile?.container ?: EnhancedContainer(4), ::DriveMenuSlot)
val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig)
val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget)
val insertPriority = IntInputWithFeedback(this, tile?.let { it::insertPriority })