New quickmove implementation

This commit is contained in:
DBotThePony 2023-03-02 22:14:02 +07:00
parent d151fd6727
commit dd4be8b961
Signed by: DBot
GPG Key ID: DCC23B5715498507
29 changed files with 152 additions and 147 deletions

View File

@ -18,8 +18,6 @@ import ru.dbotthepony.mc.otm.network.ExoSuitSlotPacket
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMenu(null, CONTAINER_ID, capability.ply.inventory) { class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMenu(null, CONTAINER_ID, capability.ply.inventory) {
override val storageSlots: Collection<Slot> get() = listOf()
val craftingGrid: CraftingContainer val craftingGrid: CraftingContainer
val craftingSlots: List<MatterySlot> val craftingSlots: List<MatterySlot>
@ -52,6 +50,19 @@ class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
init { init {
addInventorySlots(autoFrame = false) addInventorySlots(autoFrame = false)
for (slot in playerCombinedInventorySlots) {
mapQuickMove(slot, playerHotbarSlots)
}
for (slot in playerHotbarSlots) {
mapQuickMove(slot, playerCombinedInventorySlots)
}
for (slot in craftingSlots) {
mapQuickMove(slot, playerInventorySlots)
}
craftingSlots.forEach(this::addSlot) craftingSlots.forEach(this::addSlot)
} }
@ -65,6 +76,7 @@ class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
val allAccessibleSlots: List<Slot> val allAccessibleSlots: List<Slot>
init { init {
mapQuickMove(offhandSlot, playerInventorySlots)
addSlot(offhandSlot) addSlot(offhandSlot)
val builder = ImmutableList.builder<Slot>() val builder = ImmutableList.builder<Slot>()
@ -81,11 +93,11 @@ class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
init { init {
for ((a, b) in curiosSlots) { for ((a, b) in curiosSlots) {
addSlot(a) addSlot(a)
storage2Inventory(a) mapQuickMoveToInventory(a)
if (b != null) { if (b != null) {
addSlot(b) addSlot(b)
storage2Inventory(b) mapQuickMoveToInventory(b)
} }
} }
} }
@ -143,32 +155,6 @@ class ExoPackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
return ItemStack.EMPTY return ItemStack.EMPTY
} }
if (!autoRegisteredStorageSlots) {
autoRegisteredStorageSlots = true
for (slot in playerCombinedInventorySlots) {
quickMoveMapping[slot] = ::playerHotbarSlots
}
for (slot in playerHotbarSlots) {
quickMoveMapping[slot] = ::playerCombinedInventorySlots
}
for (slot in craftingSlots) {
quickMoveMapping[slot] = ::playerInventorySlots
}
for (slot in armorSlots) {
quickMoveMapping[slot.functional] = ::playerInventorySlots
if (slot.cosmetic != null) {
quickMoveMapping[slot.cosmetic] = ::playerInventorySlots
}
}
quickMoveMapping[offhandSlot] = ::playerInventorySlots
}
if (slotIndex == craftingResultSlot.index) { if (slotIndex == craftingResultSlot.index) {
val item = craftingResultSlot.item val item = craftingResultSlot.item
val leftover = moveItemStackToSlots(item, playerInventorySlots2, simulate = true) val leftover = moveItemStackToSlots(item, playerInventorySlots2, simulate = true)

View File

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList
import com.mojang.datafixers.util.Pair import com.mojang.datafixers.util.Pair
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream import it.unimi.dsi.fastutil.io.FastByteArrayInputStream
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.FriendlyByteBuf
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
@ -281,7 +282,9 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
_playerInventorySlots2.add(slot) _playerInventorySlots2.add(slot)
_playerMainSlots.add(slot) _playerMainSlots.add(slot)
_playerCombinedInventorySlots.add(slot) _playerCombinedInventorySlots.add(slot)
inventory2Storage(slot)
mapQuickMove(slot, equipmentSlots)
mapQuickMoveToExternal(slot)
addSlot(slot) addSlot(slot)
} }
@ -295,7 +298,9 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
_playerInventorySlots2.add(slot) _playerInventorySlots2.add(slot)
_playerExoSuitSlots.add(slot) _playerExoSuitSlots.add(slot)
_playerCombinedInventorySlots.add(slot) _playerCombinedInventorySlots.add(slot)
inventory2Storage(slot)
mapQuickMove(slot, equipmentSlots)
mapQuickMoveToExternal(slot)
addSlot(slot) addSlot(slot)
} }
} }
@ -303,11 +308,13 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
for (i in 0..8) { for (i in 0..8) {
val slot = InventorySlot(inventory, i) val slot = InventorySlot(inventory, i)
addSlot(slot)
_playerInventorySlots2.add(i, slot) _playerInventorySlots2.add(i, slot)
_playerInventorySlots.add(slot) _playerInventorySlots.add(slot)
_playerHotbarSlots.add(slot) _playerHotbarSlots.add(slot)
inventory2Storage(slot)
mapQuickMove(slot, equipmentSlots)
mapQuickMoveToExternal(slot)
addSlot(slot)
} }
} }
@ -372,50 +379,99 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
return player.distanceToSqr(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0 return player.distanceToSqr(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0
} }
abstract val storageSlots: Collection<Slot> private val externalSlots = ArrayList<Slot>()
protected val quickMoveMapping = Reference2ObjectOpenHashMap<Slot, () -> Collection<Slot>?>() private val quickMoveMapping = Reference2ObjectOpenHashMap<Slot, ArrayList<Collection<Slot>>>()
override fun addSlot(pSlot: Slot): Slot {
if (pSlot in slots) {
return pSlot
}
return super.addSlot(pSlot)
}
/**
* Adds slot to "storage slots" list (utilized by quick move) and calls [addSlot]
*/
protected fun <T : Slot> addStorageSlot(slot: T, addMapping: Boolean = true): T {
if (slot !in externalSlots) {
addSlot(slot)
externalSlots.add(slot)
if (addMapping) {
mapQuickMove(slot, equipmentSlots)
mapQuickMoveToInventory(slot)
}
}
return slot
}
protected fun addStorageSlot(slot: Iterable<Slot>, addMapping: Boolean = true) {
for (value in slot)
addStorageSlot(value, addMapping)
}
/** /**
* Marks slot as "storage" - shift clicking it will move its contents to Player's inventory * Marks slot as "storage" - shift clicking it will move its contents to Player's inventory
*/ */
protected fun storage2Inventory(slot: Slot) { protected fun mapQuickMoveToInventory(slot: Slot, prepend: Boolean = false) {
quickMoveMapping[slot] = ::playerInventorySlots mapQuickMove(slot, playerInventorySlots, prepend = prepend)
} }
/** /**
* Marks slot as "inventory" - shift clicking it will move its contents to menu's storage slots * Marks slot as "inventory" - shift clicking it will move its contents to menu's storage slots
*/ */
protected fun inventory2Storage(slot: Slot) { protected fun mapQuickMoveToExternal(slot: Slot, prepend: Boolean = false) {
quickMoveMapping[slot] = ::storageSlots mapQuickMove(slot, externalSlots, prepend = prepend)
} }
protected var autoRegisteredStorageSlots = false protected fun mapQuickMove(slot: Slot, target: Collection<Slot>, prepend: Boolean = false) {
val listing = quickMoveMapping.computeIfAbsent(slot, Reference2ObjectFunction { ArrayList(1) })
listing.remove(target)
if (prepend)
listing.add(0, target)
else
listing.add(target)
}
protected fun mapQuickMove(slot: Slot, vararg target: Collection<Slot>) {
for (value in target) {
mapQuickMove(slot, value)
}
}
// This method receive Player interactor and slot_index where Shift + Right click occurred // This method receive Player interactor and slot_index where Shift + Right click occurred
// It shall return item stack that got moved // It shall return item stack that got moved
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack { override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
if (!slots[slotIndex].hasItem() || !slots[slotIndex].mayPickup(ply)) {
return ItemStack.EMPTY
}
if (!autoRegisteredStorageSlots) {
autoRegisteredStorageSlots = true
for (slot in storageSlots) {
storage2Inventory(slot)
}
}
val slot = slots[slotIndex] val slot = slots[slotIndex]
val target = quickMoveMapping[slot]?.invoke() ?: return ItemStack.EMPTY
val copy = slots[slotIndex].item.copy()
if (moveItemStackTo(slots[slotIndex], target)) if (!slot.hasItem() || !slot.mayPickup(ply)) {
return copy
else
return ItemStack.EMPTY return ItemStack.EMPTY
} }
val target = quickMoveMapping[slot] ?: return ItemStack.EMPTY
val copy = slot.item.copy()
var any = false
for (collection in target) {
if (moveItemStackTo(slot, collection)) {
any = true
if (!slot.hasItem()) {
return copy
}
}
}
if (any) {
return copy
} else {
return ItemStack.EMPTY
}
}
fun quickMoveToInventory(stack: ItemStack, simulate: Boolean): ItemStack { fun quickMoveToInventory(stack: ItemStack, simulate: Boolean): ItemStack {
if (_playerInventorySlots.isEmpty()) { if (_playerInventorySlots.isEmpty()) {
return stack return stack
@ -546,11 +602,15 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
return moveItemStackToSlots(item, slots, simulate) return moveItemStackToSlots(item, slots, simulate)
} }
public override fun addDataSlots(p_38885_: ContainerData) { private var armorSlots: ImmutableList<PlayerSlot<EquipmentSlot, Slot>>? = null
super.addDataSlots(p_38885_) private var curiosSlots: ImmutableList<PlayerSlot<Slot, Slot>>? = null
} private val equipmentSlots = ArrayList<Slot>()
fun makeArmorSlots(): List<PlayerSlot<EquipmentSlot, Slot>> { fun makeArmorSlots(): List<PlayerSlot<EquipmentSlot, Slot>> {
if (armorSlots != null) {
return armorSlots!!
}
val cosmetic = ply.cosmeticArmorSlots val cosmetic = ply.cosmeticArmorSlots
return ImmutableList.of( return ImmutableList.of(
@ -559,9 +619,15 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
PlayerSlot(EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.LEGS), cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.LEGS)), PlayerSlot(EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.LEGS), cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.LEGS)),
PlayerSlot(EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.FEET), cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.FEET)), PlayerSlot(EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.FEET), cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.FEET)),
).also { ).also {
armorSlots = it
for ((a, b) in it) { for ((a, b) in it) {
equipmentSlots.add(a)
addSlot(a) addSlot(a)
if (b != null) addSlot(b) if (b != null) addSlot(b)
mapQuickMoveToInventory(a)
if (b != null) mapQuickMoveToInventory(b)
} }
} }
} }
@ -569,12 +635,16 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
fun makeEquipmentSlots(): EquipmentSlots { fun makeEquipmentSlots(): EquipmentSlots {
return EquipmentSlots( return EquipmentSlots(
armorSlots = makeArmorSlots(), armorSlots = makeArmorSlots(),
curiosSlots = ImmutableList.copyOf(ply.curiosSlots).also { curiosSlots = curiosSlots ?: ImmutableList.copyOf(ply.curiosSlots).also {
for ((a, b) in it) { for ((a, b) in it) {
equipmentSlots.add(a)
addSlot(a) addSlot(a)
if (b != null) addSlot(b) if (b != null) addSlot(b)
mapQuickMoveToInventory(a)
if (b != null) mapQuickMoveToInventory(b)
} }
} }.also { curiosSlots = it }
) )
} }

