Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Starred Mob Highlight + Fels Highlight/Line #1558

Merged
merged 14 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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<Boolean> 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<String> 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<Boolean> 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<String> colour = Property.of("0:200:255:0:255");
}

}
11 changes: 8 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ 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()
fun highlight(color: Color?) {
if (color == highlightColor) return
highlightColor = color?.takeIf { it.alpha == 255 }?.addAlpha(127) ?: color
if (color == null) {
internalRemoveColor()
} else {
internalHighlight()
}
}

private fun internalHighlight() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
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.test.GriffinUtils.drawWaypointFilled
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.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 starred get() = config.starred
private val fel get() = config.fel

@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
onToggle(
starred.highlight,
starred.colour,
// starred.showOutline
) {
val color = if (starred.highlight.get()) null else starred.colour.get().toChromaColor()
MobData.skyblockMobs.filter { it.hasStar }.forEach {
handleStar0(it, color)
}
if (!starred.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 (starred.highlight.get()) {
staredInvisible.remove(event.mob)
}
handleFelDespawn(event.mob)
}

@SubscribeEvent
fun onLorenzTick(event: LorenzTickEvent) {
if (!IslandType.CATACOMBS.isInIsland()) return
handleInvisibleStar()
}

private val staredInvisible = mutableSetOf<Mob>()

private fun handleStar(mob: Mob) {
if (!starred.highlight.get()) return
if (!mob.hasStar) return
handleStar0(mob, starred.colour.get().toChromaColor())
}

private fun handleInvisibleStar() {
if (!starred.highlight.get()) return
if (staredInvisible.isEmpty()) return
staredInvisible.removeIf {
val visible = !it.isInvisible()
if (visible) {
it.highlight(starred.colour.get().toChromaColor())
}
visible
}
}

private fun handleStar0(mob: Mob, colour: Color?) {
if (mob.isInvisible()) {
staredInvisible.add(mob)
return
}
mob.highlight(colour)
}

private val felOnTheGround = mutableSetOf<Mob>()

private fun handleFel(mob: Mob) {
if (!fel.highlight.get()) return
if (mob.name != "Fels") return
if (!mob.isInvisible()) return
felOnTheGround.add(mob)
}

@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(),
false,
false,
extraSize = -0.2,
minimumAlpha = 0.8f,
inverseAlphaScale = true
)
!mob.isInvisible()
}
}

private fun handleFelDespawn(mob: Mob) {
if (!fel.highlight.get()) return
felOnTheGround.remove(mob)
}
}
7 changes: 6 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ object GriffinUtils {
extraSize: Double = 0.0,
extraSizeTopY: Double = extraSize,
extraSizeBottomY: Double = extraSize,
minimumAlpha: Float = 0.2f,
inverseAlphaScale: Boolean = false,
) {
val (viewerX, viewerY, viewerZ) = RenderUtils.getViewerPos(partialTicks)
val x = location.x - viewerX
Expand All @@ -35,7 +37,10 @@ object GriffinUtils {
x + 1 + extraSize, y + 1 + extraSizeTopY, z + 1 + extraSize
).expandBlock(),
color,
(0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(0.2f)
if (inverseAlphaScale)
(1.0f - 0.005f * distSq.toFloat()).coerceAtLeast(minimumAlpha)
else
(0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(minimumAlpha)
)
GlStateManager.disableTexture2D()
if (distSq > 5 * 5 && beacon) RenderUtils.renderBeaconBeam(x, y + 1, z, color.rgb, 1.0f, partialTicks)
Expand Down
Loading