From 967057cf366c72be5a4900758a00fa8ba0d4619a Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 24 Oct 2022 18:22:54 +0700 Subject: [PATCH] Invalidate synchronizers exosuit menu when scrolling in non otm guis Fixes #165 --- .../mc/otm/compat/ExtendedInventoryHandler.kt | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/ExtendedInventoryHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/ExtendedInventoryHandler.kt index d0f00313e..d8dc7bc4f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/ExtendedInventoryHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/ExtendedInventoryHandler.kt @@ -14,6 +14,7 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items import net.minecraftforge.network.NetworkEvent import org.apache.logging.log4j.LogManager +import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatterySlot @@ -38,6 +39,22 @@ private class MenuConfiguration( private val slotPositions = Int2ObjectArrayMap>() private val rows = Int2ObjectAVLTreeMap>() val isIncomplete: Boolean + + private fun getRow(index: Int, matteryPlayer: MatteryPlayerCapability) = rows.computeIfAbsent(index, Int2ObjectFunction { + val row = ArrayList(9) + val offset = (it - 3) * 9 + + for (i in 0 .. 8) { + if (matteryPlayer.exoSuitContainer.containerSize > i + offset) { + row.add(MatterySlot(matteryPlayer.exoSuitContainer, i + offset)) + } else { + row.add(FakeSlot()) + } + } + + row + }) + var scroll = 0 set(value) { if (field == value || isIncomplete || value < 0) { @@ -50,26 +67,28 @@ private class MenuConfiguration( return } - field = value - - val indices = indices.iterator() - for (rowIndex in 0 .. 2) { - val row = rows.computeIfAbsent(rowIndex + value, Int2ObjectFunction { - val row = ArrayList(9) - val offset = (it - 3) * 9 + for (slot in getRow(rowIndex + field, matteryPlayer)) { + if (slot.container === matteryPlayer.exoSuitContainer) { + @Suppress("name_shadowing") + val indexOf = matteryPlayer.exoSuitMenu.slots.indexOfFirst { it.slotIndex == slot.slotIndex } - for (i in 0 .. 8) { - if (matteryPlayer.exoSuitContainer.containerSize > i + offset) { - row.add(MatterySlot(matteryPlayer.exoSuitContainer, i + offset)) - } else { - row.add(FakeSlot()) + if (indexOf != -1) { + if (slot.item.isEmpty) { + matteryPlayer.exoSuitMenu.setRemoteSlotNoCopy(indexOf, ItemStack(Items.BARRIER)) + } else { + matteryPlayer.exoSuitMenu.setRemoteSlotNoCopy(indexOf, ItemStack.EMPTY) + } } } + } + } - row - }) + field = value + val indices = this.indices.iterator() + for (rowIndex in 0 .. 2) { + val row = getRow(rowIndex + field, matteryPlayer) val positions = slotPositions[rowIndex] ?: throw IndexOutOfBoundsException("$rowIndex") for (column in 0 .. 8) {