Skip to content

Commit

Permalink
Have the options independent to allow other mod enchant parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
VixidDev committed Oct 31, 2023
1 parent bba4dd7 commit 7f0640f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.Accordion;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

public class EnchantParsingConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Toggle for Enchant Parsing")
@ConfigOption(name = "Enabled", desc = "Global Toggle for entire category")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;
Expand All @@ -27,35 +28,50 @@ public class EnchantParsingConfig {
public boolean hideEnchantDescriptions = false;

@Expose
@ConfigOption(name = "Perfect Enchantment Color", desc = "The color an enchantment will be at max level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int perfectEnchantColor = 16;
@ConfigOption(name = "Enchant Coloring", desc = "")
@Accordion
public ColorEnchants colorEnchants = new ColorEnchants();

@Expose
@ConfigOption(name = "Great Enchantment Color", desc = "The color an enchantment will be at a great level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int greatEnchantColor = 6;
public static class ColorEnchants {

@Expose
@ConfigOption(name = "Good Enchantment Color", desc = "The color an enchantment will be at a good level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int goodEnchantColor = 9;
@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 boolean colorParsing = true;

@Expose
@ConfigOption(name = "Poor Enchantment Color", desc = "The color an enchantment will be at a poor level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int poorEnchantColor = 7;
@Expose
@ConfigOption(name = "Perfect Enchantment Color", desc = "The color an enchantment will be at max level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int perfectEnchantColor = 16;

@Expose
@ConfigOption(name = "Comma Format", desc = "Change the format of the comma after each enchant.")
@ConfigEditorDropdown(values = {"Copy enchant format", "Default (Blue)"})
public int commaFormat = 0;
@Expose
@ConfigOption(name = "Great Enchantment Color", desc = "The color an enchantment will be at a great level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int greatEnchantColor = 6;

@Expose
@ConfigOption(name = "Good Enchantment Color", desc = "The color an enchantment will be at a good level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int goodEnchantColor = 9;

@Expose
@ConfigOption(name = "Poor Enchantment Color", desc = "The color an enchantment will be at a poor level.")
@ConfigEditorDropdown(values = {"§0Black", "§1Dark Blue", "§2Dark Green", "§3Dark Aqua", "§4Dark Red",
"§5Dark Purple", "§6Gold", "§7Gray", "§8Dark Gray", "§9Blue", "§aGreen", "§bAqua",
"§cRed", "§dPink", "§eYellow", "§fWhite", "§ZChroma"})
public int poorEnchantColor = 7;

@Expose
@ConfigOption(name = "Comma Format", desc = "Change the format of the comma after each enchant.")
@ConfigEditorDropdown(values = {"Copy enchant format", "Default (Blue)"})
public int commaFormat = 0;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object EnchantParser {
private val GRAY_ENCHANT_PATTERN = Pattern.compile("^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*")

private var indexOfLastGrayEnchant = -1
private var loreLines: MutableList<String> = mutableListOf()

private val gson = Gson()
private val loreCache: Cache = Cache()
Expand Down Expand Up @@ -111,6 +112,7 @@ object EnchantParser {
var shouldBeSingleColumn = false
val orderedEnchants: TreeSet<FormattedEnchant> = TreeSet()
var lastEnchant: FormattedEnchant? = null
loreLines = mutableListOf()

// Order all enchants
for (i in startEnchant..endEnchant) {
Expand Down Expand Up @@ -144,10 +146,20 @@ object EnchantParser {

if (!containsEnchant && lastEnchant != null) {
lastEnchant.addLore(loreList[i])
loreLines.add(loreList[i])
hasLore = true
}
}

// If we have color parsing off and hide enchant descriptions, remove them and return from method
if (!SkyHanniMod.feature.enchantParsing.colorEnchants.colorParsing) {
if (SkyHanniMod.feature.enchantParsing.hideEnchantDescriptions) {
loreList.removeAll(loreLines)
return
}
return
}

if (orderedEnchants.isEmpty()) {
loreCache.updateAfter(loreList)
return
Expand All @@ -160,7 +172,7 @@ object EnchantParser {

// Check we don't have any enchants with description lore
if (!hasLore && !shouldBeSingleColumn) {
val commaFormat = SkyHanniMod.feature.enchantParsing.commaFormat
val commaFormat = SkyHanniMod.feature.enchantParsing.colorEnchants.commaFormat

var builder = StringBuilder()

Expand Down Expand Up @@ -286,7 +298,7 @@ object EnchantParser {
open fun getFormattedName(level: Int) = getFormat(level) + loreName

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

if (level >= maxLevel) return "§" + COLOR_CODES[config.perfectEnchantColor]
if (level > goodLevel) return "§" + COLOR_CODES[config.greatEnchantColor]
Expand Down

0 comments on commit 7f0640f

Please sign in to comment.