diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-02 11:08:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-02 11:08:16 +0200 |
commit | 7a6c175ead0be52201f62d116dba953e5e112fa8 (patch) | |
tree | f984bdb70cafcec2b1ef1787e7ebee084ef98001 /src/main/java | |
parent | 32e7a457983a0a6050d7db8bd99dec52a5164979 (diff) | |
download | skyhanni-7a6c175ead0be52201f62d116dba953e5e112fa8.tar.gz skyhanni-7a6c175ead0be52201f62d116dba953e5e112fa8.tar.bz2 skyhanni-7a6c175ead0be52201f62d116dba953e5e112fa8.zip |
Fix: Contributor nametag flicker Patcher (#2296)
Co-authored-by: nea <nea@nea.moe>
Diffstat (limited to 'src/main/java')
4 files changed, 23 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt index c8e90fd27..c4e5fd7e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt @@ -23,16 +23,15 @@ 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.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable import kotlin.time.Duration.Companion.milliseconds @SkyHanniModule object EntityData { private val maxHealthMap = mutableMapOf<EntityLivingBase, Int>() - private val nametagCache = TimeLimitedCache<Entity, IChatComponent>(50.milliseconds) + private val nametagCache = TimeLimitedCache<Entity, ChatComponentText>(50.milliseconds) @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -95,11 +94,11 @@ object EntityData { } @JvmStatic - fun getDisplayName(entity: Entity, ci: CallbackInfoReturnable<IChatComponent>) { - ci.returnValue = postRenderNametag(entity, ci.returnValue) + fun getDisplayName(entity: Entity, oldValue: ChatComponentText): ChatComponentText { + return postRenderNametag(entity, oldValue) } - private fun postRenderNametag(entity: Entity, chatComponent: IChatComponent) = nametagCache.getOrPut(entity) { + private fun postRenderNametag(entity: Entity, chatComponent: ChatComponentText) = nametagCache.getOrPut(entity) { val event = EntityDisplayNameEvent(entity, chatComponent) event.postAndCatch() event.chatComponent diff --git a/src/main/java/at/hannibal2/skyhanni/events/entity/EntityDisplayNameEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityDisplayNameEvent.kt index 1a3bcfed4..c4d24eb0a 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/entity/EntityDisplayNameEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityDisplayNameEvent.kt @@ -2,6 +2,6 @@ package at.hannibal2.skyhanni.events.entity import at.hannibal2.skyhanni.events.LorenzEvent import net.minecraft.entity.Entity -import net.minecraft.util.IChatComponent +import net.minecraft.util.ChatComponentText -class EntityDisplayNameEvent(val entity: Entity, var chatComponent: IChatComponent) : LorenzEvent() +class EntityDisplayNameEvent(val entity: Entity, var chatComponent: ChatComponentText) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntity.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntity.java index 951e65e27..12f1cdc61 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntity.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntity.java @@ -2,17 +2,19 @@ package at.hannibal2.skyhanni.mixins.transformers; import at.hannibal2.skyhanni.data.EntityData; import net.minecraft.entity.Entity; -import net.minecraft.util.IChatComponent; +import net.minecraft.util.ChatComponentText; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(Entity.class) public abstract class MixinEntity { - @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) - public void getDisplayName(CallbackInfoReturnable<IChatComponent> ci) { - EntityData.getDisplayName((Entity) (Object) this, ci); + @ModifyVariable( + method = "getDisplayName", + at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ChatStyle;setInsertion(Ljava/lang/String;)Lnet/minecraft/util/ChatStyle;", shift = At.Shift.AFTER) + ) + public ChatComponentText getDisplayName(ChatComponentText value) { + return EntityData.getDisplayName((Entity) (Object) this, value); } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityPlayer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityPlayer.java index 4a0d4d4a3..876ea1c8b 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityPlayer.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityPlayer.java @@ -2,17 +2,20 @@ package at.hannibal2.skyhanni.mixins.transformers; import at.hannibal2.skyhanni.data.EntityData; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(EntityPlayer.class) public class MixinEntityPlayer { - @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) - public void getDisplayName(CallbackInfoReturnable<IChatComponent> ci) { - EntityData.getDisplayName((EntityPlayer) (Object) this, ci); + @ModifyVariable( + method = "getDisplayName", + at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ChatStyle;setInsertion(Ljava/lang/String;)Lnet/minecraft/util/ChatStyle;", shift = At.Shift.AFTER) + ) + public IChatComponent getDisplayName(IChatComponent value) { + return EntityData.getDisplayName((EntityPlayer) (Object) this, (ChatComponentText) value); } } |