aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon <brandon.wamboldt@gmail.com>2023-10-01 06:10:01 -0300
committerGitHub <noreply@github.com>2023-10-01 11:10:01 +0200
commit9202db955f10e38cf037d209c133468aa6d3b2e7 (patch)
tree59ca22190624fa1e0c4b4b082162ed3d7450f3e4
parent06450f7f801428be2ca92ed124717ea5a00c7241 (diff)
downloadskyhanni-9202db955f10e38cf037d209c133468aa6d3b2e7.tar.gz
skyhanni-9202db955f10e38cf037d209c133468aa6d3b2e7.tar.bz2
skyhanni-9202db955f10e38cf037d209c133468aa6d3b2e7.zip
Add spawn timer support for Arachne quickspawns (#525)
Add spawn timer support for Arachne quickspawns #525
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt60
1 files changed, 53 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt
index b2d76824d..a3c7d58ae 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mobs/SpawnTimers.kt
@@ -3,14 +3,17 @@ package at.hannibal2.skyhanni.features.mobs
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.PacketEvent
+import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
-import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
-import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
+import net.minecraft.network.play.server.S2APacketParticles
+import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.client.event.RenderWorldLastEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
@@ -21,6 +24,19 @@ class SpawnTimers {
private var arachneSpawnTime = SimpleTimeMark.farPast()
private val arachneFragmentMessage = "^☄ [a-z0-9_]{2,22} placed an arachne's calling! something is awakening! \\(4/4\\)\$".toRegex()
private val arachneCrystalMessage = "^☄ [a-z0-9_]{2,22} placed an arachne crystal! something is awakening!$".toRegex()
+ private var saveNextTickParticles = false
+ private var particleCounter = 0
+ private var tickTime: Long = 0
+ private var searchTime: Long = 0
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ searchTime = 0
+ tickTime = 0
+ particleCounter = 0
+ saveNextTickParticles = false
+ arachneSpawnTime = SimpleTimeMark.farPast()
+ }
@SubscribeEvent
fun onRenderWorld(event: RenderWorldLastEvent) {
@@ -38,10 +54,40 @@ class SpawnTimers {
val message = event.message.removeColor().lowercase()
if (arachneFragmentMessage.matches(message) || arachneCrystalMessage.matches(message)) {
- arachneSpawnTime = if (arachneCrystalMessage.matches(message))
- SimpleTimeMark.now() + 24.seconds
- else
- SimpleTimeMark.now() + 19.seconds
+ if (arachneCrystalMessage.matches(message)) {
+ saveNextTickParticles = true
+ searchTime = System.currentTimeMillis()
+ particleCounter = 0
+ tickTime = 0L
+ } else arachneSpawnTime = SimpleTimeMark.now() + 19.seconds
+ }
+ }
+
+ // All this to detect "quickspawn" vs regular arachne spawn
+ @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
+ fun onChatPacket(event: PacketEvent.ReceiveEvent) {
+ if (!saveNextTickParticles) return
+ if (System.currentTimeMillis() <= searchTime + 3000) return
+
+ if (particleCounter == 0 && tickTime == 0L) tickTime = System.currentTimeMillis()
+
+ if (System.currentTimeMillis() > tickTime + 60) {
+ arachneSpawnTime = if (particleCounter <= 20) {
+ SimpleTimeMark.now() + 21.seconds
+ } else {
+ SimpleTimeMark.now() + 37.seconds
+ }
+ saveNextTickParticles = false
+ return
+ }
+
+ val packet = event.packet
+ if (packet is S2APacketParticles) {
+ val location = packet.toLorenzVec().round(2)
+ if (arachneAltarLocation.distance(location) > 30) return
+ if (packet.particleType == EnumParticleTypes.REDSTONE && packet.particleSpeed == 1.0f) {
+ particleCounter += 1
+ }
}
}