Move Battery bank to slotted container
This commit is contained in:
parent
51be2c89f4
commit
b4977ea6ae
@ -21,6 +21,9 @@ import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
||||
import ru.dbotthepony.mc.otm.capability.transcieveEnergy
|
||||
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.FilteredContainerSlot
|
||||
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.core.otmRandom
|
||||
@ -33,22 +36,31 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
|
||||
var gaugeLevel by syncher.float()
|
||||
private set
|
||||
|
||||
// 6 на 2
|
||||
val container: MatteryContainer = object : MatteryContainer(::setChanged, CAPACITY) {
|
||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||
super.setChanged(slot, new, old)
|
||||
batteryStatus[slot].value = new.getCapability(Capabilities.EnergyStorage.ITEM) != null
|
||||
private inner class Slot(container: SlottedContainer, slot: Int) : FilteredContainerSlot(container, slot) {
|
||||
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||
return super.canAutomationPlaceItem(itemStack) && itemStack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { it.canExtract() && it.extractEnergy(Int.MAX_VALUE, true) > 0 } == true
|
||||
}
|
||||
|
||||
override fun canAutomationTakeItem(desired: Int): Boolean {
|
||||
return super.canAutomationTakeItem(desired) && item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canExtract() || it.extractEnergy(Int.MAX_VALUE, true) <= 0 } != false
|
||||
}
|
||||
|
||||
override fun notifyChanged(old: ItemStack) {
|
||||
super.notifyChanged(old)
|
||||
|
||||
batteryStatus[slot].value = item.getCapability(Capabilities.EnergyStorage.ITEM) != null
|
||||
gaugeLevel = batteryLevel.percentage(maxBatteryLevel)
|
||||
}
|
||||
|
||||
override fun getMaxStackSize(): Int = 1
|
||||
}.also(::addDroppableContainer)
|
||||
|
||||
val batteryStatus = immutableList(CAPACITY) {
|
||||
syncher.boolean(false)
|
||||
override val maxStackSize: Int
|
||||
get() = 1
|
||||
}
|
||||
|
||||
val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(HandlerFilter.Dischargeable))
|
||||
// 6 на 2
|
||||
val container = SlottedContainer.simple(CAPACITY, ::Slot, ::markDirtyFast).also(::addDroppableContainer)
|
||||
val batteryStatus = immutableList(CAPACITY) { syncher.boolean(false) }
|
||||
|
||||
val itemConfig = ConfigurableItemHandler(inputOutput = container)
|
||||
|
||||
init {
|
||||
savetables.stateful(::container, INVENTORY_KEY)
|
||||
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
|
||||
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.immutableList
|
||||
import ru.dbotthepony.mc.otm.menu.BatteryMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
@ -21,7 +22,7 @@ class BatteryBankMenu(
|
||||
tile: BatteryBankBlockEntity? = null,
|
||||
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
|
||||
val powerLevel = ProfiledLevelGaugeWidget(this, tile?.energyConfig?.energy)
|
||||
val storageSlots: List<MatteryMenuSlot>
|
||||
val storageSlots: List<BatteryMenuSlot>
|
||||
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||
val energyConfig = EnergyConfigPlayerInput(this, allowPull = false, allowPush = true)
|
||||
val itemConfig = ItemConfigPlayerInput(this, allowPull = false, allowPush = false)
|
||||
@ -33,7 +34,7 @@ class BatteryBankMenu(
|
||||
itemConfig.with(tile.itemConfig)
|
||||
}
|
||||
|
||||
val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY)
|
||||
val container = tile?.container ?: SlottedContainer.filtered(BatteryBankBlockEntity.CAPACITY)
|
||||
|
||||
storageSlots = immutableList(BatteryBankBlockEntity.CAPACITY) {
|
||||
addStorageSlot(BatteryMenuSlot(container, it))
|
||||
|
Loading…
Reference in New Issue
Block a user