Skip to content

Commit 91135ad

Browse files
chore: change linkedlist/java arraydeque to kotlin arraydeque
1 parent 5a01a54 commit 91135ad

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/main/kotlin/gg/skytils/skytilsmod/core/GuiManager.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
4646
import java.io.File
4747
import java.io.Reader
4848
import java.io.Writer
49-
import java.util.*
5049

5150
object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
5251
val elements = hashMapOf<Int, GuiElement>()
@@ -60,7 +59,7 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
6059
var subtitleDisplayTicks = 0
6160

6261
private val gui = Window(ElementaVersion.V2)
63-
private val toastQueue: Queue<Toast> = LinkedList()
62+
private val toastQueue = ArrayDeque<Toast>()
6463
private val maxToasts: Int
6564
get() = ((UResolution.scaledHeight * 0.5) / 32).toInt()
6665
private val takenSlots = sortedSetOf<Int>()
@@ -86,7 +85,7 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
8685
takenSlots.add(index)
8786
toast.animateBeforeHide {
8887
takenSlots.remove(index)
89-
toastQueue.poll()?.let { newToast ->
88+
toastQueue.removeFirstOrNull()?.let { newToast ->
9089
addToast(newToast)
9190
}
9291
}
@@ -96,25 +95,21 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
9695
}
9796
}
9897

99-
fun getByID(ID: Int): GuiElement? {
100-
return elements[ID]
98+
fun getByID(id: Int): GuiElement? {
99+
return elements[id]
101100
}
102101

103102
fun getByName(name: String?): GuiElement? {
104103
return names[name]
105104
}
106105

107-
fun searchElements(query: String): List<GuiElement> {
108-
val results: MutableList<GuiElement> = ArrayList()
109-
for ((key, value) in names) {
110-
if (key.contains(query)) results.add(value)
111-
}
112-
return results
106+
fun searchElements(query: String): Collection<GuiElement> {
107+
return names.filter { it.key.contains(query) }.values
113108
}
114109

115110
@SubscribeEvent
116111
fun renderPlayerInfo(event: RenderGameOverlayEvent.Post) {
117-
if (Skytils.usingLabymod && Minecraft.getMinecraft().ingameGUI !is GuiIngameForge) return
112+
if (Skytils.usingLabymod && mc.ingameGUI !is GuiIngameForge) return
118113
if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR) return
119114
GlState.pushState()
120115
MinecraftForge.EVENT_BUS.post(RenderHUDEvent(event))

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/IcePathSolver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
3939
import java.awt.Color
4040
import java.awt.Point
4141
import java.util.*
42+
import kotlin.collections.ArrayDeque
4243
import kotlin.math.abs
4344

4445
object IcePathSolver {
@@ -202,7 +203,7 @@ object IcePathSolver {
202203
queue.addLast(Point(startX, startY))
203204
iceCaveColors[startY][startX] = startPoint
204205
while (queue.size != 0) {
205-
val currPos = queue.pollFirst()
206+
val currPos = queue.removeFirst()
206207
// traverse adjacent nodes while sliding on the ice
207208
for (dir in EnumFacing.HORIZONTALS) {
208209
val nextPos = move(iceCave, iceCaveColors, currPos, dir)
@@ -220,7 +221,7 @@ object IcePathSolver {
220221
steps.add(currPos)
221222
while (tmp !== startPoint) {
222223
count++
223-
tmp = iceCaveColors[tmp!!.y][tmp.x]
224+
tmp = iceCaveColors[tmp.y][tmp.x]!!
224225
steps.add(tmp)
225226
}
226227
//System.out.println("Silverfish solved in " + count + " moves.");

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/AlignmentTaskSolver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
4141
import java.awt.Color
4242
import java.awt.Point
4343
import java.util.*
44+
import kotlin.collections.ArrayDeque
4445
import kotlin.random.Random
4546

4647
object AlignmentTaskSolver {
@@ -286,8 +287,8 @@ object AlignmentTaskSolver {
286287
) { arrayOfNulls<Point>(grid[0].size) }
287288
queue.addLast(start)
288289
gridCopy[start.y][start.x] = start
289-
while (queue.size != 0) {
290-
val currPos = queue.pollFirst()!!
290+
while (queue.isNotEmpty()) {
291+
val currPos = queue.removeFirst()
291292
// traverse adjacent nodes while sliding on the ice
292293
for (dir in directions) {
293294
val nextPos = move(grid, gridCopy, currPos, dir)

src/main/kotlin/gg/skytils/skytilsmod/utils/GlState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.lwjgl.opengl.GL11
2424
import org.lwjgl.opengl.GL14
2525
import org.lwjgl.opengl.GLContext
2626
import java.nio.FloatBuffer
27-
import java.util.*
2827

2928
class GlState {
3029

0 commit comments

Comments
 (0)