aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-09-07 23:00:02 +0200
committerGitHub <noreply@github.com>2024-09-07 23:00:02 +0200
commit88416edd2f5a50e1ba88e9adb574e3c60c49abca (patch)
treea2b98d9abb6273dbc11b098c737f087c9bfa4c7c /src/main/java/at/hannibal2/skyhanni
parentae587b6cb7964fbe36a7d70f4b5c944a1671225f (diff)
downloadskyhanni-88416edd2f5a50e1ba88e9adb574e3c60c49abca.tar.gz
skyhanni-88416edd2f5a50e1ba88e9adb574e3c60c49abca.tar.bz2
skyhanni-88416edd2f5a50e1ba88e9adb574e3c60c49abca.zip
Feature: Rift time Nametag Format (#2015)
Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/EntityData.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderPlayer.java23
5 files changed, 66 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java
index 679a01aa3..c2db26b8e 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java
@@ -30,4 +30,10 @@ public class RiftTimerConfig {
@ConfigLink(owner = RiftTimerConfig.class, field = "enabled")
public Position timerPosition = new Position(10, 10, false, true);
+ @Expose
+ @ConfigOption(name = "Nametag Format", desc = "Format the remaining rift time for other players in their nametag.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean nametag = true;
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
index c4e5fd7e7..d2f81a6d8 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent
+import at.hannibal2.skyhanni.events.entity.EntityHealthDisplayEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.EntityUtils
@@ -32,6 +33,7 @@ object EntityData {
private val maxHealthMap = mutableMapOf<EntityLivingBase, Int>()
private val nametagCache = TimeLimitedCache<Entity, ChatComponentText>(50.milliseconds)
+ private val healthDisplayCache = TimeLimitedCache<String, String>(50.milliseconds)
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
@@ -103,4 +105,12 @@ object EntityData {
event.postAndCatch()
event.chatComponent
}
+
+ @JvmStatic
+ fun getHealthDisplay(text: String) = healthDisplayCache.getOrPut(text) {
+ val event = EntityHealthDisplayEvent(text)
+ event.postAndCatch()
+ event.text
+ }
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt
new file mode 100644
index 000000000..5657dc2c8
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.events.entity
+
+import at.hannibal2.skyhanni.events.LorenzEvent
+
+class EntityHealthDisplayEvent(var text: String) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
index a4d277ceb..21f13c156 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
@@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.entity.EntityHealthDisplayEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.TimeUtils
import at.hannibal2.skyhanni.utils.TimeUtils.format
@@ -23,11 +25,20 @@ object RiftTimer {
private val config get() = RiftAPI.config.timer
- private val timePattern by RepoPattern.pattern(
- "rift.everywhere.timer",
+ private val repoGroup = RepoPattern.group("rift.everywhere")
+ private val timePattern by repoGroup.pattern(
+ "timer",
"§(?<color>[a7])(?<time>.*)ф Left.*"
)
+ /**
+ * REGEX-TEST: 3150 §aф
+ */
+ private val nametagPattern by repoGroup.pattern(
+ "nametag.timer",
+ "(?<time>\\d+) §aф"
+ )
+
private var display = emptyList<String>()
private var maxTime = 0.seconds
private var currentTime = 0.seconds
@@ -117,5 +128,14 @@ object RiftTimer {
config.timerPosition.renderStrings(display, posLabel = "Rift Timer")
}
+ @SubscribeEvent
+ fun onEntityHealthDisplay(event: EntityHealthDisplayEvent) {
+ if (!RiftAPI.inRift() || !config.nametag) return
+ val time = nametagPattern.matchMatcher(event.text) {
+ group("time")?.toIntOrNull()
+ } ?: return
+ event.text = "${time.seconds.format()} §aф"
+ }
+
fun isEnabled() = RiftAPI.inRift() && config.enabled
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderPlayer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderPlayer.java
new file mode 100644
index 000000000..7a5dad63b
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderPlayer.java
@@ -0,0 +1,23 @@
+package at.hannibal2.skyhanni.mixins.transformers;
+
+import at.hannibal2.skyhanni.data.EntityData;
+import net.minecraft.client.renderer.entity.RenderPlayer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
+
+@Mixin(RenderPlayer.class)
+public class MixinRenderPlayer {
+
+ @ModifyArg(
+ method = "renderOffsetLivingLabel(Lnet/minecraft/client/entity/AbstractClientPlayer;DDDLjava/lang/String;FD)V",
+ at = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/client/renderer/entity/RenderPlayer;renderLivingLabel(Lnet/minecraft/entity/Entity;Ljava/lang/String;DDDI)V"
+ ),
+ index = 1
+ )
+ private String modifyRenderLivingLabelArgs(String string) {
+ return EntityData.getHealthDisplay(string);
+ }
+}