From 3c19da86b963d2212450d9b3c269266273660c4f Mon Sep 17 00:00:00 2001 From: whatsy Date: Wed, 25 Nov 2026 12:21:22 -0500 Subject: [PATCH] chore: code cleanup --- .../mod/common/api/storage/pc/PCStore.kt | 9 +++------ .../mod/common/client/gui/pc/BoxStorageSlot.kt | 3 +-- .../cobblemon/mod/common/client/gui/pc/PCGUI.kt | 3 ++- .../mod/common/client/gui/pc/StorageWidget.kt | 17 +++++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/storage/pc/PCStore.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/storage/pc/PCStore.kt index f4eec03bd2..ef1c06fbd6 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/storage/pc/PCStore.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/storage/pc/PCStore.kt @@ -286,13 +286,10 @@ open class PCStore( } if (pokemonMoves.any { (_, target, _) -> get(target) != null && target !in sourcePositions }) return false - pokemonMoves.forEach { (source, _, _) -> setAtPosition(source, null) } - pokemonMoves.forEach { (_, target, pokemon) -> setAtPosition(target, pokemon) } - - pokemonMoves.forEach { (_, _, pokemon) -> + pokemonMoves.forEach { (source, target, pokemon) -> + setAtPosition(source, null) + setAtPosition(target, pokemon) sendPacketToObservers(RemoveClientPokemonPacket(this, pokemon.uuid)) - } - pokemonMoves.forEach { (_, target, pokemon) -> sendPacketToObservers(SetPCPokemonPacket(uuid, target) { pokemon }) } pcChangeObservable.emit(Unit) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/BoxStorageSlot.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/BoxStorageSlot.kt index 6812eef1dd..b0b969cdb7 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/BoxStorageSlot.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/BoxStorageSlot.kt @@ -29,8 +29,7 @@ class BoxStorageSlot( val grabbedSlot = parent.grabbedSlot return if (grabbedSlot == null) { - val pokemon = getPokemon() - pokemon == null || !parent.isInMultiSelection(pokemon, position) + getPokemon().let { it == null || !parent.isInMultiSelection(it, position) } } else { grabbedSlot.getPokemon() != getPokemon() } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/PCGUI.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/PCGUI.kt index 336451c106..7708f2ecf4 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/PCGUI.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/PCGUI.kt @@ -51,6 +51,7 @@ import net.minecraft.sounds.SoundEvent import kotlin.isInitialized import net.minecraft.resources.ResourceLocation import net.minecraft.util.FastColor +import org.lwjgl.glfw.GLFW class PCGUI( val pc: ClientPC, @@ -870,7 +871,7 @@ class PCGUI( override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean { val handled = super.mouseReleased(mouseX, mouseY, button) - if (button == 0) { + if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (selectionDragActive) { dragEndX = mouseX.toInt() dragEndY = mouseY.toInt() diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/StorageWidget.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/StorageWidget.kt index 0c1c2ca96e..92ecf7e5fd 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/StorageWidget.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/pc/StorageWidget.kt @@ -291,9 +291,10 @@ class StorageWidget( val moves = mutableListOf() val selectedSources = mutableSetOf() - for (row in 0 until height) { - for (column in 0 until width) { - val pokemon = selection.getPokemon(column, row) ?: continue + + repeat(height) { row -> + repeat(width) { column -> + val pokemon = selection.getPokemon(column, row) ?: return@repeat val source = PCPosition(selection.sourceBox, (selection.sourceRow + row) * 6 + selection.sourceColumn + column) val target = PCPosition(destination.box, (destinationRow + row) * 6 + destinationColumn + column) selectedSources.add(source) @@ -303,12 +304,12 @@ class StorageWidget( if (moves.isEmpty()) return false - for (row in 0 until height) { - for (column in 0 until width) { - if (selection.getPokemon(column, row) == null) continue + repeat(height) { row -> + repeat(width) { column -> + if (selection.getPokemon(column, row) == null) return@repeat val target = PCPosition(destination.box, (destinationRow + row) * 6 + destinationColumn + column) - val displacedPokemon = pc.get(target) ?: continue - if (target in selectedSources) continue + val displacedPokemon = pc.get(target) ?: return@repeat + if (target in selectedSources) return@repeat val displacedSource = PCPosition( selection.sourceBox,