Add item configuration to matter capacitor bank

This commit is contained in:
DBotThePony 2023-03-25 20:27:48 +07:00
parent 37400a2d5d
commit 065dd8bbe6
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 19 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
import ru.dbotthepony.mc.otm.container.HandlerFilter
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.math.Decimal
@ -122,17 +123,27 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
val container = object : MatteryContainer(this::setChangedLight, BatteryBankBlockEntity.CAPACITY) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
super.setChanged(slot, new, old)
capacitorStatus[slot].value = new.getCapability(MatteryCapability.MATTER).isPresent
capacitorStatus[slot].boolean = new.getCapability(MatteryCapability.MATTER).isPresent
gaugeLevel = (storedMatter / maxStoredMatter).toFloat()
}
}.also(::addDroppableContainer)
val itemConfig = ConfigurableItemHandler(input = container.handler(object : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER).isPresent
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return false
}
}))
val capacitorStatus = immutableList(BatteryBankBlockEntity.CAPACITY) {
synchronizer.bool(false)
}
init {
savetable(::container, INVENTORY_KEY)
savetables.stateful(::container, INVENTORY_KEY)
exposeGlobally(MatteryCapability.MATTER, this)
exposeGlobally(MatteryCapability.MATTER_NODE, matterNode)
}

View File

@ -5,6 +5,7 @@ import ru.dbotthepony.mc.otm.menu.matter.MatterCapacitorBankMenu
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.slot.MatterCapacitorSlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
@ -22,6 +23,8 @@ class MatterCapacitorBankScreen(p_97741_: MatterCapacitorBankMenu, p_97742_: Inv
for (i in 6 .. 11)
MatterCapacitorSlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * (i - 6), 32f + 18f)
makeDeviceControls(this, frame, itemConfig = menu.itemConfig)
return frame
}
}

View File

@ -7,6 +7,7 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.MatterContainerInputSlot
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus
@ -14,11 +15,10 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
p_38852_: Int,
inventory: Inventory,
tile: MatterCapacitorBankBlockEntity? = null
) : MatteryMenu(
MMenus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile
) {
) : MatteryMenu(MMenus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile) {
val matterGauge = LevelGaugeWidget(this)
val totalMatterGauge = LevelGaugeWidget(this)
val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig)
val storageSlots: List<MatterContainerInputSlot>