View File

@ -28,5 +28,6 @@ abstract class MatteryPoweredMenu protected constructor(
} }
addSlot(batterySlot) addSlot(batterySlot)
mapQuickMoveToInventory(batterySlot)
} }
} }

View File

@ -14,7 +14,7 @@ class CargoCrateMenu @JvmOverloads constructor(
inventory: Inventory, inventory: Inventory,
tile: CargoCrateBlockEntity? = null tile: CargoCrateBlockEntity? = null
) : MatteryMenu(MMenus.CARGO_CRATE, p_38852_, inventory, tile) { ) : MatteryMenu(MMenus.CARGO_CRATE, p_38852_, inventory, tile) {
override val storageSlots: List<MatterySlot> val storageSlots: List<MatterySlot>
private val trackedPlayerOpen = !inventory.player.isSpectator private val trackedPlayerOpen = !inventory.player.isSpectator
@ -22,9 +22,7 @@ class CargoCrateMenu @JvmOverloads constructor(
val container = tile?.container ?: SimpleContainer(CargoCrateBlockEntity.CAPACITY) val container = tile?.container ?: SimpleContainer(CargoCrateBlockEntity.CAPACITY)
storageSlots = ImmutableList(CargoCrateBlockEntity.CAPACITY) { storageSlots = ImmutableList(CargoCrateBlockEntity.CAPACITY) {
val slot = MatterySlot(container, it) addStorageSlot(MatterySlot(container, it))
addSlot(slot)
return@ImmutableList slot
} }
if (trackedPlayerOpen) { if (trackedPlayerOpen) {

View File

@ -30,7 +30,4 @@ class HoloSignMenu @JvmOverloads constructor(
redstone.with(tile.redstoneControl::redstoneSetting) redstone.with(tile.redstoneControl::redstoneSetting)
} }
} }
override val storageSlots: Collection<Slot>
get() = listOf()
} }

