From d34cdde58e461707b203205fe3e8bb26bbc9b740 Mon Sep 17 00:00:00 2001 From: WMF Date: Fri, 6 Dec 2024 07:49:58 +0100 Subject: [PATCH] rolled back anticreep drawing --- assets/mod.hjson | 2 +- src/floodcompat/FloodCompat.kt | 58 ++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/assets/mod.hjson b/assets/mod.hjson index 2bd58ae..053f3ea 100644 --- a/assets/mod.hjson +++ b/assets/mod.hjson @@ -3,7 +3,7 @@ name: "floodcompat" author: "io community" main: "floodcompat.FloodCompat" description: "Reduces desyncs & applies flood changes on join." -version: "1.2.2" +version: "1.2.3" minGameVersion: 146 java: true hidden: true \ No newline at end of file diff --git a/src/floodcompat/FloodCompat.kt b/src/floodcompat/FloodCompat.kt index 9c4f3e3..b36eb76 100644 --- a/src/floodcompat/FloodCompat.kt +++ b/src/floodcompat/FloodCompat.kt @@ -24,7 +24,8 @@ class FloodCompat : Mod() { /** Vanilla values of changed vars for restoration later */ private val defaults = mutableListOf() /** All the tiles that currently have effects drawn on top */ - private val allTiles = ObjectMap>() + private val allTiles = ObjectSet() + private val allTasks = Seq() /** Used to prevent flood from applying twice */ private var applied = false @@ -50,42 +51,59 @@ class FloodCompat : Mod() { if (pos <= 0 || rad <= 0 || time <= 0 || team <= 0) return@addPacketHandler val tile = world.tile(pos) ?: return@addPacketHandler + val color = Team.get(team).color - val start = Time.millis() + val tiles = Seq() Geometry.circle(tile.x.toInt(), tile.y.toInt(), rad) { cx: Int, cy: Int -> val t = world.tile(cx, cy) - if (t != null && !allTiles.containsKey(t)) { - allTiles.put(t, listOf(start, time.toLong(), team.toLong(), start + (time * 1000L))) // start time, overall length, team, end time + if (t != null && !allTiles.contains(t)) { + tiles.add(t) } } + allTiles.addAll(tiles) + + val startTime = Time.millis() + + allTasks.addAll( + Timer.schedule({ + val sizeMultiplier = 1 - (Time.millis() - startTime) / 1000f / time + tiles.each { t: Tile -> + Timer.schedule({ + Fx.lightBlock.at( + t.getX(), + t.getY(), + Mathf.random(0.01f, 1.5f * sizeMultiplier), + color + ) + }, Mathf.random(1f)) + } + }, 0f, 1f, time), + + Timer.schedule({ + allTiles.removeAll(tiles) + tiles.clear() + }, time.toFloat()) + ) } Timer.schedule({ - val it = allTiles.iterator() - while(it.hasNext()){ - val entry = it.next() - if(Time.millis() >= entry.value[3]){ + val it = allTasks.iterator() + while (it.hasNext()) { + val task = it.next() + if (task == null || !task.isScheduled) it.remove() - }else{ - val sizeMultiplier = 1 - (Time.millis() - entry.value[0]) / 1000f / entry.value[1] - Timer.schedule({ - Fx.lightBlock.at( - entry.key.getX(), - entry.key.getY(), - Mathf.random(0.01f, 1.5f * sizeMultiplier), - Team.get(entry.value[2].toInt()).color - ) - }, Mathf.random(1f)) - } } - }, 0f, 1f) + }, 0f, 5f) } /** This is a function so that foo's can call it when downloading the mod */ private fun onWorldLoad() { Log.debug("Send flood") Call.serverPacketReliable("flood", "1.2") + allTiles.clear() + allTasks.each{ it.cancel() } + allTasks.clear() } /** Applies flood changes */