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