Skip to content

Commit

Permalink
Merge pull request #1 from ItsEmpa/improvement/highlight-blocks
Browse files Browse the repository at this point in the history
fixes and some formatting
  • Loading branch information
Vahvl authored Jun 27, 2024
2 parents 7232aba + 3ee3523 commit 1314885
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@

public class HighlightClickedBlocksConfig {
@Expose
@ConfigOption(name = "Enabled", desc = "Highlight levers, chests, and Wither Essence when clicked in Dungeons.")
@ConfigOption(name = "Enabled", desc = "Highlight levers, chests, and wither essence when clicked in Dungeons.")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;

@Expose
@ConfigOption(name = "Chest Colour", desc = "Colour of clicked chests")
@ConfigOption(name = "Chest Color", desc = "Color of clicked chests.")
@ConfigEditorColour
public String chestColour = "0:178:85:255:85";
public String chestColor = "0:178:85:255:85";

@Expose
@ConfigOption(name = "Trapped Chest Colour", desc = "Colour of clicked trapped chests")
@ConfigOption(name = "Trapped Chest Color", desc = "Color of clicked trapped chests.")
@ConfigEditorColour
public String trappedChestColour = "0:178:0:170:0";
public String trappedChestColor = "0:178:0:170:0";

@Expose
@ConfigOption(name = "Locked Chest Colour", desc = "Colour of clicked locked chests")
@ConfigOption(name = "Locked Chest Color", desc = "Color of clicked locked chests.")
@ConfigEditorColour
public String lockedChestColour = "0:178:255:85:85";
public String lockedChestColor = "0:178:255:85:85";

@Expose
@ConfigOption(name = "Wither Essence Colour", desc = "Colour of clicked wither essence")
@ConfigOption(name = "Wither Essence Color", desc = "Color of clicked wither essence.")
@ConfigEditorColour
public String witherEssenceColour = "0:178:255:85:255";
public String witherEssenceColor = "0:178:255:85:255";

@Expose
@ConfigOption(name = "Lever Colour", desc = "Colour of clicked levers")
@ConfigOption(name = "Lever Color", desc = "Color of clicked levers.")
@ConfigEditorColour
public String leverColour = "0:178:255:255:85";
public String leverColor = "0:178:255:255:85";

@Expose
@ConfigOption(name = "Show Text", desc = "If enabled shows a text telling you what you clicked with the highlight.")
@ConfigOption(name = "Show Text", desc = "Shows a text saying what you clicked with the highlight.")
@ConfigEditorBoolean
public boolean showTextEnabled = true;
public boolean showText = true;

@Expose
@ConfigOption(name = "Random Colour", desc = "If enabled makes the colours random.")
@ConfigOption(name = "Random Color", desc = "If enabled makes the colors random.")
@ConfigEditorBoolean
public boolean randomColourEnabled = false;
public boolean randomColor = false;

@ConfigOption(name = "Reset Colours", desc = "Resets the colours of the highlights to default ones.")
@ConfigOption(name = "Reset Colors", desc = "Resets the colors of the highlights to default ones.")
@ConfigEditorButton(buttonText = "Reset")
public Runnable reset = () -> {
chestColour = "0:178:85:255:85";
trappedChestColour = "0:178:0:170:0";
lockedChestColour = "0:178:255:85:85";
witherEssenceColour = "0:178:255:85:255";
leverColour = "0:178:255:255:85";
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";
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ 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 {
private var colorIndex = 0
private val colors = LorenzColor.entries.filter {
it !in listOf(
LorenzColor.BLACK,
LorenzColor.WHITE,
Expand All @@ -36,11 +37,11 @@ object DungeonHighlightClickedBlocks {
)
}

private fun getRandomColour(): LorenzColor {
var id = colourIndex + 1
if (id == colours.size) id = 0
colourIndex = id
return colours[colourIndex]
private fun getRandomColor(): LorenzColor {
var id = colorIndex + 1
if (id == colors.size) id = 0
colorIndex = id
return colors[colorIndex]
}

@SubscribeEvent
Expand All @@ -52,7 +53,7 @@ object DungeonHighlightClickedBlocks {
}

if (event.message == "§cThat chest is locked!") {
blocks.lastOrNull { it.value.displayText.contains("Chest") }?.value?.colour = config.lockedChestColour.toChromaColor()
blocks.lastOrNull { it.value.displayText.contains("Chest") }?.value?.color = config.lockedChestColor.toChromaColor()
}
}

Expand Down Expand Up @@ -85,28 +86,26 @@ object DungeonHighlightClickedBlocks {
val inWaterRoom = DungeonAPI.getRoomID() == "-60,-60"
if (inWaterRoom && type == ClickedBlockType.LEVER) return

val color = if (config.randomColourEnabled) getRandomColour().toColor() else type.colour()
val color = if (config.randomColor) getRandomColor().toColor() else type.color()
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() }),
enum class ClickedBlockType(val display: String, val color: () -> Color) {
LEVER("Lever", { config.leverColor.toChromaColor() }),
CHEST("Chest", { config.chestColor.toChromaColor() }),
TRAPPED_CHEST("Trapped Chest", { config.trappedChestColor.toChromaColor() }),
WITHER_ESSENCE("Wither Essence", { config.witherEssenceColor.toChromaColor() }),
}

@SubscribeEvent
fun onWorldRender(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return

blocks.forEach { (position, block) ->
event.drawColor(position, block.colour)
if (config.showTextEnabled) {
event.drawColor(position, block.color)
if (config.showText) {
event.drawString(position.add(0.5, 0.5, 0.5), block.displayText, true)
} else {
return
}
}
}
Expand All @@ -116,8 +115,8 @@ object DungeonHighlightClickedBlocks {
event.move(52, "dungeon.highlightClickedBlocks", "dungeon.clickedBlocks.enabled")
}

class ClickedBlock(val displayText: String, var colour: Color)
class ClickedBlock(val displayText: String, var color: Color)

fun isEnabled() = !DungeonAPI.inBossRoom && inDungeonAPI.inDungeon() && config.enabled
fun isEnabled() = !DungeonAPI.inBossRoom && DungeonAPI.inDungeon() && config.enabled

}

0 comments on commit 1314885

Please sign in to comment.