Move Matter capacitor bank to slotted container

This commit is contained in:
DBotThePony 2025-03-03 15:00:30 +07:00
parent edb3aa657d
commit 6e7b90a8e8
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 24 additions and 19 deletions

View File

@ -18,14 +18,15 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage
import ru.dbotthepony.mc.otm.container.HandlerFilter
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.core.immutableList
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
import ru.dbotthepony.mc.otm.menu.matter.MatterCapacitorBankMenu
import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(
MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterStorage {
class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterStorage {
var gaugeLevel by syncher.float()
private set
@ -125,31 +126,34 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
override val matterFlow: FlowDirection
get() = FlowDirection.BI_DIRECTIONAL
val container = object : MatteryContainer(::markDirtyFast, BatteryBankBlockEntity.CAPACITY) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
super.setChanged(slot, new, old)
capacitorStatus[slot].value = new.getCapability(MatteryCapability.MATTER_ITEM) != null
private inner class Slot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
override fun notifyChanged(old: ItemStack) {
super.notifyChanged(old)
capacitorStatus[slot].value = item.getCapability(MatteryCapability.MATTER_ITEM) != null
gaugeLevel = storedMatter.percentage(maxStoredMatter)
}
override fun getMaxStackSize(): Int = 1
}.also(::addDroppableContainer)
val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(object : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.getCapability(MatteryCapability.MATTER_ITEM) != null
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
return super.canAutomationPlaceItem(itemStack) && itemStack.getCapability(MatteryCapability.MATTER_ITEM) != null
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
stack.getCapability(MatteryCapability.MATTER_ITEM)?.let {
override fun canAutomationTakeItem(desired: Int): Boolean {
item.getCapability(MatteryCapability.MATTER_ITEM)?.let {
if (it.storedMatter.isPositive) {
return false
}
}
return true
return super.canAutomationTakeItem(desired)
}
}))
override val maxStackSize: Int
get() = 1
}
val container = SlottedContainer.simple(BatteryBankBlockEntity.CAPACITY, ::Slot, ::markDirtyFast).also(::addDroppableContainer)
val itemConfig = ConfigurableItemHandler(inputOutput = container)
val capacitorStatus = immutableList(BatteryBankBlockEntity.CAPACITY) {
syncher.boolean(false)

View File

@ -1,9 +1,10 @@
package ru.dbotthepony.mc.otm.menu.matter
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.menu.MatterContainerInputMenuSlot
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
@ -31,9 +32,9 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
})
}
val container = tile?.container ?: SimpleContainer(2 * 6)
val container = tile?.container ?: SlottedContainer.simple(BatteryBankBlockEntity.CAPACITY)
storageSlots = immutableList(2 * 6) {
storageSlots = immutableList(BatteryBankBlockEntity.CAPACITY) {
addStorageSlot(MatterContainerInputMenuSlot(container, it))
}