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.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<List<SlotPos>>()
|
||||
private val rows = Int2ObjectAVLTreeMap<List<Slot>>()
|
||||
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
|
||||
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<Slot>(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) {
|
||||
|
Loading…
Reference in New Issue
Block a user