View File

@ -16,7 +16,7 @@ class MinecartCargoCrateMenu @JvmOverloads constructor(
inventory: Inventory, inventory: Inventory,
val cart: MinecartCargoCrate? = null val cart: MinecartCargoCrate? = null
) : MatteryMenu(MMenus.CARGO_CRATE, p_38852_, inventory) { ) : MatteryMenu(MMenus.CARGO_CRATE, p_38852_, inventory) {
override val storageSlots: List<MatterySlot> val storageSlots: List<MatterySlot>
private val trackedPlayerOpen = !inventory.player.isSpectator private val trackedPlayerOpen = !inventory.player.isSpectator
@ -24,9 +24,7 @@ class MinecartCargoCrateMenu @JvmOverloads constructor(
val container = cart as Container? ?: SimpleContainer(CargoCrateBlockEntity.CAPACITY) val container = cart as Container? ?: SimpleContainer(CargoCrateBlockEntity.CAPACITY)
storageSlots = ImmutableList(CargoCrateBlockEntity.CAPACITY) { storageSlots = ImmutableList(CargoCrateBlockEntity.CAPACITY) {
val slot = MatterySlot(container, it) addStorageSlot(MatterySlot(container, it))
addSlot(slot)
return@ImmutableList slot
} }
if (trackedPlayerOpen) { if (trackedPlayerOpen) {

View File

@ -28,7 +28,7 @@ class MatterBottlerMenu @JvmOverloads constructor(
val progressWidget: ProgressGaugeWidget val progressWidget: ProgressGaugeWidget
val matterWidget: LevelGaugeWidget val matterWidget: LevelGaugeWidget
override val storageSlots: List<MatterySlot> val storageSlots: List<MatterySlot>
init { init {
val container = tile?.container ?: SimpleContainer(6) val container = tile?.container ?: SimpleContainer(6)
@ -57,7 +57,7 @@ class MatterBottlerMenu @JvmOverloads constructor(
} }
} }
storageSlots.forEach(this::addSlot) storageSlots.forEach(this::addStorageSlot)
addInventorySlots() addInventorySlots()
} }
} }

