Skip to content

Commit

Permalink
Feature: Pet Nametag (hannibal002#1880)
Browse files Browse the repository at this point in the history
Co-authored-by: Empa <[email protected]>
Co-authored-by: Cal <[email protected]>
Co-authored-by: hannibal2 <[email protected]>
Co-authored-by: CalMWolfs <[email protected]>
  • Loading branch information
5 people authored Sep 11, 2024
1 parent 7aea6aa commit c48d82d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class PetConfig {
@Accordion
public PetExperienceToolTipConfig petExperienceToolTip = new PetExperienceToolTipConfig();

@Expose
@ConfigOption(name = "Pet Nametag", desc = "")
@Accordion
public PetNametagConfig nametag = new PetNametagConfig();

@Expose
@ConfigOption(name = "Hide Autopet Messages", desc = "Hide the autopet messages from chat.\n" +
"§eRequires the display to be enabled.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package at.hannibal2.skyhanni.config.features.misc.pets;

import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class PetNametagConfig {

@Expose
@ConfigOption(name = "Hide Pet Level", desc = "Hide the pet level above the pet.")
@ConfigEditorBoolean
public boolean hidePetLevel = false;

@Expose
@ConfigOption(name = "Hide Max Pet Level", desc = "Hide the pet level above the pet if it is max level.")
@ConfigEditorBoolean
public boolean hideMaxPetLevel = false;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.misc
package at.hannibal2.skyhanni.features.misc.pets

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.misc
package at.hannibal2.skyhanni.features.misc.pets

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.misc
package at.hannibal2.skyhanni.features.misc.pets

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.misc
package at.hannibal2.skyhanni.features.misc.pets

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package at.hannibal2.skyhanni.features.misc.pets

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.chat.Text.asComponent
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object PetNametag {

private val config get() = SkyHanniMod.feature.misc.pets.nametag

/**
* REGEX-TEST: §8[§7Lv99§8] Ammonite
* REGEX-TEST: §8[§7Lv100§8] Endermite§5 ✦
*/
private val petNametagPattern by RepoPattern.pattern(
"pet.nametag",
"(?<start>§8\\[§7Lv(?<lvl>\\d+)§8]) (?<rarity>§.)(?<pet>[\\w\\s]+)(?<skin>§. ✦)?",
)

@SubscribeEvent
fun onNameTagRender(event: EntityDisplayNameEvent) {
if (!isEnabled()) return
if (event.entity !is EntityArmorStand) return

petNametagPattern.matchMatcher(event.chatComponent.unformattedText) {
val start = group("start")
val lvl = group("lvl").formatInt()
val rarity = group("rarity")
val pet = group("pet")
val skin = groupOrNull("skin") ?: ""

val hideLevel = config.hidePetLevel
val hideMaxLevel = config.hideMaxPetLevel && (lvl == 100 || lvl == 200)

val text = buildString {
if (!hideLevel && !hideMaxLevel) {
append(start)
}
append(rarity + pet + skin)
}

event.chatComponent = text.asComponent()
}
}

private fun isEnabled() = LorenzUtils.inSkyBlock && (config.hidePetLevel || config.hideMaxPetLevel)
}

0 comments on commit c48d82d

Please sign in to comment.