diff options
author | ronald <inglettronald@gmail.com> | 2023-07-27 20:26:07 -0500 |
---|---|---|
committer | ronald <inglettronald@gmail.com> | 2023-07-27 20:26:07 -0500 |
commit | 71b8238eff91de0243e641c2eeadacd61b8f0f88 (patch) | |
tree | d85ade48712412986eaf22663517327712552775 /src | |
parent | a1294824e249df578551447b40c920a45c3eb457 (diff) | |
download | DulkirMod-Fabric-71b8238eff91de0243e641c2eeadacd61b8f0f88.tar.gz DulkirMod-Fabric-71b8238eff91de0243e641c2eeadacd61b8f0f88.tar.bz2 DulkirMod-Fabric-71b8238eff91de0243e641c2eeadacd61b8f0f88.zip |
Miniboss Highlight and performance optimizations
Diffstat (limited to 'src')
5 files changed, 93 insertions, 1 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index 208a267..7db8905 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -10,15 +10,18 @@ import com.dulkirfabric.features.* import com.dulkirfabric.features.chat.AbiPhoneDND import com.dulkirfabric.features.chat.BridgeBotFormatter import com.dulkirfabric.features.chat.ChatStacking +import com.dulkirfabric.features.slayer.MiniBossHighlight import com.dulkirfabric.hud.ActionBarHudReplacements import com.dulkirfabric.hud.SpeedOverlay import com.dulkirfabric.util.ActionBarUtil +import com.dulkirfabric.util.ScoreBoardUtils import com.dulkirfabric.util.TablistUtils import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents @@ -78,6 +81,8 @@ object Registrations { EVENT_BUS.subscribe(ActionBarHudReplacements) EVENT_BUS.subscribe(ChatStacking) EVENT_BUS.subscribe(AotvHighlight) + EVENT_BUS.subscribe(MiniBossHighlight) + EVENT_BUS.subscribe(ScoreBoardUtils) if (FabricLoader.getInstance().isDevelopmentEnvironment) EVENT_BUS.subscribe(RenderTest) diff --git a/src/main/kotlin/com/dulkirfabric/features/slayer/MiniBossHighlight.kt b/src/main/kotlin/com/dulkirfabric/features/slayer/MiniBossHighlight.kt new file mode 100644 index 0000000..4720890 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/slayer/MiniBossHighlight.kt @@ -0,0 +1,60 @@ +package com.dulkirfabric.features.slayer + +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.events.WorldRenderLastEvent +import com.dulkirfabric.util.ScoreBoardUtils +import com.dulkirfabric.util.TextUtils +import com.dulkirfabric.util.Utils.getInterpolatedPos +import com.dulkirfabric.util.render.WorldRenderUtils +import meteordevelopment.orbit.EventHandler +import net.minecraft.entity.decoration.ArmorStandEntity +import net.minecraft.util.math.Box +import java.awt.Color + + +object MiniBossHighlight { + data class MiniBoss(val name: String, val box: Box) + + private val zombieBox = Box(-.3, .1, -.3, .3, -1.9, .3) + private val spiderBox = Box(-.7, -.3, -.7, .7, -1.2, .7) + private val wolfBox = Box(-.3, -0.0, -.3, .3, -.85, .3) + private val emanBox = Box(-.3, 0.0, -.3, .3, -2.9, .3) + private val blazeBox = Box(-.4, -.2, -.4, .4, -2.0, .4) + + private val miniBosses = listOf( + MiniBoss("Revenant Sycophant", zombieBox), + MiniBoss("Revenant Champion", zombieBox), + MiniBoss("Deformed Revenant", zombieBox), + MiniBoss("Atoned Champion", zombieBox), + MiniBoss("Atoned Revenant", zombieBox), + MiniBoss("Tarantula Vermin", spiderBox), + MiniBoss("Tarantula Beast", spiderBox), + MiniBoss("Mutant Tarantula", spiderBox), + MiniBoss("Pack Enforcer", wolfBox), + MiniBoss("Sven Follower", wolfBox), + MiniBoss("Sven Alpha", wolfBox), + MiniBoss("Voidling Devotee", emanBox), + MiniBoss("Voidling Radical", emanBox), + MiniBoss("Voidcrazed Maniac", emanBox), + MiniBoss("Flare Demon", blazeBox), + MiniBoss("Kindleheart Demon", blazeBox), + MiniBoss("Burningsoul Demon", blazeBox) + ) + + @EventHandler + fun drawMiniBossBoxes(event: WorldRenderLastEvent) { + // TODO: check for a slayer quest being active + if (!ScoreBoardUtils.hasActiveSlayerQuest) return + + val ents = mc.world?.entities ?: return + + ents.forEach { + if (it !is ArmorStandEntity) return@forEach + val name = it.customName?.string ?: return@forEach + val result = miniBosses.find { mini -> name.contains(mini.name) } ?: return@forEach + WorldRenderUtils.drawWireFrame(event.context, result.box.offset(it.getInterpolatedPos(event.context.tickDelta())) + , Color(0, 255, 0), 8f) + } + } + +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt b/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt index a2bdb3a..fb2f967 100644 --- a/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt @@ -1,6 +1,8 @@ package com.dulkirfabric.util import com.dulkirfabric.DulkirModFabric +import com.dulkirfabric.events.LongUpdateEvent +import meteordevelopment.orbit.EventHandler import net.minecraft.scoreboard.Team import net.minecraft.text.StringVisitable import net.minecraft.text.Style @@ -10,6 +12,8 @@ import java.util.* object ScoreBoardUtils { + var hasActiveSlayerQuest = false + /** * Gets Scoreboard lines, will return null if not in Skyblock. */ @@ -69,4 +73,12 @@ object ScoreBoardUtils { }, Style.EMPTY) return sb.toString().replace("§[^a-f0-9]".toRegex(), "") } + + @EventHandler + fun updateUtility(event: LongUpdateEvent) { + val lines = getLines() ?: return + hasActiveSlayerQuest = lines.any { + it.contains("Slayer Quest") + } + } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt b/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt index c3baa9e..d5e3e37 100644 --- a/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt @@ -5,6 +5,7 @@ import net.minecraft.text.Text object TextUtils { const val CHAT_PREFIX = "§f<§3DulkirMod§f>§r" + private val colorRegex = "§.".toRegex() fun info(text: String, prefix: Boolean = true) { if (mc.player == null) return @@ -33,6 +34,6 @@ object TextUtils { } fun stripColorCodes(string: String): String { - return string.replace("§.".toRegex(), "") + return string.replace(colorRegex, "") } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/Utils.kt b/src/main/kotlin/com/dulkirfabric/util/Utils.kt index 4ceb8c4..93597d2 100644 --- a/src/main/kotlin/com/dulkirfabric/util/Utils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/Utils.kt @@ -1,6 +1,8 @@ package com.dulkirfabric.util import com.dulkirfabric.events.PlaySoundEvent +import net.minecraft.entity.Entity +import net.minecraft.util.math.Vec3d object Utils { fun isInSkyblock(): Boolean { @@ -18,4 +20,16 @@ object Utils { println("Pitch: ${event.sound.pitch}") println("Volume: ${event.sound.volume}") } + + private fun lerp(prev: Vec3d, cur: Vec3d, tickDelta: Float): Vec3d { + return Vec3d( + prev.x + (cur.x - prev.x) * tickDelta, + prev.y + (cur.y - prev.y) * tickDelta, + prev.z + (cur.z - prev.z) * tickDelta, + ) + } + fun Entity.getInterpolatedPos(tickDelta: Float): Vec3d { + val prevPos = Vec3d(this.prevX, this.prevY, this.prevZ) + return lerp(prevPos, this.pos, tickDelta) + } }
\ No newline at end of file |