From 4673dd129d3774b5d4934e848083ecad2de27617 Mon Sep 17 00:00:00 2001 From: WMF Date: Mon, 2 Dec 2024 09:09:36 +0100 Subject: [PATCH] the notifications are no more --- assets/mod.hjson | 2 +- src/floodcompat/FloodCompat.kt | 47 ++++++++++++++-------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/assets/mod.hjson b/assets/mod.hjson index 91ee95a..2bd58ae 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.1" +version: "1.2.2" 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 60d3c87..9c4f3e3 100644 --- a/src/floodcompat/FloodCompat.kt +++ b/src/floodcompat/FloodCompat.kt @@ -24,7 +24,7 @@ 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 = ObjectSet() + private val allTiles = ObjectMap>() /** Used to prevent flood from applying twice */ private var applied = false @@ -50,58 +50,49 @@ 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 tiles = Seq() + val start = Time.millis() Geometry.circle(tile.x.toInt(), tile.y.toInt(), rad) { cx: Int, cy: Int -> val t = world.tile(cx, cy) - if (t != null && !allTiles.contains(t)) { - tiles.add(t) + 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 } } - allTiles.addAll(tiles) - - val startTime = Time.millis() + } - Timer.schedule({ - val sizeMultiplier = 1 - (Time.millis() - startTime) / 1000f / time - tiles.each { t: Tile -> + Timer.schedule({ + val it = allTiles.iterator() + while(it.hasNext()){ + val entry = it.next() + if(Time.millis() >= entry.value[3]){ + it.remove() + }else{ + val sizeMultiplier = 1 - (Time.millis() - entry.value[0]) / 1000f / entry.value[1] Timer.schedule({ Fx.lightBlock.at( - t.getX(), - t.getY(), + entry.key.getX(), + entry.key.getY(), Mathf.random(0.01f, 1.5f * sizeMultiplier), - color + Team.get(entry.value[2].toInt()).color ) }, Mathf.random(1f)) } - }, 0f, 1f, time) - - Timer.schedule({ - allTiles.removeAll(tiles) - tiles.clear() - }, time.toFloat()) - } + } + }, 0f, 1f) } /** 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.1") - Timer.schedule({ notif() }, 3f) + Call.serverPacketReliable("flood", "1.2") allTiles.clear() } - private fun notif(){ - if (net.client() && !applied) ui.chatfrag.addMessage("[scarlet]FloodCompat flood check failed...\n[accent]Playing on flood? Try rejoining!\nHave a nice day!") - } - /** Applies flood changes */ private fun enable() { if (applied) throw AssertionError("Tried to enable flood even though it was already enabled!") applied = true - ui.chatfrag.addMessage("[lime]Server check succeeded!\n[accent]Applying flood changes.") Log.info("Enabling FloodCompat") Time.mark()