diff options
author | inglettronald <71849533+inglettronald@users.noreply.github.com> | 2023-03-21 18:08:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 18:08:57 -0500 |
commit | 2cb6f4cffee0ab505b35938cf71518e4640a229a (patch) | |
tree | 02224acacc7e7823079a8e2cc24377eafe33700c /src/main/kotlin/dulkirmod/features/DragonTimer.kt | |
parent | 05c6b155f1de3a96ef081627ff7805238742162f (diff) | |
parent | 3968c49ccfb1fb3b0c6a8274f4d45ed0ba50ec48 (diff) | |
download | DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.tar.gz DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.tar.bz2 DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.zip |
Merge pull request #11 from IlmarsXd/master
refactor modules (class -> object), add memory leak fix
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/DragonTimer.kt')
-rw-r--r-- | src/main/kotlin/dulkirmod/features/DragonTimer.kt | 235 |
1 files changed, 114 insertions, 121 deletions
diff --git a/src/main/kotlin/dulkirmod/features/DragonTimer.kt b/src/main/kotlin/dulkirmod/features/DragonTimer.kt index 0716cef..df1f12f 100644 --- a/src/main/kotlin/dulkirmod/features/DragonTimer.kt +++ b/src/main/kotlin/dulkirmod/features/DragonTimer.kt @@ -12,125 +12,118 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color import kotlin.math.max -class DragonTimer { - data class Dragon (val color: String, val pos: Vec3, var spawnTime: Long) - - companion object { - var dragons = arrayOf( - Dragon("orange", Vec3(84.0, 18.0, 56.0), 0), - Dragon("red", Vec3(27.0, 18.0, 56.0), 0), - Dragon("green", Vec3(26.0, 18.0, 95.0), 0), - Dragon("purple", Vec3(57.0, 18.0, 125.0), 0), - Dragon("blue", Vec3(84.0, 18.0, 95.0), 0) - ) - } - - /** - * Called from within the MixinWorld Class - */ - fun handleNewParticle(particleID: Int, xCoord: Double, yCoord: Double, zCoord: Double) { - if (particleID != 26) return - if (!ScoreBoardUtils.isInM7) return - if (!Config.dragonTimer) return - //TextUtils.info("§6particle id ${particleID} 175 = $p_175720_2_") - - val particleVec = Vec3(xCoord, yCoord, zCoord) - for (d in dragons) { - if (inRangeOf(d.color, particleVec)) { - if (System.currentTimeMillis() - d.spawnTime > 10000) { - d.spawnTime = System.currentTimeMillis() - } - } - } - } - - @SubscribeEvent - fun onRenderWorld(event: RenderWorldLastEvent) { - val curTime: Long = System.currentTimeMillis() - // for some reason this really doesn't like the syntax for (d in dragons) - for (i in 0..4) { - // d.spawnTime + 5000 is when dragon actually spawn - val d = dragons[i] - if (d.spawnTime + 5000 > curTime) { - if (isDead(d.color)) - return - val timeUntilSpawn: Float = ((d.spawnTime + 5000 - curTime).toFloat() / 1000f) - val color = when { - timeUntilSpawn <= 1 -> "§c" - timeUntilSpawn <= 3 -> "§e" - else -> "§a" - } - val playerVec = mc.thePlayer.positionVector - val scale = max(1f, playerVec.distanceTo(d.pos).toFloat()/5f) - WorldRenderUtils.renderString(d.pos, "${color}${String.format("%.2f", timeUntilSpawn)}", - false, scale, true) - } - } - } - - /** - * true = dead - */ - private fun isDead(color:String): Boolean { - val world: World = mc.theWorld - val pos = when (color) { - "orange" -> BlockPos(90, 21, 56) - "red" -> BlockPos(20,22,59) - "green" -> BlockPos(22,21,94) - "purple" -> BlockPos(56,20,130) - "blue" -> BlockPos(89,21,94) - else -> BlockPos(0,0,0) - } - return world.isAirBlock(pos) - } - private fun inRangeOf(color: String, pos: Vec3): Boolean { - when (color) { - "orange" -> { - return (pos.xCoord.toInt() in 82..88 - && pos.yCoord.toInt() in 15..22 - && pos.zCoord.toInt() in 53..59) - } - "red" -> { - return (pos.xCoord.toInt() in 24..30 - && pos.yCoord.toInt() in 15..22 - && pos.zCoord.toInt() in 56..62) - } - "green" -> { - return (pos.xCoord.toInt() in 23..29 - && pos.yCoord.toInt() in 15..22 - && pos.zCoord.toInt() in 91..97) - } - "purple" -> { - return (pos.xCoord.toInt() in 53..59 - && pos.yCoord.toInt() in 15..22 - && pos.zCoord.toInt() in 122..128) - } - "blue" -> { - return (pos.xCoord.toInt() in 82..88 - && pos.yCoord.toInt() in 15..22 - && pos.zCoord.toInt() in 91..97) - } - else -> { - return false - } - } - } - - @SubscribeEvent - fun dragonBoxes(event: RenderWorldLastEvent) { - if (!Config.dragonKillBox) return - if (!ScoreBoardUtils.isInM7) return - if (mc.thePlayer.positionVector.yCoord > 45) return - // Blue - WorldRenderUtils.drawCustomBox(71.5, 25.0, 16.0, 10.0, 82.5, 25.0, Color(0, 170, 170, 255), 3f, phase = false) - // Purple - WorldRenderUtils.drawCustomBox(45.5, 23.0, 13.0, 10.0, 113.5, 23.0, Color(170, 0, 170, 255), 3f, phase = false) - // Green - WorldRenderUtils.drawCustomBox(7.0, 30.0, 8.0, 20.0, 80.0, 30.0, Color(85, 255, 85, 255), 3f, phase = false) - // Red - WorldRenderUtils.drawCustomBox(14.5, 25.0, 13.0, 15.0, 45.5, 25.0, Color(255, 85, 85, 255), 3f, phase = false) - // Orange - WorldRenderUtils.drawCustomBox(72.0, 30.0, 8.0, 20.0, 47.0, 30.0, Color(255, 170, 0, 255), 3f, phase = false) - } -} +object DragonTimer { + data class Dragon(val color: String, val pos: Vec3, var spawnTime: Long) + private val dragons = arrayOf( + Dragon("orange", Vec3(84.0, 18.0, 56.0), 0), + Dragon("red", Vec3(27.0, 18.0, 56.0), 0), + Dragon("green", Vec3(26.0, 18.0, 95.0), 0), + Dragon("purple", Vec3(57.0, 18.0, 125.0), 0), + Dragon("blue", Vec3(84.0, 18.0, 95.0), 0) + ) + + /** + * Called from within the MixinWorld Class + */ + fun handleNewParticle(pID: Int, x: Double, y: Double, z: Double) { + if (!Config.dragonTimer) return + + if (pID != 26) return + // if (!TabListUtils.isInDungeons) return + //TextUtils.info("§6particle id ${particleID} 175 = $p_175720_2_") + + val particleVec = Vec3(x, y, z) + dragons.forEach { + if (System.currentTimeMillis() - it.spawnTime < 10000 || !inRangeOf(it.color, particleVec)) return@forEach + it.spawnTime = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + renderDragonBoxes() + + if (!Config.dragonTimer) return + val curTime = System.currentTimeMillis() + dragons.forEach { + if (it.spawnTime + 5000 < curTime || isDead(it.color)) return@forEach + val timeUntilSpawn = (it.spawnTime + 5000 - curTime) / 1000f + val color = when { + timeUntilSpawn <= 1 -> "§c" + timeUntilSpawn <= 3 -> "§e" + else -> "§a" + } + + val scale = max(1.0, mc.thePlayer.positionVector.distanceTo(it.pos) / 5.0).toFloat() + + WorldRenderUtils.renderString( + it.pos, "${color}${String.format("%.2f", timeUntilSpawn)}", false, scale, true + ) + } + } + + /** + * true = dead + */ + private fun isDead(color: String): Boolean { + val world: World = mc.theWorld + val pos = when (color) { + "orange" -> BlockPos(90, 21, 56) + "red" -> BlockPos(20, 22, 59) + "green" -> BlockPos(22, 21, 94) + "purple" -> BlockPos(56, 20, 130) + "blue" -> BlockPos(89, 21, 94) + else -> BlockPos(0, 0, 0) + } + return world.isAirBlock(pos) + } + + private fun inRangeOf(color: String, pos: Vec3): Boolean { + val x = pos.xCoord.toInt() + val y = pos.yCoord.toInt() + val z = pos.zCoord.toInt() + + return when (color) { + "orange" -> { + x in 82..88 && y in 15..22 && z in 53..59 + } + + "red" -> { + x in 24..30 && y in 15..22 && z in 56..62 + } + + "green" -> { + x in 23..29 && y in 15..22 && z in 91..97 + } + + "purple" -> { + x in 53..59 && y in 15..22 && z in 122..128 + } + + "blue" -> { + x in 82..88 && y in 15..22 && z in 91..97 + } + + else -> { + false + } + } + } + + private fun renderDragonBoxes() { + if (!Config.dragonKillBox) return + if (!ScoreBoardUtils.isInM7) return + if (mc.thePlayer.positionVector.yCoord > 45) return + // Blue + WorldRenderUtils.drawCustomBox(71.5, 25.0, 16.0, 10.0, 82.5, 25.0, Color(0, 170, 170, 255), 3f, phase = false) + // Purple + WorldRenderUtils.drawCustomBox(45.5, 23.0, 13.0, 10.0, 113.5, 23.0, Color(170, 0, 170, 255), 3f, phase = false) + // Green + WorldRenderUtils.drawCustomBox(7.0, 30.0, 8.0, 20.0, 80.0, 30.0, Color(85, 255, 85, 255), 3f, phase = false) + // Red + WorldRenderUtils.drawCustomBox(14.5, 25.0, 13.0, 15.0, 45.5, 25.0, Color(255, 85, 85, 255), 3f, phase = false) + // Orange + WorldRenderUtils.drawCustomBox(72.0, 30.0, 8.0, 20.0, 47.0, 30.0, Color(255, 170, 0, 255), 3f, phase = false) + } + }
\ No newline at end of file |