diff options
author | Vahvl <74665243+Vahvl@users.noreply.github.com> | 2024-08-26 13:34:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 12:34:28 +0200 |
commit | 8db1b0a2394a9a804af0df87f10f12b91906ec74 (patch) | |
tree | a5f113d6e2344fd79813acc52a8807eb85124d04 /src/main/java/at/hannibal2/skyhanni | |
parent | 396ba68990b5719a5f65678da0fd27926028f033 (diff) | |
download | skyhanni-8db1b0a2394a9a804af0df87f10f12b91906ec74.tar.gz skyhanni-8db1b0a2394a9a804af0df87f10f12b91906ec74.tar.bz2 skyhanni-8db1b0a2394a9a804af0df87f10f12b91906ec74.zip |
Improvement: Clicked blocks highlight (#2166)
Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
3 files changed, 130 insertions, 32 deletions
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 1729623d2..60809f44f 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 @@ -12,9 +12,8 @@ public class DungeonConfig { @Expose @ConfigOption(name = "Clicked Blocks", desc = "Highlight levers, chests, and Wither Essence when clicked in Dungeons.") - @ConfigEditorBoolean - @FeatureToggle - public boolean highlightClickedBlocks = false; + @Accordion + public HighlightClickedBlocksConfig clickedBlocks = new HighlightClickedBlocksConfig(); @Expose @ConfigOption(name = "Milestones Display", desc = "Show the current milestone in Dungeons.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/HighlightClickedBlocksConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/HighlightClickedBlocksConfig.java new file mode 100644 index 000000000..6ba7232b0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dungeon/HighlightClickedBlocksConfig.java @@ -0,0 +1,61 @@ +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.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class HighlightClickedBlocksConfig { + @Expose + @ConfigOption(name = "Enabled", desc = "Highlight levers, chests, and wither essence when clicked in Dungeons.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Chest Color", desc = "Color of clicked chests.") + @ConfigEditorColour + public String chestColor = "0:178:85:255:85"; + + @Expose + @ConfigOption(name = "Trapped Chest Color", desc = "Color of clicked trapped chests.") + @ConfigEditorColour + public String trappedChestColor = "0:178:0:170:0"; + + @Expose + @ConfigOption(name = "Locked Chest Color", desc = "Color of clicked locked chests.") + @ConfigEditorColour + public String lockedChestColor = "0:178:255:85:85"; + + @Expose + @ConfigOption(name = "Wither Essence Color", desc = "Color of clicked wither essence.") + @ConfigEditorColour + public String witherEssenceColor = "0:178:255:85:255"; + + @Expose + @ConfigOption(name = "Lever Color", desc = "Color of clicked levers.") + @ConfigEditorColour + public String leverColor = "0:178:255:255:85"; + + @Expose + @ConfigOption(name = "Show Text", desc = "Shows a text saying what you clicked with the highlight.") + @ConfigEditorBoolean + public boolean showText = true; + + @Expose + @ConfigOption(name = "Random Color", desc = "If enabled makes the colors random.") + @ConfigEditorBoolean + public boolean randomColor = false; + + @ConfigOption(name = "Reset Colors", desc = "Resets the colors of the highlights to default ones.") + @ConfigEditorButton(buttonText = "Reset") + public Runnable reset = () -> { + chestColor = "0:178:85:255:85"; + trappedChestColor = "0:178:0:170:0"; + lockedChestColor = "0:178:255:85:85"; + witherEssenceColor = "0:178:255:85:255"; + leverColor = "0:178:255:255:85"; + }; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHighlightClickedBlocks.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHighlightClickedBlocks.kt index 16b5cb5f6..64bdc90da 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHighlightClickedBlocks.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHighlightClickedBlocks.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.dungeon import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -8,49 +9,77 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.BlockUtils import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt +import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor +import at.hannibal2.skyhanni.utils.ExtendedChatColor import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.drawColor import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.TimeLimitedCache +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.init.Blocks import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color +import kotlin.time.Duration.Companion.seconds @SkyHanniModule object DungeonHighlightClickedBlocks { - private val blocks = mutableListOf<ClickedBlock>() - private var colorIndex = 0 - private val colors = listOf(LorenzColor.YELLOW, LorenzColor.AQUA, LorenzColor.GREEN, LorenzColor.LIGHT_PURPLE) + private val config get() = SkyHanniMod.feature.dungeon.clickedBlocks + + private val patternGroup = RepoPattern.group("dungeons.highlightclickedblock") + private val leverPattern by patternGroup.pattern( + "lever", + "§cYou hear the sound of something opening...", + ) + private val lockedPattern by patternGroup.pattern( + "locked", + "§cThat chest is locked!", + ) - private fun getNextColor(): LorenzColor { + private val blocks = TimeLimitedCache<LorenzVec, ClickedBlock>(3.seconds) + private var colorIndex = 0 + val undesirableColors = listOf( + LorenzColor.BLACK, + LorenzColor.WHITE, + LorenzColor.CHROMA, + LorenzColor.GRAY, + LorenzColor.DARK_GRAY, + ) + private val randomColors = LorenzColor.entries.filter { it !in undesirableColors } + + private fun getRandomColor(): LorenzColor { var id = colorIndex + 1 - if (id == colors.size) id = 0 + if (id == randomColors.size) id = 0 colorIndex = id - return colors[colorIndex] + return randomColors[colorIndex] } @SubscribeEvent fun onChat(event: LorenzChatEvent) { - if (!SkyHanniMod.feature.dungeon.highlightClickedBlocks) return - if (!DungeonAPI.inDungeon()) return + if (!isEnabled()) return - if (event.message == "§cYou hear the sound of something opening...") { + if (leverPattern.matches(event.message)) { event.blockedReason = "dungeon_highlight_clicked_block" } + + if (lockedPattern.matches(event.message)) { + blocks.lastOrNull { it.value.displayText.contains("Chest") }?.value?.color = config.lockedChestColor.toChromaColor() + } } @SubscribeEvent fun onBlockClick(event: BlockClickEvent) { - if (!SkyHanniMod.feature.dungeon.highlightClickedBlocks) return - if (!DungeonAPI.inDungeon()) return - if (DungeonAPI.inBossRoom) return + if (!isEnabled()) return if (event.clickType != ClickType.RIGHT_CLICK) return val position = event.position - if (blocks.any { it.position == position }) return + if (blocks.containsKey(position)) return val type: ClickedBlockType = when (position.getBlockAt()) { - Blocks.chest, Blocks.trapped_chest -> ClickedBlockType.CHEST + Blocks.chest -> ClickedBlockType.CHEST + Blocks.trapped_chest -> ClickedBlockType.TRAPPED_CHEST Blocks.lever -> ClickedBlockType.LEVER Blocks.skull -> ClickedBlockType.WITHER_ESSENCE else -> return @@ -69,28 +98,37 @@ object DungeonHighlightClickedBlocks { val inWaterRoom = DungeonAPI.getRoomID() == "-60,-60" if (inWaterRoom && type == ClickedBlockType.LEVER) return - val color = getNextColor() - val displayText = color.getChatColor() + "Clicked " + type.display - blocks.add(ClickedBlock(position, displayText, color, System.currentTimeMillis())) + val color = if (config.randomColor) getRandomColor().toColor() else type.color().toChromaColor() + val displayText = ExtendedChatColor(color.rgb, false).toString() + "Clicked " + type.display + blocks[position] = ClickedBlock(displayText, color) + } + + enum class ClickedBlockType(val display: String, val color: () -> String) { + LEVER("Lever", { config.leverColor }), + CHEST("Chest", { config.chestColor }), + TRAPPED_CHEST("Trapped Chest", { config.trappedChestColor }), + WITHER_ESSENCE("Wither Essence", { config.witherEssenceColor }), } @SubscribeEvent fun onWorldRender(event: LorenzRenderWorldEvent) { - if (!SkyHanniMod.feature.dungeon.highlightClickedBlocks) return - if (!DungeonAPI.inDungeon()) return + if (!isEnabled()) return - blocks.removeAll { System.currentTimeMillis() > it.time + 3000 } - blocks.forEach { - event.drawColor(it.position, it.color) - event.drawString(it.position.add(0.5, 0.5, 0.5), it.displayText, true) + blocks.forEach { (position, block) -> + event.drawColor(position, block.color) + if (config.showText) { + event.drawString(position.add(0.5, 0.5, 0.5), block.displayText, true) + } } } - class ClickedBlock(val position: LorenzVec, val displayText: String, val color: LorenzColor, val time: Long) - - enum class ClickedBlockType(val display: String) { - LEVER("Lever"), - CHEST("Chest"), - WITHER_ESSENCE("Wither Essence"), + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(52, "dungeon.highlightClickedBlocks", "dungeon.clickedBlocks.enabled") } + + class ClickedBlock(val displayText: String, var color: Color) + + fun isEnabled() = !DungeonAPI.inBossRoom && DungeonAPI.inDungeon() && config.enabled + } |