From 36c4a5d6967901b695f66585497e689f7ded90d7 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Thu, 9 May 2024 21:10:39 +0800 Subject: [PATCH] bug fixes --- .../mixin/EntityRendererMixin.java | 22 +++++++++++++++++++ .../polynametag/mixin/RenderMixin.java | 2 +- .../mixin/RendererLivingEntityMixin.java | 2 +- .../mixin/essential/OnlineIndicatorMixin.java | 4 ++-- .../mixin/levelhead/AboveHeadRenderMixin.java | 15 ++++++++----- .../org/polyfrost/polynametag/PolyNametag.kt | 9 +------- .../polynametag/render/NametagPreview.kt | 2 -- src/main/resources/mixins.polynametag.json | 1 + 8 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java diff --git a/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java new file mode 100644 index 0000000..ab48698 --- /dev/null +++ b/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java @@ -0,0 +1,22 @@ +package org.polyfrost.polynametag.mixin; + +import net.minecraft.client.renderer.EntityRenderer; +import org.polyfrost.polynametag.PolyNametag; +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.CallbackInfo; + +@Mixin(EntityRenderer.class) +public class EntityRendererMixin { + + @Inject(method = "renderWorld", at = @At("HEAD")) + private void start(float partialTicks, long finishTimeNano, CallbackInfo ci) { + PolyNametag.INSTANCE.setDrawingWorld(false); + } + + @Inject(method = "renderWorld", at = @At("TAIL")) + private void end(float partialTicks, long finishTimeNano, CallbackInfo ci) { + PolyNametag.INSTANCE.setDrawingWorld(true); + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java index 9f48bc6..1811115 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java @@ -94,7 +94,7 @@ private void drawBG(Entity entityIn, String str, double x, double y, double z, i @Inject(method = "renderLivingLabel", at = @At("HEAD"), cancellable = true) private void move(Entity entityIn, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; - if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingInGUI()) { + if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingWorld()) { PolyNametag.INSTANCE.getLabels().add(new PolyNametag.LabelInfo((Render) (Object) this, entityIn, str, x, y, z, maxDistance)); ci.cancel(); } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java index 02b31d4..cacffe9 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java @@ -108,7 +108,7 @@ private void drawBG(EntityLivingBase entity, double x, double y, double z, Callb @Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true) private void move(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; - if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingInGUI()) { + if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingWorld()) { PolyNametag.INSTANCE.getNames().add(new PolyNametag.NameInfo((RendererLivingEntity) (Object) this, entity, x, y, z)); ci.cancel(); } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/essential/OnlineIndicatorMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/essential/OnlineIndicatorMixin.java index 9eaae0b..93d59ca 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/essential/OnlineIndicatorMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/essential/OnlineIndicatorMixin.java @@ -36,7 +36,7 @@ public class OnlineIndicatorMixin { @Dynamic("Essential") @Inject(method = "drawNametagIndicator", at = @At("HEAD"), cancellable = true) private static void skip(UMatrixStack matrixStack, Entity entity, String str, int light, CallbackInfo ci) { - if (ModConfig.INSTANCE.enabled) return; + if (!ModConfig.INSTANCE.enabled) return; if (!PolyNametag.INSTANCE.getDrawingEssential()) ci.cancel(); } @@ -51,7 +51,7 @@ private static void skip(UMatrixStack matrixStack, Entity entity, String str, in index = 3 ) private static double polyNametag$modifyBackgroundZ(double z) { - if (ModConfig.INSTANCE.enabled) return z; + if (!ModConfig.INSTANCE.enabled) return z; if (!NametagRenderingKt.shouldDrawBackground()) return z; return z + 0.01; } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java index aeacf51..c146df9 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java @@ -11,10 +11,7 @@ import org.spongepowered.asm.mixin.Dynamic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Coerce; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.awt.*; @@ -30,10 +27,16 @@ public abstract class AboveHeadRenderMixin { @Dynamic("LevelHead") @Inject(method = "renderName", at = @At("HEAD")) private void move(LevelheadTag tag, EntityPlayer entityIn, double x, double y, double z, CallbackInfo ci) { - if (ModConfig.INSTANCE.enabled) return; + if (!ModConfig.INSTANCE.enabled) return; PolyNametag.INSTANCE.setDrawEssential(false); } + @Dynamic("LevelHead") + @ModifyVariable(method = "renderName", at = @At("STORE"), name = "xMultiplier") + private int stupid(int value) { + return PolyNametag.INSTANCE.isPatcher() ? 1 : value; + } + @Dynamic("LevelHead") @Redirect( method = "render(Lnet/minecraftforge/client/event/RenderLivingEvent$Specials$Post;)V", @@ -64,7 +67,7 @@ private void move(LevelheadTag tag, EntityPlayer entityIn, double x, double y, d @Dynamic("LevelHead") @Inject(method = "renderName", at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics;drawDirect()V", shift = At.Shift.AFTER)) private void drawBG(LevelheadTag tag, EntityPlayer entityIn, double x, double y, double z, CallbackInfo ci) { - if (ModConfig.INSTANCE.enabled) return; + if (!ModConfig.INSTANCE.enabled) return; int stringWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(tag.getString()) / 2; float[] color = NametagRenderingKt.getBackBackgroundGLColorOrEmpty(); NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, new Color(color[0], color[1], color[2], color[3]), entityIn); diff --git a/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt b/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt index 848c3a3..74f0276 100644 --- a/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt +++ b/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt @@ -6,7 +6,6 @@ import net.minecraft.client.renderer.entity.Render import net.minecraft.client.renderer.entity.RendererLivingEntity import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase -import net.minecraftforge.client.event.RenderWorldEvent import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Loader @@ -47,17 +46,11 @@ object PolyNametag { var names: MutableList = ArrayList() var drawing = false - var drawingInGUI = false + var drawingWorld = false var drawEssential = false - @SubscribeEvent - fun startWorld(event: RenderWorldEvent.Pre) { - drawingInGUI = false - } - @SubscribeEvent fun onRender(event: RenderWorldLastEvent) { - drawingInGUI = true if (!ModConfig.enabled) return if (names.isEmpty() && labels.isEmpty()) return GlStateManager.pushMatrix() diff --git a/src/main/kotlin/org/polyfrost/polynametag/render/NametagPreview.kt b/src/main/kotlin/org/polyfrost/polynametag/render/NametagPreview.kt index 6530045..cb67ca4 100644 --- a/src/main/kotlin/org/polyfrost/polynametag/render/NametagPreview.kt +++ b/src/main/kotlin/org/polyfrost/polynametag/render/NametagPreview.kt @@ -104,11 +104,9 @@ class NametagPreview( renderManager.playerViewY = 180f renderManager.isRenderShadow = false val renderer = renderManager.getEntityRenderObject(entity) as RendererLivingEntity - PolyNametag.drawingInGUI = true drawing = true renderer.renderName(entity, 0.0, 0.0, 0.0) drawing = false - PolyNametag.drawingInGUI = false entity.riddenByEntity = entity // cancel original nametag renderManager.doRenderEntity(entity, 0.0, 0.0, 0.0, 0f, 1f, true) renderManager.isRenderShadow = true diff --git a/src/main/resources/mixins.polynametag.json b/src/main/resources/mixins.polynametag.json index 4d511f8..739decf 100644 --- a/src/main/resources/mixins.polynametag.json +++ b/src/main/resources/mixins.polynametag.json @@ -7,6 +7,7 @@ "maxShiftBy": 5 }, "client": [ + "EntityRendererMixin", "FontRendererAccessor", "GuiInventoryMixin", "RenderAccessor",