-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: SBA style Enchant Parsing (#654)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
ed53f75
commit f3b3b44
Showing
11 changed files
with
700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/at/hannibal2/skyhanni/config/features/inventory/EnchantParsingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/at/hannibal2/skyhanni/events/ChatHoverEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Cache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] } | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.