View File

@ -20,7 +20,7 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
val matterGauge: LevelGaugeWidget val matterGauge: LevelGaugeWidget
val totalMatterGauge: LevelGaugeWidget val totalMatterGauge: LevelGaugeWidget
override val storageSlots: List<MatterContainerInputSlot> val storageSlots: List<MatterContainerInputSlot>
init { init {
if (tile == null) { if (tile == null) {
@ -38,9 +38,7 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
val container = tile?.container ?: SimpleContainer(2 * 6) val container = tile?.container ?: SimpleContainer(2 * 6)
storageSlots = ImmutableList(2 * 6) { storageSlots = ImmutableList(2 * 6) {
val slot = MatterContainerInputSlot(container, it) addStorageSlot(MatterContainerInputSlot(container, it))
addSlot(slot)
slot
} }
addInventorySlots() addInventorySlots()

View File

@ -48,12 +48,10 @@ class MatterDecomposerMenu @JvmOverloads constructor(
progressWidget = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) progressWidget = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess)
} }
addStorageSlot(outputMain)
addStorageSlot(outputStacking)
addStorageSlot(input)
addInventorySlots() addInventorySlots()
} }
override val storageSlots: List<Slot> = ImmutableList.of(
addSlot(outputMain),
addSlot(outputStacking),
addSlot(input),
)
} }

View File

