Move SortInput to upper level

This commit is contained in:
DBotThePony 2025-03-15 22:26:47 +07:00
parent cf32fd9d2a
commit d5a9632c97
Signed by: DBot
GPG Key ID: DCC23B5715498507
8 changed files with 32 additions and 23 deletions

View File

@ -35,8 +35,8 @@ import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.math.RelativeSide
import ru.dbotthepony.mc.otm.core.util.ItemStackSorter
import ru.dbotthepony.mc.otm.core.util.getLevelFromXp
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.UpgradeSlots
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
@ -449,7 +449,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
return result
}
fun sortingButtons(input: MatteryMenu.SortInput, unfoldableSettings: Boolean = true) {
fun sortingButtons(input: SortInput, unfoldableSettings: Boolean = true) {
object : ButtonPanel<S>(screen, this@DeviceControls, width = 18f, height = 18f) {
var buttons: List<EditablePanel<*>>? = null

View File

@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.MenuType
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.SortInput
abstract class AbstractVanillaChestMenu(
type: MenuType<*>,
@ -17,7 +18,7 @@ abstract class AbstractVanillaChestMenu(
abstract val columns: Int
abstract val containerSlots: List<MatteryMenuSlot>
val sort = SortInput(container, playerSortSettings)
val sort = SortInput(this, container, playerSortSettings)
override fun stillValid(player: Player): Boolean {
return container.stillValid(player)

View File

@ -135,7 +135,7 @@ class ExopackInventoryMenu(val capability: MatteryPlayer) : MatteryMenu(null, CO
}
}
sortEnderChest = SortInput(player.enderChestInventory, playerEnderSortSettings)
sortEnderChest = SortInput(this, player.enderChestInventory, playerEnderSortSettings)
} else {
enderChestSlots = listOf()
sortEnderChest = null

View File

@ -3,8 +3,6 @@ package ru.dbotthepony.mc.otm.menu
import com.google.common.collect.ImmutableList
import com.mojang.datafixers.util.Pair
import it.unimi.dsi.fastutil.bytes.ByteArrayList
import it.unimi.dsi.fastutil.ints.IntArrayList
import it.unimi.dsi.fastutil.ints.IntCollection
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceArrayList
@ -15,7 +13,6 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerPlayer
import net.minecraft.util.RandomSource
import net.minecraft.world.Container
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu
@ -41,8 +38,6 @@ import ru.dbotthepony.mc.otm.compat.curios.curiosSlots
import ru.dbotthepony.mc.otm.compat.curios.isCurioSlot
import ru.dbotthepony.mc.otm.container.IEnhancedContainer
import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot
import ru.dbotthepony.mc.otm.container.computeSortedIndices
import ru.dbotthepony.mc.otm.container.sortWithIndices
import ru.dbotthepony.mc.otm.container.util.containerSlotOrNull
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.core.collect.ConditionalSet
@ -165,16 +160,6 @@ abstract class MatteryMenu(
}
}
inner class SortInput(val container: Container, val settings: IItemStackSortingSettings) {
val input = PlayerInput(MatteryStreamCodec.Collection<RegistryFriendlyByteBuf, Int, IntCollection>(StreamCodecs.VAR_INT, ::IntArrayList)) {
container.sortWithIndices(it)
}
fun clientInput() {
input.accept(container.computeSortedIndices(settings.actualComparator))
}
}
fun oneWayInput(allowSpectators: Boolean = false, handler: () -> Unit): PlayerInput<Nothing?> {
return PlayerInput(StreamCodecs.NOTHING, allowSpectators) {
handler.invoke()
@ -316,7 +301,7 @@ abstract class MatteryMenu(
_exopackChargeSlots.add(BatteryMenuSlot(mattery.exopackChargeSlots, i, direction = FlowDirection.INPUT).also { mapQuickMoveToExternal(it); mapQuickMoveToInventory(it); addSlot(it) })
}
sortInventoryInput = SortInput(mattery.inventoryAndExopackNoHotbar, playerSortSettings)
sortInventoryInput = SortInput(this, mattery.inventoryAndExopackNoHotbar, playerSortSettings)
}
private var broadcastOnce = false

View File

@ -0,0 +1,20 @@
package ru.dbotthepony.mc.otm.menu
import it.unimi.dsi.fastutil.ints.IntArrayList
import it.unimi.dsi.fastutil.ints.IntCollection
import net.minecraft.network.RegistryFriendlyByteBuf
import net.minecraft.world.Container
import ru.dbotthepony.mc.otm.container.computeSortedIndices
import ru.dbotthepony.mc.otm.container.sortWithIndices
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
import ru.dbotthepony.mc.otm.network.StreamCodecs
class SortInput(menu: MatteryMenu, val container: Container, val settings: IItemStackSortingSettings) {
val input = menu.PlayerInput(MatteryStreamCodec.Collection<RegistryFriendlyByteBuf, Int, IntCollection>(StreamCodecs.VAR_INT, ::IntArrayList)) {
container.sortWithIndices(it)
}
fun clientInput() {
input.accept(container.computeSortedIndices(settings.actualComparator))
}
}

View File

@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Player
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
import ru.dbotthepony.mc.otm.menu.makeSlots
import ru.dbotthepony.mc.otm.registry.game.MMenus
@ -18,7 +19,7 @@ class CargoCrateMenu(
val storageSlots = makeSlots(actualContainer, ::UserFilteredMenuSlot)
private val trackedPlayerOpen = !inventory.player.isSpectator
val sort = SortInput(actualContainer, playerSortSettings)
val sort = SortInput(this, actualContainer, playerSortSettings)
init {
if (trackedPlayerOpen) {

View File

@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
import ru.dbotthepony.mc.otm.entity.MinecartCargoCrate
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.makeSlots
import ru.dbotthepony.mc.otm.registry.game.MMenus
@ -21,7 +22,7 @@ class MinecartCargoCrateMenu(
private val trackedPlayerOpen = !inventory.player.isSpectator
val sort = SortInput(actualContainer, playerSortSettings)
val sort = SortInput(this, actualContainer, playerSortSettings)
init {
if (trackedPlayerOpen) {

View File

@ -8,6 +8,7 @@ import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.tech.ItemHatchBlockEntity
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.makeSlots
@ -28,7 +29,7 @@ class ItemHatchMenu(
}
}
val sort = SortInput(actualContainer, playerSortSettings)
val sort = SortInput(this, actualContainer, playerSortSettings)
val redstone = EnumInputWithFeedback<RedstoneSetting>(this)
init {