Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Vahvl authored Jun 27, 2024
1 parent 867694f commit 484d67a
Showing 1 changed file with 57 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,73 @@
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
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<LorenzVec, ClickedBlock>(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<ClickedBlock>()
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
Expand All @@ -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
}

0 comments on commit 484d67a

Please sign in to comment.