@ -294,9 +294,6 @@ class MatterPanelMenu @JvmOverloads constructor(
} }
} }
override val storageSlots: Collection<Slot>
get() = emptyList()
companion object { companion object {
private val LOGGER = LogManager.getLogger() private val LOGGER = LogManager.getLogger()
} }

View File

@ -37,9 +37,7 @@ class MatterRecyclerMenu @JvmOverloads constructor(
progress = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) progress = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess)
} }
addSlot(input) addStorageSlot(input)
addInventorySlots() addInventorySlots()
} }
override val storageSlots: Collection<Slot> = ImmutableList.of(input)
} }

View File

@ -20,15 +20,13 @@ class MatterReplicatorMenu @JvmOverloads constructor(
) { ) {
val matter: LevelGaugeWidget val matter: LevelGaugeWidget
val progress: ProgressGaugeWidget val progress: ProgressGaugeWidget
override val storageSlots: List<MachineOutputSlot> val storageSlots: List<MachineOutputSlot>
init { init {
val container = tile?.container ?: SimpleContainer(5) val container = tile?.container ?: SimpleContainer(5)
storageSlots = ImmutableList(5) { storageSlots = ImmutableList(5) {
val slot = MachineOutputSlot(container, it) addStorageSlot(MachineOutputSlot(container, it))
addSlot(slot)
return@ImmutableList slot
} }
if (tile != null) { if (tile != null) {

View File

@ -31,7 +31,7 @@ class MatterScannerMenu @JvmOverloads constructor(
override fun mayPlace(itemStack: ItemStack) = MatterManager.canDecompose(itemStack) override fun mayPlace(itemStack: ItemStack) = MatterManager.canDecompose(itemStack)
} }
addSlot(input) addStorageSlot(input)
if (tile != null) { if (tile != null) {
progress = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) progress = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess)
@ -45,6 +45,4 @@ class MatterScannerMenu @JvmOverloads constructor(
addInventorySlots() addInventorySlots()
} }
override val storageSlots: List<MatterySlot> = listOf(input)
} }

View File

@ -20,7 +20,7 @@ class PatternStorageMenu @JvmOverloads constructor(
val storedThis: LevelGaugeWidget val storedThis: LevelGaugeWidget
val storedGrid: LevelGaugeWidget val storedGrid: LevelGaugeWidget
override val storageSlots: List<PatternSlot> val storageSlots: List<PatternSlot>
init { init {
if (tile == null) { if (tile == null) {
@ -38,11 +38,9 @@ class PatternStorageMenu @JvmOverloads constructor(
val patterns = tile?.container ?: SimpleContainer(2 * 4) val patterns = tile?.container ?: SimpleContainer(2 * 4)
storageSlots = ImmutableList(2 * 4) { storageSlots = ImmutableList(2 * 4) {
PatternSlot(patterns, it) addStorageSlot(PatternSlot(patterns, it))
} }
storageSlots.forEach(this::addSlot)
addInventorySlots() addInventorySlots()
} }
} }

View File

@ -14,15 +14,13 @@ class DriveRackMenu @JvmOverloads constructor(
inventory: Inventory, inventory: Inventory,
tile: DriveRackBlockEntity? = null tile: DriveRackBlockEntity? = null
) : MatteryPoweredMenu(MMenus.DRIVE_RACK, p_38852_, inventory, tile) { ) : MatteryPoweredMenu(MMenus.DRIVE_RACK, p_38852_, inventory, tile) {
override val storageSlots: List<MatterySlot> val storageSlots: List<MatterySlot>
init { init {
val container = tile?.container ?: SimpleContainer(4) val container = tile?.container ?: SimpleContainer(4)
storageSlots = ImmutableList(4) { storageSlots = ImmutableList(4) {
val slot = DriveSlot(container, it) addStorageSlot(DriveSlot(container, it))
addSlot(slot)
slot
} }
addInventorySlots() addInventorySlots()

View File

@ -56,12 +56,10 @@ class DriveViewerMenu @JvmOverloads constructor(
powered = null powered = null
} }
addSlot(driveSlot) addStorageSlot(driveSlot)
addInventorySlots() addInventorySlots()
} }
override val storageSlots: List<Slot> = ImmutableList.of(driveSlot, batterySlot)
val driveFilter = ItemFilter(PortableCondensationDriveItem.MAX_FILTERS) { self, _, _, _ -> val driveFilter = ItemFilter(PortableCondensationDriveItem.MAX_FILTERS) { self, _, _, _ ->
if (tile?.container?.get(0)?.item is PortableCondensationDriveItem) { if (tile?.container?.get(0)?.item is PortableCondensationDriveItem) {
tile.container[0].getOrCreateTag().put(PortableCondensationDriveItem.FILTER_PATH, self.serializeNBT()) tile.container[0].getOrCreateTag().put(PortableCondensationDriveItem.FILTER_PATH, self.serializeNBT())

View File

@ -130,8 +130,6 @@ class ItemMonitorMenu @JvmOverloads constructor(
} }
} }
override val storageSlots: List<Slot> = listOf(batterySlot)
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack { override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
if (playerInventorySlots.any { it.index == slotIndex }) { if (playerInventorySlots.any { it.index == slotIndex }) {
if (tile == null) { if (tile == null) {

View File

@ -27,8 +27,7 @@ class StorageBusMenu @JvmOverloads constructor(
busFilterState = BooleanInputWithFeedback(this) busFilterState = BooleanInputWithFeedback(this)
} }
addStorageSlot(batterySlot)
addInventorySlots() addInventorySlots()
} }
override val storageSlots: Collection<Slot> = listOf(batterySlot)
} }

View File

@ -29,6 +29,4 @@ class StorageExporterMenu @JvmOverloads constructor(
addInventorySlots() addInventorySlots()
} }
override val storageSlots: List<Slot> = listOf(batterySlot)
} }

View File

@ -29,6 +29,4 @@ class StorageImporterMenu @JvmOverloads constructor(
addInventorySlots() addInventorySlots()
} }
override val storageSlots: List<Slot> = listOf(batterySlot)
} }

