From 2dac2c177c83f5c222ef1558a3b1772923ad3777 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:27:32 +0200 Subject: [PATCH] Feature: Starred Mob Highlight + Fels Highlight/Line (#1558) Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .idea/dictionaries/default_user.xml | 1 + .../features/dungeon/DungeonConfig.java | 5 + .../dungeon/ObjectHighlighterConfig.java | 72 +++++++++ .../at/hannibal2/skyhanni/data/mob/Mob.kt | 21 ++- .../features/dungeon/DungeonMobManager.kt | 149 ++++++++++++++++++ 5 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/dungeon/ObjectHighlighterConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMobManager.kt diff --git a/.idea/dictionaries/default_user.xml b/.idea/dictionaries/default_user.xml index db27217cfba0..b94b0c94a02c 100644 --- a/.idea/dictionaries/default_user.xml +++ b/.idea/dictionaries/default_user.xml @@ -81,6 +81,7 @@ explosivity ezpz fairylosopher + fels fermento firedust firesale diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/DungeonConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/DungeonConfig.java index b76039da1036..1729623d264d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/DungeonConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/DungeonConfig.java @@ -67,6 +67,11 @@ public class DungeonConfig { @FeatureToggle public boolean architectNotifier = true; + @Expose + @ConfigOption(name = "Object Highlighter", desc = "Highlights various things in Dungeons.") + @Accordion + public ObjectHighlighterConfig objectHighlighter = new ObjectHighlighterConfig(); + @Expose @ConfigOption(name = "Object Hider", desc = "Hide various things in Dungeons.") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/ObjectHighlighterConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/ObjectHighlighterConfig.java new file mode 100644 index 000000000000..385c162c6623 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/ObjectHighlighterConfig.java @@ -0,0 +1,72 @@ +package at.hannibal2.skyhanni.config.features.dungeon; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.Accordion; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorInfoText; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.observer.Property; + +public class ObjectHighlighterConfig { + + // TODO move some stuff from DungeonConfig into this + + @Expose + @ConfigOption(name = "Stared", desc = "") + @Accordion + public StarredConfig starred = new StarredConfig(); + + public static class StarredConfig { + @Expose + @ConfigOption(name = "Highlight Starred", desc = "Highlights all starred mobs in one colour.") + @ConfigEditorBoolean + @FeatureToggle + public Property highlight = Property.of(true); + + /* + TODO for someone who has time + @Expose + @ConfigOption(name = "Show Outline", desc = "Shows only a outline instead of a full highlight.") + @ConfigEditorBoolean + public Property showOutline = Property.of(true); */ + + @ConfigOption( + name = "No Chroma", + desc = "§cThe chroma setting for the color is currently not working!" + ) + @ConfigEditorInfoText + public String info; + + @Expose + @ConfigOption(name = "Colour", desc = "Color in which the stared mobs are highlighted.") + @ConfigEditorColour + public Property colour = Property.of("0:60:255:255:0"); + } + + @Expose + @ConfigOption(name = "Fels Skull", desc = "") + @Accordion + public FelConfig fel = new FelConfig(); + + public static class FelConfig { + + @Expose + @ConfigOption(name = "Highlight Fels Skull", desc = "Highlights fels that are not yet active.") + @ConfigEditorBoolean + @FeatureToggle + public Property highlight = Property.of(true); + + @Expose + @ConfigOption(name = "Draw Line", desc = "Draws a line to fels skulls. Works only if the highlight is enabled.") + @ConfigEditorBoolean + public Boolean line = false; + + @Expose + @ConfigOption(name = "Colour", desc = "Color for the fel skull and line.") + @ConfigEditorColour + public Property colour = Property.of("0:200:255:0:255"); + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt index 1d5827490f54..7e7e9f96cdc8 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt @@ -115,10 +115,17 @@ class Mob( private var highlightColor: Color? = null - /** If no alpha is set or alpha is set to 255 it will set the alpha to 127 */ - fun highlight(color: Color) { - highlightColor = color.takeIf { it.alpha == 255 }?.addAlpha(127) ?: color - internalHighlight() + /** If [color] has no alpha or alpha is set to 255 it will set the alpha to 127 + * If [color] is set to null it removes a highlight*/ + fun highlight(color: Color?) { + if (color == highlightColor) return + if (color == null) { + internalRemoveColor() + highlightColor = null + } else { + highlightColor = color.takeIf { it.alpha == 255 }?.addAlpha(127) ?: color + internalHighlight() + } } private fun internalHighlight() { @@ -162,8 +169,10 @@ class Mob( } private fun makeRelativeBoundingBox() = - (baseEntity.entityBoundingBox.union(extraEntities.filter { it !is EntityArmorStand } - .mapNotNull { it.entityBoundingBox }))?.offset(-baseEntity.posX, -baseEntity.posY, -baseEntity.posZ) + (baseEntity.entityBoundingBox.union( + extraEntities.filter { it !is EntityArmorStand } + .mapNotNull { it.entityBoundingBox }, + ))?.offset(-baseEntity.posX, -baseEntity.posY, -baseEntity.posZ) fun fullEntityList() = baseEntity.toSingletonListOrEmpty() + diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMobManager.kt new file mode 100644 index 000000000000..46450a5645d5 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMobManager.kt @@ -0,0 +1,149 @@ +package at.hannibal2.skyhanni.features.dungeon + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.mob.Mob +import at.hannibal2.skyhanni.data.mob.MobData +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.MobEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor +import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine +import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.RenderUtils.exactPlayerEyeLocation +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color + +@SkyHanniModule +object DungeonMobManager { + + private val config get() = SkyHanniMod.feature.dungeon.objectHighlighter + private val starredConfig get() = config.starred + private val fel get() = config.fel + + private val staredInvisible = mutableSetOf() + private val felOnTheGround = mutableSetOf() + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + onToggle( + starredConfig.highlight, + starredConfig.colour, + ) { + val color = if (starredConfig.highlight.get()) getStarColor() else null + MobData.skyblockMobs.filter { it.hasStar }.forEach { + handleStar0(it, color) + } + if (!starredConfig.highlight.get()) { + staredInvisible.clear() + } + } + onToggle( + fel.highlight, + fel.colour, + ) { + if (fel.highlight.get()) { + if (felOnTheGround.isEmpty()) { + MobData.skyblockMobs.forEach(::handleFel) + } + } else { + felOnTheGround.clear() + } + } + } + + @SubscribeEvent + fun onMobSpawn(event: MobEvent.Spawn.SkyblockMob) { + if (event.mob.mobType != Mob.Type.DUNGEON) return + handleStar(event.mob) + handleFel(event.mob) + } + + @SubscribeEvent + fun onMobDeSpawn(event: MobEvent.DeSpawn.SkyblockMob) { + if (event.mob.mobType != Mob.Type.DUNGEON) return + if (starredConfig.highlight.get()) { + staredInvisible.remove(event.mob) + } + handleFelDespawn(event.mob) + } + + @SubscribeEvent + fun onLorenzTick(event: LorenzTickEvent) { + if (!IslandType.CATACOMBS.isInIsland()) return + handleInvisibleStar() + } + + @SubscribeEvent + fun onRenderWorld(event: LorenzRenderWorldEvent) { + if (!fel.highlight.get()) return + if (fel.line) { + felOnTheGround.filter { it.canBeSeen() }.forEach { + event.draw3DLine( + it.baseEntity.getLorenzVec().add(y = 0.15), + event.exactPlayerEyeLocation(), + fel.colour.get().toChromaColor(), + 3, + true, + ) + } + } + + felOnTheGround.removeIf { mob -> + event.drawWaypointFilled( + mob.baseEntity.getLorenzVec().add(-0.5, -0.23, -0.5), + fel.colour.get().toChromaColor(), + seeThroughBlocks = false, + beacon = false, + extraSize = -0.2, + minimumAlpha = 0.8f, + inverseAlphaScale = true, + ) + !mob.isInvisible() + } + } + + private fun handleStar(mob: Mob) { + if (!starredConfig.highlight.get()) return + if (!mob.hasStar) return + handleStar0(mob, getStarColor()) + } + + private fun handleInvisibleStar() { + if (!starredConfig.highlight.get()) return + staredInvisible.removeIf { + val visible = !it.isInvisible() + if (visible) { + it.highlight(getStarColor()) + } + visible + } + } + + private fun getStarColor(): Color = starredConfig.colour.get().toChromaColor() + + private fun handleStar0(mob: Mob, colour: Color?) { + if (mob.isInvisible()) { + staredInvisible.add(mob) + return + } + mob.highlight(colour) + } + + private fun handleFel(mob: Mob) { + if (!fel.highlight.get()) return + if (mob.name != "Fels") return + if (!mob.isInvisible()) return + felOnTheGround.add(mob) + } + + private fun handleFelDespawn(mob: Mob) { + if (!fel.highlight.get()) return + felOnTheGround.remove(mob) + } +}