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,24 +39,8 @@ 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
|
||||||
var scroll = 0
|
|
||||||
set(value) {
|
|
||||||
if (field == value || isIncomplete || value < 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val matteryPlayer = player.matteryPlayer ?: return
|
private fun getRow(index: Int, matteryPlayer: MatteryPlayerCapability) = rows.computeIfAbsent(index, Int2ObjectFunction {
|
||||||
|
|
||||||
if (!matteryPlayer.hasExoSuit || matteryPlayer.exoSuitContainer.containerSize <= (value - 1) * 9) {
|
|
||||||
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 row = ArrayList<Slot>(9)
|
||||||
val offset = (it - 3) * 9
|
val offset = (it - 3) * 9
|
||||||
|
|
||||||
@ -70,6 +55,40 @@ private class MenuConfiguration(
|
|||||||
row
|
row
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var scroll = 0
|
||||||
|
set(value) {
|
||||||
|
if (field == value || isIncomplete || value < 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val matteryPlayer = player.matteryPlayer ?: return
|
||||||
|
|
||||||
|
if (!matteryPlayer.hasExoSuit || matteryPlayer.exoSuitContainer.containerSize <= (value - 1) * 9) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (rowIndex in 0 .. 2) {
|
||||||
|
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 }
|
||||||
|
|
||||||
|
if (indexOf != -1) {
|
||||||
|
if (slot.item.isEmpty) {
|
||||||
|
matteryPlayer.exoSuitMenu.setRemoteSlotNoCopy(indexOf, ItemStack(Items.BARRIER))
|
||||||
|
} else {
|
||||||
|
matteryPlayer.exoSuitMenu.setRemoteSlotNoCopy(indexOf, ItemStack.EMPTY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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