View File

@ -15,6 +15,7 @@ class StoragePowerSupplierMenu @JvmOverloads constructor(
var activeNodes by mSynchronizer.int() var activeNodes by mSynchronizer.int()
init { init {
addStorageSlot(batterySlot)
addInventorySlots() addInventorySlots()
} }
@ -26,6 +27,4 @@ class StoragePowerSupplierMenu @JvmOverloads constructor(
super.broadcastChanges() super.broadcastChanges()
} }
override val storageSlots: List<Slot> = listOf(batterySlot)
} }

View File

@ -116,11 +116,7 @@ class AndroidStationMenu @JvmOverloads constructor(
init { init {
addInventorySlots() addInventorySlots()
addSlot(androidBattery) addStorageSlot(androidBattery)
}
override val storageSlots = immutableList {
accept(androidBattery)
} }
override fun stillValid(player: Player): Boolean { override fun stillValid(player: Player): Boolean {

View File

@ -22,7 +22,7 @@ class BatteryBankMenu @JvmOverloads constructor(
tile: BatteryBankBlockEntity? = null, tile: BatteryBankBlockEntity? = null,
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) { ) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
val powerLevel: LevelGaugeWidget val powerLevel: LevelGaugeWidget
override val storageSlots: List<MatterySlot> val storageSlots: List<MatterySlot>
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java) val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
init { init {
@ -34,9 +34,7 @@ class BatteryBankMenu @JvmOverloads constructor(
powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull()) powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull())
storageSlots = ImmutableList(BatteryBankBlockEntity.CAPACITY) { storageSlots = ImmutableList(BatteryBankBlockEntity.CAPACITY) {
val slot = BatterySlot(container, it) addStorageSlot(BatterySlot(container, it))
addSlot(slot)
return@ImmutableList slot
} }
addInventorySlots() addInventorySlots()

View File

@ -58,11 +58,11 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t
val energy = LevelGaugeWidget(this, tile?.energy) val energy = LevelGaugeWidget(this, tile?.energy)
var burnTime by mSynchronizer.int() var burnTime by mSynchronizer.int()
override val storageSlots = listOf( init {
addSlot(fuelSlot), addStorageSlot(fuelSlot)
addSlot(batterySlot), addStorageSlot(batterySlot)
addSlot(residueSlot), addStorageSlot(residueSlot)
) }
init { init {
addInventorySlots() addInventorySlots()

View File

@ -17,7 +17,7 @@ class CobblerMenu @JvmOverloads constructor(
inventory: Inventory, inventory: Inventory,
tile: CobblerBlockEntity? = null tile: CobblerBlockEntity? = null
) : MatteryMenu(MMenus.COBBLESTONE_GENERATOR, p_38852_, inventory, tile) { ) : MatteryMenu(MMenus.COBBLESTONE_GENERATOR, p_38852_, inventory, tile) {
override val storageSlots = (tile?.container ?: SimpleContainer(CobblerBlockEntity.CONTAINER_SIZE)).let { c -> ImmutableList(c.containerSize) { addSlot(MachineOutputSlot(c, it)) } } val storageSlots = (tile?.container ?: SimpleContainer(CobblerBlockEntity.CONTAINER_SIZE)).let { c -> ImmutableList(c.containerSize) { addStorageSlot(MachineOutputSlot(c, it)) } }
val redstone = EnumInputWithFeedback<RedstoneSetting>(this) val redstone = EnumInputWithFeedback<RedstoneSetting>(this)
val itemConfig = ItemHandlerPlayerInput(this, false, false) val itemConfig = ItemHandlerPlayerInput(this, false, false)

View File

@ -72,9 +72,6 @@ class EnergyCounterMenu @JvmOverloads constructor(
super.broadcastChanges() super.broadcastChanges()
} }
override val storageSlots: Collection<Slot> get() = emptySet()
companion object { companion object {
private val MINUS_ONE = -BigDecimal.ONE private val MINUS_ONE = -BigDecimal.ONE
} }

View File

@ -1,9 +1,7 @@
package ru.dbotthepony.mc.otm.menu.tech package ru.dbotthepony.mc.otm.menu.tech
import com.google.common.collect.ImmutableList
import net.minecraft.world.SimpleContainer import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.Slot
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
@ -49,10 +47,10 @@ class EnergyServoMenu @JvmOverloads constructor(
} }
init { init {
addSlot(dischargeSlot) // charge then discharge for charging to take priority over discharging
addSlot(chargeSlot) addStorageSlot(chargeSlot)
addStorageSlot(dischargeSlot)
addInventorySlots() addInventorySlots()
} }
override val storageSlots: Collection<Slot> = ImmutableList.of(dischargeSlot, chargeSlot)
} }

View File

@ -1,6 +1,5 @@
package ru.dbotthepony.mc.otm.menu.tech package ru.dbotthepony.mc.otm.menu.tech
import com.google.common.collect.ImmutableList
import net.minecraft.server.level.ServerPlayer import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.SimpleContainer import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
@ -21,16 +20,14 @@ class PlatePressMenu @JvmOverloads constructor(
val inputSlot = MatterySlot(tile?.inputContainer ?: SimpleContainer(1), 0) val inputSlot = MatterySlot(tile?.inputContainer ?: SimpleContainer(1), 0)
val outputSlot = MachineOutputSlot(tile?.outputContainer ?: SimpleContainer(1), 0) { tile?.popExperience(ply as ServerPlayer) } val outputSlot = MachineOutputSlot(tile?.outputContainer ?: SimpleContainer(1), 0) { tile?.popExperience(ply as ServerPlayer) }
override val storageSlots: List<MatterySlot> = ImmutableList.of(inputSlot, outputSlot)
val progressGauge = if (tile != null) ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) else ProgressGaugeWidget(this) val progressGauge = if (tile != null) ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) else ProgressGaugeWidget(this)
val itemConfig = ItemHandlerPlayerInput(this, allowPush = true) val itemConfig = ItemHandlerPlayerInput(this, allowPush = true)
val energyConfig = EnergyPlayerInput(this, allowPull = true) val energyConfig = EnergyPlayerInput(this, allowPull = true)
init { init {
addSlot(inputSlot) addStorageSlot(inputSlot)
addSlot(outputSlot) addStorageSlot(outputSlot)
addInventorySlots() addInventorySlots()
if (tile != null) { if (tile != null) {

View File

@ -7,8 +7,4 @@ abstract class AbstractWidget(val menu: MatteryMenu,) {
val slotID: Int = menu.addWidget(this) val slotID: Int = menu.addWidget(this)
abstract fun updateServer() abstract fun updateServer()
protected fun addDataSlots(slots: ContainerData) {
menu.addDataSlots(slots)
}
} }