Skip to content

Commit

Permalink
option to hide pet candy count on max + fix pet lvl regex
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Dec 29, 2023
1 parent c7fff03 commit bdd5750
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive

object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 18
const val CONFIG_VERSION = 19
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class MiscConfig {
@Accordion
public TrackerConfig tracker = new TrackerConfig();

@Expose
@ConfigOption(name = "Pet Candy Display", desc = "")
@Accordion
public PetCandyDisplayConfig petCandy = new PetCandyDisplayConfig();

@Expose
@ConfigOption(name = "Exp Bottles", desc = "Hides all the experience orbs lying on the ground.")
@ConfigEditorBoolean
Expand Down Expand Up @@ -153,12 +158,6 @@ public class MiscConfig {
@Expose
public Position playerMovementSpeedPos = new Position(394, 124, false, true);

@Expose
@ConfigOption(name = "Pet Candy Used", desc = "Show the number of Pet Candy used on a pet.")
@ConfigEditorBoolean
@FeatureToggle
public boolean petCandyUsed = true;

@Expose
@ConfigOption(name = "Server Restart Title", desc = "Show a title with seconds remaining until the server restarts after a Game Update or Scheduled Restart.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package at.hannibal2.skyhanni.config.features.misc;

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

public class PetCandyDisplayConfig {
@Expose
@ConfigOption(name = "Pet Candy Used", desc = "Show the number of Pet Candy used on a pet.")
@ConfigEditorBoolean
@FeatureToggle
public boolean showCandy = true;

@Expose
@ConfigOption(name = "Hide On Maxed", desc = "Hides the candy count on pets that are max level.")
@ConfigEditorBoolean
@FeatureToggle
public boolean hideOnMaxed = false;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package at.hannibal2.skyhanni.features.misc

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.drawSlotText
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMaxPetLevel
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetCandyUsed
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetLevel
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class PetCandyUsedDisplay {

private val config get() = SkyHanniMod.feature.misc.petCandy

@SubscribeEvent
fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) {
val stack = event.stack ?: return
if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return
if (!SkyHanniMod.feature.misc.petCandyUsed) return
if (!config.showCandy) return

if (config.hideOnMaxed) {
if (stack.getPetLevel() == stack.getMaxPetLevel()) return
}

val petCandyUsed = stack.getPetCandyUsed() ?: return
if (petCandyUsed == 0) return
Expand All @@ -24,4 +33,9 @@ class PetCandyUsedDisplay {

event.drawSlotText(x, y, stackTip, .9f)
}

@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(19, "misc.petCandyUsed", "misc.petCandy.showCandy")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object SkyBlockItemModifierUtils {
private val drillPartTypes = listOf("drill_part_upgrade_module", "drill_part_engine", "drill_part_fuel_tank")

// TODO USE SH-REPO
private val petLevelPattern = "§7\\[Lvl (?<level>.*)\\] .*".toPattern()
private val petLevelPattern = "(?:§f§f)?§7\\[Lvl (?<level>\\d+)] .*".toPattern()

fun ItemStack.getHotPotatoCount() = getAttributeInt("hot_potato_count")

Expand Down Expand Up @@ -100,6 +100,8 @@ object SkyBlockItemModifierUtils {
return 0
}

fun ItemStack.getMaxPetLevel() = if (this.getInternalName() == "GOLDEN_DRAGON;4".asInternalName()) 200 else 100

fun ItemStack.getDrillUpgrades() = getExtraAttributes()?.let {
val list = mutableListOf<NEUInternalName>()
for (attributes in it.keySet) {
Expand Down

0 comments on commit bdd5750

Please sign in to comment.