aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-06-02 10:11:16 +0200
committerGitHub <noreply@github.com>2024-06-02 10:11:16 +0200
commit191e24ef1d95f2af571c917237817f8e1648ea0b (patch)
tree941e36445db5f8d1aa3a672d4b6434cdc98df4d7 /src/main/java/at/hannibal2/skyhanni/data
parent4c838a148544a862b7a52ba68347d0d5715e7b5e (diff)
downloadSkyHanni-191e24ef1d95f2af571c917237817f8e1648ea0b.tar.gz
SkyHanni-191e24ef1d95f2af571c917237817f8e1648ea0b.tar.bz2
SkyHanni-191e24ef1d95f2af571c917237817f8e1648ea0b.zip
Improvement: Contributor nametag (#1687)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/EntityData.kt22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
index 4cc5f840d..318ac465a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
@@ -6,11 +6,15 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
+import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
import at.hannibal2.skyhanni.utils.LorenzUtils.derpy
+import at.hannibal2.skyhanni.utils.TimeLimitedCache
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.entity.EntityPlayerSP
+import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.boss.EntityWither
import net.minecraft.entity.item.EntityArmorStand
@@ -18,11 +22,16 @@ import net.minecraft.entity.item.EntityItem
import net.minecraft.entity.item.EntityItemFrame
import net.minecraft.entity.item.EntityXPOrb
import net.minecraft.network.play.server.S1CPacketEntityMetadata
+import net.minecraft.util.IChatComponent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
+import kotlin.time.Duration.Companion.milliseconds
-class EntityData {
+@SkyHanniModule
+object EntityData {
private val maxHealthMap = mutableMapOf<EntityLivingBase, Int>()
+ private val nametagCache = TimeLimitedCache<Entity, IChatComponent>(50.milliseconds)
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
@@ -83,4 +92,15 @@ class EntityData {
}
}
}
+
+ @JvmStatic
+ fun getDisplayName(entity: Entity, ci: CallbackInfoReturnable<IChatComponent>) {
+ ci.returnValue = postRenderNametag(entity, ci.returnValue)
+ }
+
+ private fun postRenderNametag(entity: Entity, chatComponent: IChatComponent) = nametagCache.getOrPut(entity) {
+ val event = EntityDisplayNameEvent(entity, chatComponent)
+ event.postAndCatch()
+ event.chatComponent
+ }
}