Skip to content

Commit

Permalink
Feature: SBA style Enchant Parsing (#654)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
VixidDev and hannibal002 authored Apr 25, 2024
1 parent ed53f75 commit f3b3b44
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ import at.hannibal2.skyhanni.features.misc.items.AuctionHouseCopyUnderbidPrice
import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue
import at.hannibal2.skyhanni.features.misc.items.EstimatedWardrobePrice
import at.hannibal2.skyhanni.features.misc.items.GlowingDroppedItems
import at.hannibal2.skyhanni.features.misc.items.enchants.EnchantParser
import at.hannibal2.skyhanni.features.misc.limbo.LimboPlaytime
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures
Expand Down Expand Up @@ -842,6 +843,7 @@ class SkyHanniMod {
loadModule(DungeonFinderFeatures())
loadModule(GoldenGoblinHighlight())
loadModule(TabWidgetSettings())
loadModule(EnchantParser)
loadModule(PabloHelper())
loadModule(FishingBaitWarnings())
loadModule(CustomScoreboard())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package at.hannibal2.skyhanni.config.features.inventory;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.utils.LorenzColor;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.observer.Property;

public class EnchantParsingConfig {

@Expose
@ConfigOption(name = "Enable", desc = "Toggle for coloring the enchants. Turn this off if you want to use enchant parsing from other mods.")
@ConfigEditorBoolean
@FeatureToggle
public Property<Boolean> colorParsing = Property.of(true);

@Expose
@ConfigOption(name = "Format", desc = "The way the enchants are formatted in the tooltip.")
@ConfigEditorDropdown()
public Property<EnchantFormat> format = Property.of(EnchantFormat.NORMAL);

public enum EnchantFormat {
NORMAL("Normal"),
COMPRESSED("Compressed"),
STACKED("Stacked");

public final String str;

EnchantFormat(String str) {
this.str = str;
}

@Override
public String toString() {
return str;
}
}

@Expose
@ConfigOption(name = "Perfect Enchantment Color", desc = "The color an enchantment will be at max level.")
@ConfigEditorDropdown()
public Property<LorenzColor> perfectEnchantColor = Property.of(LorenzColor.CHROMA);

@Expose
@ConfigOption(name = "Great Enchantment Color", desc = "The color an enchantment will be at a great level.")
@ConfigEditorDropdown()
public Property<LorenzColor> greatEnchantColor = Property.of(LorenzColor.GOLD);

@Expose
@ConfigOption(name = "Good Enchantment Color", desc = "The color an enchantment will be at a good level.")
@ConfigEditorDropdown()
public Property<LorenzColor> goodEnchantColor = Property.of(LorenzColor.BLUE);

@Expose
@ConfigOption(name = "Poor Enchantment Color", desc = "The color an enchantment will be at a poor level.")
@ConfigEditorDropdown()
public Property<LorenzColor> poorEnchantColor = Property.of(LorenzColor.GRAY);

@Expose
@ConfigOption(name = "Comma Format", desc = "Change the format of the comma after each enchant.")
@ConfigEditorDropdown()
public Property<CommaFormat> commaFormat = Property.of(CommaFormat.COPY_ENCHANT);

public enum CommaFormat {
COPY_ENCHANT("Copy enchant format"),
DEFAULT("Default (Blue)");

public final String str;

CommaFormat(String str) {
this.str = str;
}

@Override
public String toString() {
return str;
}
}

@Expose
@ConfigOption(name = "Hide Vanilla Enchants", desc = "Hide the regular vanilla enchants usually found in the first 1-2 lines of lore.")
@ConfigEditorBoolean
@FeatureToggle
public Property<Boolean> hideVanillaEnchants = Property.of(true);

@Expose
@ConfigOption(name = "Hide Enchant Description", desc = "Hides the enchant description after each enchant if available.")
@ConfigEditorBoolean
@FeatureToggle
public Property<Boolean> hideEnchantDescriptions = Property.of(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class InventoryConfig {
@Category(name = "Bazaar", desc = "Bazaar settings.")
public BazaarConfig bazaar = new BazaarConfig();

@Expose
@Category(name = "Enchant Parsing", desc = "Settings for Skyhanni's Enchant Parsing")
public EnchantParsingConfig enchantParsing = new EnchantParsingConfig();

@Expose
@Category(name = "Helpers", desc = "Settings for Helpers")
public HelperConfig helper = new HelperConfig();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/events/ChatHoverEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package at.hannibal2.skyhanni.events

import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText

/**
* This event is mainly used for doing things on chat hover and reading the chat component
* of the hovered chat.
*
* To edit the chat component, add to, or use methods in [GuiChatHook][at.hannibal2.skyhanni.mixins.hooks.GuiChatHook].
*
* The edited chat component in [GuiChatHook][at.hannibal2.skyhanni.mixins.hooks.GuiChatHook] does not change the actual
* chat component, but rather makes a new one just before rendering.
*/
class ChatHoverEvent(val component: ChatComponentText) : LorenzEvent() {
fun getHoverEvent(): HoverEvent = component.chatStyle.chatHoverEvent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package at.hannibal2.skyhanni.features.misc.items.enchants

class Cache {
var cachedLoreBefore: List<String> = listOf()
var cachedLoreAfter: List<String> = listOf()

// So tooltip gets changed on the same item if the config was changed in the interim
var configChanged = false

fun updateBefore(loreBeforeModification: List<String>) {
cachedLoreBefore = loreBeforeModification.toList()
}

fun updateAfter(loreAfterModification: List<String>) {
cachedLoreAfter = loreAfterModification.toList()
configChanged = false
}

fun isCached(loreBeforeModification: List<String>): Boolean {
if (configChanged || loreBeforeModification.size != cachedLoreBefore.size) return false
return loreBeforeModification.indices.none { loreBeforeModification[it] != cachedLoreBefore[it] }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package at.hannibal2.skyhanni.features.misc.items.enchants

import at.hannibal2.skyhanni.SkyHanniMod
import com.google.gson.annotations.Expose
import java.util.TreeSet

open class Enchant : Comparable<Enchant> {
@Expose
var nbtName = ""

@Expose
var loreName = ""

@Expose
private var goodLevel = 0

@Expose
private var maxLevel = 0

private fun isNormal() = this is Normal
private fun isUltimate() = this is Ultimate
private fun isStacking() = this is Stacking

open fun getFormattedName(level: Int) = getFormat(level) + loreName

open fun getFormat(level: Int): String {
val config = SkyHanniMod.feature.inventory.enchantParsing

if (level >= maxLevel) return config.perfectEnchantColor.get().getChatColor()
if (level > goodLevel) return config.greatEnchantColor.get().getChatColor()
if (level == goodLevel) return config.goodEnchantColor.get().getChatColor()
return config.poorEnchantColor.get().getChatColor()
}

override fun toString() = "$nbtName $goodLevel $maxLevel\n"

override fun compareTo(other: Enchant): Int {
if (this.isUltimate() == other.isUltimate()) {
if (this.isStacking() == other.isStacking()) {
return this.loreName.compareTo(other.loreName)
}
return if (this.isStacking()) -1 else 1
}
return if (this.isUltimate()) -1 else 1
}

class Normal : Enchant() {
}

class Ultimate : Enchant() {
override fun getFormat(level: Int) = "§d§l"
}

class Stacking : Enchant() {
@Expose
private var nbtNum: String? = null

@Expose
private var statLabel: String? = null

@Expose
private var stackLevel: TreeSet<Int>? = null

override fun toString() = "$nbtNum ${stackLevel.toString()} ${super.toString()}"
}

class Dummy(name: String) : Enchant() {
init {
loreName = name
nbtName = name
}

// Ensures enchants not yet in repo stay as vanilla formatting
// (instead of that stupid dark red lowercase formatting *cough* sba *cough*)
override fun getFormattedName(level: Int) = "§9$loreName"
}
}
Loading

0 comments on commit f3b3b44

Please sign in to comment.