Update Chemical generator to use SlottedContainer

This commit is contained in:
DBotThePony 2025-03-07 18:33:29 +07:00
parent af4123990f
commit 4107ec2313
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 16 additions and 15 deletions

View File

@ -14,6 +14,8 @@ import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
import ru.dbotthepony.mc.otm.config.MachinesConfig
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.SlottedContainer
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
import ru.dbotthepony.mc.otm.core.math.Decimal
@ -23,20 +25,16 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
return ChemicalGeneratorMenu(containerID, inventory, this)
}
val batteryContainer = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val residueContainer = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val fuelContainer = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val batteryItemHandler = batteryContainer.handler(HandlerFilter.Chargeable)
val residueItemHandler = residueContainer.handler(HandlerFilter.OnlyOut)
val fuelItemHandler = fuelContainer.handler(HandlerFilter.ChemicalFuel)
val batteryContainer = SlottedContainer.simple(1, AutomationFilters.DISCHARGABLE.filteredProvider, ::markDirtyFast).also(::addDroppableContainer)
val residueContainer = SlottedContainer.simple(1, AutomationFilters.ONLY_OUT.simpleProvider, ::markDirtyFast).also(::addDroppableContainer)
val fuelContainer = SlottedContainer.simple(1, AutomationFilters.CHEMICAL_FUEL.filteredProvider, ::markDirtyFast).also(::addDroppableContainer)
val energy = ProfiledEnergyStorage(GeneratorEnergyStorage(::markDirtyFast, MachinesConfig.ChemicalGenerator.VALUES::energyCapacity, MachinesConfig.ChemicalGenerator.VALUES::energyThroughput))
val itemConfig = ConfigurableItemHandler(
input = fuelItemHandler,
output = residueItemHandler,
battery = batteryItemHandler,
input = fuelContainer,
output = residueContainer,
battery = batteryContainer,
backDefault = ItemHandlerMode.BATTERY)
val energyConfig = ConfigurableEnergy(energy)

View File

@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.UserFilteredSlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
@ -35,7 +36,7 @@ class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory,
progress.setRecipeType { listOf(RecipeTypes.FUELING) }
SlotPanel(this, frame, menu.residueSlot, 56f, PROGRESS_SLOT_TOP)
SlotPanel(this, frame, menu.fuelSlot, 104f, PROGRESS_SLOT_TOP)
UserFilteredSlotPanel(this, frame, menu.fuelSlot, 104f, PROGRESS_SLOT_TOP)
makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, itemConfig = menu.itemConfig, energyConfig = menu.energyConfig)

View File

@ -1,6 +1,5 @@
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 net.neoforged.neoforge.capabilities.Capabilities
@ -8,8 +7,11 @@ import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
@ -30,19 +32,19 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t
}
}
val fuelSlot = object : MatteryMenuSlot(tile?.fuelContainer ?: SimpleContainer(1), 0) {
val fuelSlot = object : UserFilteredMenuSlot(tile?.fuelContainer ?: SlottedContainer.filtered(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return itemStack.getBurnTime(null) > 0
}
}
val residueSlot = object : MatteryMenuSlot(tile?.residueContainer ?: SimpleContainer(1), 0) {
val residueSlot = object : MatteryMenuSlot(tile?.residueContainer ?: EnhancedContainer(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return false
}
}
val batterySlot = object : MatteryMenuSlot(tile?.batteryContainer ?: SimpleContainer(1), 0) {
val batterySlot = object : UserFilteredMenuSlot(tile?.batteryContainer ?: SlottedContainer.filtered(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return itemStack.getCapability(Capabilities.EnergyStorage.ITEM)?.canReceive() ?: false
}