Invalidate synchronizers exosuit menu when scrolling in non otm guis
Fixes #165
This commit is contained in:
parent
3e2b524519
commit
967057cf36
@ -14,6 +14,7 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.minecraft.world.item.Items
|
import net.minecraft.world.item.Items
|
||||||
import net.minecraftforge.network.NetworkEvent
|
import net.minecraftforge.network.NetworkEvent
|
||||||
import org.apache.logging.log4j.LogManager
|
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.capability.matteryPlayer
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
||||||
@ -38,6 +39,22 @@ private class MenuConfiguration(
|
|||||||
private val slotPositions = Int2ObjectArrayMap<List<SlotPos>>()
|
private val slotPositions = Int2ObjectArrayMap<List<SlotPos>>()
|
||||||
private val rows = Int2ObjectAVLTreeMap<List<Slot>>()
|
private val rows = Int2ObjectAVLTreeMap<List<Slot>>()
|
||||||
val isIncomplete: Boolean
|
val isIncomplete: Boolean
|
||||||
|
|
||||||
|
private fun getRow(index: Int, matteryPlayer: MatteryPlayerCapability) = rows.computeIfAbsent(index, Int2ObjectFunction {
|
||||||
|
val row = ArrayList<Slot>(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
|
var scroll = 0
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value || isIncomplete || value < 0) {
|
if (field == value || isIncomplete || value < 0) {
|
||||||
@ -50,26 +67,28 @@ private class MenuConfiguration(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
field = value
|
|
||||||
|
|
||||||
val indices = indices.iterator()
|
|
||||||
|
|
||||||
for (rowIndex in 0 .. 2) {
|
for (rowIndex in 0 .. 2) {
|
||||||
val row = rows.computeIfAbsent(rowIndex + value, Int2ObjectFunction {
|
for (slot in getRow(rowIndex + field, matteryPlayer)) {
|
||||||
val row = ArrayList<Slot>(9)
|
if (slot.container === matteryPlayer.exoSuitContainer) {
|
||||||
val offset = (it - 3) * 9
|
@Suppress("name_shadowing")
|
||||||
|
val indexOf = matteryPlayer.exoSuitMenu.slots.indexOfFirst { it.slotIndex == slot.slotIndex }
|
||||||
|
|
||||||
for (i in 0 .. 8) {
|
if (indexOf != -1) {
|
||||||
if (matteryPlayer.exoSuitContainer.containerSize > i + offset) {
|
if (slot.item.isEmpty) {
|
||||||
row.add(MatterySlot(matteryPlayer.exoSuitContainer, i + offset))
|
matteryPlayer.exoSuitMenu.setRemoteSlotNoCopy(indexOf, ItemStack(Items.BARRIER))
|
||||||
} else {
|
} else {
|
||||||
row.add(FakeSlot())
|
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")
|
val positions = slotPositions[rowIndex] ?: throw IndexOutOfBoundsException("$rowIndex")
|
||||||
|
|
||||||
for (column in 0 .. 8) {
|
for (column in 0 .. 8) {
|
||||||
|
Loading…
Reference in New Issue
Block a user