From 484d67a66e3626ea59d4f633feaea25622724876 Mon Sep 17 00:00:00 2001 From: Vahvl <74665243+Vahvl@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:28:59 +0300 Subject: [PATCH] Add files via upload --- .../dungeon/DungeonHighlightClickedBlocks.kt | 87 ++++++++++++------- 1 file changed, 57 insertions(+), 30 deletions(-) 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 16b5cb5f666a..86df5907451a 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,65 @@ 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.RenderUtils.drawColor import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.TimeLimitedCache 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 config get() = SkyHanniMod.feature.dungeon.clickedBlocks + private val blocks = TimeLimitedCache(3.seconds) + private var colourIndex = 0 + private val colours = LorenzColor.entries.filter { + it !in listOf( + LorenzColor.BLACK, + LorenzColor.WHITE, + LorenzColor.CHROMA, + LorenzColor.GRAY, + LorenzColor.DARK_GRAY, + ) + } - private val blocks = mutableListOf() - private var colorIndex = 0 - private val colors = listOf(LorenzColor.YELLOW, LorenzColor.AQUA, LorenzColor.GREEN, LorenzColor.LIGHT_PURPLE) - - private fun getNextColor(): LorenzColor { - var id = colorIndex + 1 - if (id == colors.size) id = 0 - colorIndex = id - return colors[colorIndex] + private fun getRandomColour(): LorenzColor { + var id = colourIndex + 1 + if (id == colours.size) id = 0 + colourIndex = id + return colours[colourIndex] } @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...") { event.blockedReason = "dungeon_highlight_clicked_block" } + + if (event.message == "§cThat chest is locked!") { + blocks.lastOrNull { it.value.displayText.contains("Chest") }?.value?.colour = config.lockedChestColour.toChromaColor() + } } @SubscribeEvent fun onBlockClick(event: BlockClickEvent) { - if (!SkyHanniMod.feature.dungeon.highlightClickedBlocks) return - if (!DungeonAPI.inDungeon()) return + if (!isEnabled()) return if (DungeonAPI.inBossRoom) 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 +86,38 @@ 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.randomColourEnabled) getRandomColour().toColor() else type.colour() + val displayText = ExtendedChatColor(color.rgb, false).toString() + "Clicked " + type.display + blocks[position] = ClickedBlock(displayText, color) + } + + enum class ClickedBlockType(val display: String, val colour: () -> Color) { + LEVER("Lever", { config.leverColour.toChromaColor() }), + CHEST("Chest", { config.chestColour.toChromaColor() }), + TRAPPED_CHEST("Trapped Chest", { config.trappedChestColour.toChromaColor() }), + WITHER_ESSENCE("Wither Essence", { config.witherEssenceColour.toChromaColor() }), } @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.colour) + if (config.showTextEnabled) { + event.drawString(position.add(0.5, 0.5, 0.5), block.displayText, true) + }else { + return + } } } - 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 colour: Color) + + fun isEnabled() = DungeonAPI.inDungeon() && config.enabled }