From c48d82d06f375139f1e0a0a32ffd6d2f4aa98546 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:56:56 +0200 Subject: [PATCH] Feature: Pet Nametag (#1880) Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> --- .../config/features/misc/pets/PetConfig.java | 5 ++ .../features/misc/pets/PetNametagConfig.java | 19 +++++++ .../misc/{ => pets}/CurrentPetDisplay.kt | 2 +- .../misc/{ => pets}/PetCandyUsedDisplay.kt | 2 +- .../features/misc/{ => pets}/PetExpTooltip.kt | 2 +- .../misc/{ => pets}/PetItemDisplay.kt | 2 +- .../skyhanni/features/misc/pets/PetNametag.kt | 56 +++++++++++++++++++ 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetNametagConfig.java rename src/main/java/at/hannibal2/skyhanni/features/misc/{ => pets}/CurrentPetDisplay.kt (98%) rename src/main/java/at/hannibal2/skyhanni/features/misc/{ => pets}/PetCandyUsedDisplay.kt (96%) rename src/main/java/at/hannibal2/skyhanni/features/misc/{ => pets}/PetExpTooltip.kt (99%) rename src/main/java/at/hannibal2/skyhanni/features/misc/{ => pets}/PetItemDisplay.kt (96%) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetNametag.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetConfig.java index 8cd295249ad5..02c2b2ed45fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetConfig.java @@ -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.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetNametagConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetNametagConfig.java new file mode 100644 index 000000000000..4da1b816014e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/pets/PetNametagConfig.java @@ -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; + +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/CurrentPetDisplay.kt similarity index 98% rename from src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt rename to src/main/java/at/hannibal2/skyhanni/features/misc/pets/CurrentPetDisplay.kt index 1c93d6b3c82a..6f74f353d46a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/CurrentPetDisplay.kt @@ -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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetCandyUsedDisplay.kt similarity index 96% rename from src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt rename to src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetCandyUsedDisplay.kt index c80c30f09c74..e331e6c750ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetCandyUsedDisplay.kt @@ -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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetExpTooltip.kt similarity index 99% rename from src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt rename to src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetExpTooltip.kt index 3a7cf784a0c9..8e544a3dfefc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetExpTooltip.kt @@ -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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetItemDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetItemDisplay.kt similarity index 96% rename from src/main/java/at/hannibal2/skyhanni/features/misc/PetItemDisplay.kt rename to src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetItemDisplay.kt index 12e82a893716..9d3349c5b1e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetItemDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetItemDisplay.kt @@ -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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetNametag.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetNametag.kt new file mode 100644 index 000000000000..f3b16069e655 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pets/PetNametag.kt @@ -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", + "(?§8\\[§7Lv(?\\d+)§8]) (?§.)(?[\\w\\s]+)(?§. ✦)?", + ) + + @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) +}