diff options
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/utils')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/Area.kt | 34 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/RenderUtils.kt | 42 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/SkyBlock.kt (renamed from src/main/kotlin/com/ambientaddons/utils/LocationUtils.kt) | 17 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonClass.kt | 16 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayer.kt | 6 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayers.kt | 28 |
6 files changed, 135 insertions, 8 deletions
diff --git a/src/main/kotlin/com/ambientaddons/utils/Area.kt b/src/main/kotlin/com/ambientaddons/utils/Area.kt new file mode 100644 index 0000000..8366a05 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/Area.kt @@ -0,0 +1,34 @@ +package com.ambientaddons.utils + +enum class Area { + Dungeon, + PrivateIsland, + DungeonHub, + GoldMine, + DeepCaverns, + DwarvenMines, + CrystalHollows, + SpiderDen, + CrimsonIsle, + End, + Park, + FarmingIslands; + + companion object { + fun fromString(str: String?): Area? = when (str?.lowercase()) { + "Crimson Isle" -> CrimsonIsle + "Catacombs" -> Dungeon + "Private Island" -> PrivateIsland + "Dungeon Hub" -> DungeonHub + "Gold Mine" -> GoldMine + "Deep Caverns" -> DeepCaverns + "Dwarven Mines" -> DwarvenMines + "Crystal Hollows" -> CrystalHollows + "Spider's Den" -> SpiderDen + "The Park" -> Park + "The End" -> End + "The Farming Islands" -> FarmingIslands + else -> null + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/utils/RenderUtils.kt b/src/main/kotlin/com/ambientaddons/utils/RenderUtils.kt new file mode 100644 index 0000000..f10a711 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/RenderUtils.kt @@ -0,0 +1,42 @@ +package com.ambientaddons.utils + +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.WorldRenderer +import net.minecraft.client.renderer.vertex.DefaultVertexFormats +import kotlin.math.roundToInt + +object RenderUtils { + + // from Mojang + fun renderDurabilityBar(x: Int, y: Int, percentFilled: Double) { + val percent = percentFilled.coerceIn(0.0, 1.0) + if (percent == 0.0) return + val barWidth = (percentFilled * 13.0).roundToInt() + val barColorIndex = (percentFilled * 255.0).roundToInt() + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableTexture2D() + GlStateManager.disableAlpha() + GlStateManager.disableBlend() + val tessellator = Tessellator.getInstance() + val worldrenderer = tessellator.worldRenderer + draw(worldrenderer, x + 2, y + 13, 13, 2, 0, 0, 0, 255) + draw(worldrenderer, x + 2, y + 13, 12, 1, (255 - barColorIndex) / 4, 64, 0, 255) + draw(worldrenderer, x + 2, y + 13, barWidth, 1, 255 - barColorIndex, barColorIndex, 0, 255) + GlStateManager.enableAlpha() + GlStateManager.enableTexture2D() + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + + private fun draw(renderer: WorldRenderer, x: Int, y: Int, width: Int, height: Int, red: Int, green: Int, blue: Int, alpha: Int) { + renderer.begin(7, DefaultVertexFormats.POSITION_COLOR) + renderer.pos((x + 0).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + 0).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + width).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + Tessellator.getInstance().draw() + } + +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/utils/LocationUtils.kt b/src/main/kotlin/com/ambientaddons/utils/SkyBlock.kt index d185a08..cb108ee 100644 --- a/src/main/kotlin/com/ambientaddons/utils/LocationUtils.kt +++ b/src/main/kotlin/com/ambientaddons/utils/SkyBlock.kt @@ -13,11 +13,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import net.minecraftforge.fml.common.network.FMLNetworkEvent -object LocationUtils { +object SkyBlock { private var areaRegex = Regex("^(?:Area|Dungeon): ([\\w ].+)\$") - private var onHypixel = false + var onHypixel = false var inSkyblock = false - var location: String? = null + var area: Area? = null var dungeonFloor: DungeonFloor? = null var ticks = 0 @@ -25,7 +25,7 @@ object LocationUtils { fun onWorldUnload(event: WorldEvent.Unload) { inSkyblock = false dungeonFloor = null - location = null + area = null } @SubscribeEvent @@ -64,13 +64,14 @@ object LocationUtils { inSkyblock = title?.contains("SKYBLOCK") == true } if (inSkyblock) { - if (location == null) { + if (area == null) { val tab = fetchTabEntries() - location = tab.firstNotNullOfOrNull { areaRegex.find(it.text.stripControlCodes()) }?.let { + val locationString = tab.firstNotNullOfOrNull { areaRegex.find(it.text.stripControlCodes()) }?.let { it.groupValues.getOrNull(1) } + area = Area.fromString(locationString) } - if (location == "Catacombs" && dungeonFloor == null) { + if (area == Area.Dungeon && dungeonFloor == null) { val dungeonLine = fetchScoreboardLines().find { it.run { contains("The Catacombs (") && !contains("Queue") } } @@ -82,6 +83,6 @@ object LocationUtils { } override fun toString(): String = - "onHypixel: $onHypixel, inSkyblock: $inSkyblock, location: $location, floor: $dungeonFloor" + "onHypixel: $onHypixel, inSkyblock: $inSkyblock, location: $area, floor: $dungeonFloor" }
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonClass.kt b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonClass.kt new file mode 100644 index 0000000..75442d0 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonClass.kt @@ -0,0 +1,16 @@ +package com.ambientaddons.utils.dungeon + +enum class DungeonClass { + Healer, Tank, Mage, Archer, Berserk; + + companion object { + fun fromString(str: String?): DungeonClass? = when (str?.lowercase()) { + "healer" -> Healer + "tank" -> Tank + "mage" -> Mage + "archer" -> Archer + "berserk" -> Berserk + else -> null + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayer.kt b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayer.kt new file mode 100644 index 0000000..b7903f5 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayer.kt @@ -0,0 +1,6 @@ +package com.ambientaddons.utils.dungeon + +data class DungeonPlayer(val name: String) { + var dungeonClass: DungeonClass? = null + var isAlive: Boolean = true +} diff --git a/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayers.kt b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayers.kt new file mode 100644 index 0000000..ba21a04 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/dungeon/DungeonPlayers.kt @@ -0,0 +1,28 @@ +package com.ambientaddons.utils.dungeon + +import com.ambientaddons.utils.Extensions.stripControlCodes +import com.ambientaddons.utils.Area +import com.ambientaddons.utils.SkyBlock +import com.ambientaddons.utils.TabListUtils +import com.ambientaddons.utils.text +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent + +object DungeonPlayers { + private val playerRegex = Regex("^\\[\\d{1,3}] (?<name>[\\w]{3,16}) (?:.*)*\\((?:(?<class>Healer|Tank|Berserk|Mage|Archer) (?<level>[XVIL0]+)|(?<status>DEAD|EMPTY))\\)") + var playerCount = 0 + private val playerSlots = listOf(5, 9, 13, 17, 1) + private var ticks = 0 + + @SubscribeEvent + fun onTick(event: ClientTickEvent) { + if (SkyBlock.area != Area.Dungeon) return + if (ticks % 10 == 0) { + val rawPlayers = TabListUtils.fetchTabEntries().let { tabEntries -> + playerSlots.map { tabEntries[it].text.stripControlCodes() } + } + playerCount = rawPlayers.size + } + ticks++ + } +}
\ No newline at end of file |