Skip to content

Commit

Permalink
Make Set Highlighting use lore rather than ItemAbility data
Browse files Browse the repository at this point in the history
Oxyopiia committed Jul 27, 2024
1 parent 27c697d commit cb4a63c
Showing 2 changed files with 72 additions and 19 deletions.
48 changes: 30 additions & 18 deletions src/main/java/net/oxyopia/vice/config/Config.java
Original file line number Diff line number Diff line change
@@ -206,24 +206,6 @@ public void OPEN_DEV_CONFIG() {
)
public int ITEM_COOLDOWN_TITLE_TYPE = 0;

@Property(
type = PropertyType.SWITCH,
name = "Set Colors in Inventory",
description = "Highlights ability items in the inventory with their respective set color.",
category = "Abilities",
subcategory = "Quality of Life"
)
public boolean INVENTORY_SET_COLORS = false;

@Property(
type = PropertyType.PERCENT_SLIDER,
name = "Set Colors Opacity",
description = "The opacity of Set Colors in Inventory.",
category = "Abilities",
subcategory = "Quality of Life"
)
public float INVENTORY_SET_COLORS_OPACITY = 0.5f;

@Property(
type = PropertyType.SWITCH,
name = "Wrong Set Indicator",
@@ -292,6 +274,35 @@ public void OPEN_DEV_CONFIG() {
)
public float ITEMCD_BACKGROUND_OPACITY = 0.2f;

// Abilities/Set Color Overlay

@Property(
type = PropertyType.SWITCH,
name = "Set Colors in Inventory",
description = "Highlights ability items in the inventory with their respective set color.",
category = "Abilities",
subcategory = "Set Colors"
)
public boolean INVENTORY_SET_COLORS = false;

@Property(
type = PropertyType.PERCENT_SLIDER,
name = "Set Colors Opacity",
description = "The opacity of Set Colors in Inventory.",
category = "Abilities",
subcategory = "Set Colors"
)
public float INVENTORY_SET_COLORS_OPACITY = 0.5f;

@Property(
type = PropertyType.SWITCH,
name = "Include Armor in Set Colors",
description = "Whether to highlight armor with their Set Color too.",
category = "Abilities",
subcategory = "Set Colors"
)
public boolean INCLUDE_ARMOR_IN_SET_COLORS = true;

// Arenas/Quality of Life

@Property(
@@ -779,6 +790,7 @@ public void init() {
addDependency("HIDE_ITEMCD_WHEN_READY", "ITEMCD_DISPLAY_TYPE", (value) -> ITEM_COOLDOWN_DISPLAY && (int) value != 0 && (int) value != 4);
addDependency("ITEMCD_BACKGROUND_OPACITY", "ITEM_COOLDOWN_DISPLAY");
addDependency("INVENTORY_SET_COLORS_OPACITY", "INVENTORY_SET_COLORS");
addDependency("INCLUDE_ARMOR_IN_SET_COLORS", "INVENTORY_SET_COLORS");

addDependency("LIVE_ARENA_MOBS", "LIVE_ARENA_TOGGLE");
addDependency("LIVE_ARENA_ROUND_TIMER", "LIVE_ARENA_TOGGLE");
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
package net.oxyopia.vice.features.itemabilities

import gg.essential.elementa.utils.withAlpha
import net.fabricmc.fabric.api.item.v1.EnchantingContext
import net.minecraft.enchantment.Enchantments
import net.minecraft.item.ItemStack
import net.oxyopia.vice.Vice
import net.oxyopia.vice.data.Set
import net.oxyopia.vice.events.ContainerRenderSlotEvent
import net.oxyopia.vice.events.core.SubscribeEvent
import net.oxyopia.vice.utils.HudUtils.highlight
import net.oxyopia.vice.utils.ItemUtils.cleanName
import net.oxyopia.vice.utils.ItemUtils.getLore
import net.oxyopia.vice.utils.ItemUtils.isPlayerHeadWithArmor

object SetHighlighting {
private val cache = hashMapOf<String, Set?>()
private val loreRegex by lazy {
Regex("♦ Set: (.+)")
}

@SubscribeEvent
fun onInventorySlotRender(event: ContainerRenderSlotEvent) {
if (!Vice.config.INVENTORY_SET_COLORS) return
val item = event.slot.stack

if (!Vice.config.INCLUDE_ARMOR_IN_SET_COLORS &&
(item.canBeEnchantedWith(Enchantments.PROTECTION, EnchantingContext.ANVIL) || item.isPlayerHeadWithArmor())
) return

val set = ItemAbility.getByName(event.slot.stack.cleanName())?.set ?: return
val set = event.slot.stack.getSet(event) ?: return
event.highlight(set.color.withAlpha(Vice.config.INVENTORY_SET_COLORS_OPACITY))
}

private fun ItemStack.getSet(event: ContainerRenderSlotEvent): Set? {
val name = cleanName()

return cache[name] ?: run {
val lore = getLore()
if (lore.isEmpty()) return null

lore.forEach {
loreRegex.find(it)?.apply {
val matchedSet = Set.getByName(groupValues[1])

cache[name] = matchedSet
return@run matchedSet
}
}

if (event.shouldCacheEmpty()) cache[name] = null
return null
}
}

private fun ContainerRenderSlotEvent.shouldCacheEmpty(): Boolean {
return chestName.contains("Crafting") || chestName.contains("Backpack")
}
}

0 comments on commit cb4a63c

Please sign in to comment.