Skip to content

Commit

Permalink
fixed self nametag not showing in F1
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jun 28, 2024
1 parent 437bb67 commit b04c433
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.polyfrost.polynametag.mixin;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import org.polyfrost.polynametag.render.NametagRenderingKt;
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;

@Mixin(FontRenderer.class)
public class FontRendererMixin {

@Inject(method = "drawString(Ljava/lang/String;FFIZ)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;renderString(Ljava/lang/String;FFIZ)I", ordinal = 1))
private void translate(String text, float x, float y, int color, boolean dropShadow, CallbackInfoReturnable<Integer> cir) {
if (NametagRenderingKt.getDrawingText()) GlStateManager.translate(0f, 0f, -0.01f);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.polyfrost.polynametag.config.ModConfig;
import org.polyfrost.polynametag.render.NametagRenderingKt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

Expand All @@ -22,6 +23,18 @@
@Mixin(value = RendererLivingEntity.class, priority = 1001)
public abstract class RendererLivingEntityMixin {

@Unique
private boolean shouldShowOwnNametag;

@Redirect(
method = "canRenderName(Lnet/minecraft/entity/EntityLivingBase;)Z",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;isGuiEnabled()Z")
)
private boolean gui() {
shouldShowOwnNametag = ((ModConfig.INSTANCE.enabled && ModConfig.INSTANCE.getShowOwnNametag() && (ModConfig.INSTANCE.getShowInInventory() || !PolyNametag.INSTANCE.getDrawingInventory()) && (!PolyNametag.INSTANCE.getDrawingWorld() || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0)) || ModConfig.INSTANCE.getNametagPreview().getDrawing());
return shouldShowOwnNametag || Minecraft.isGuiEnabled();
}

@Redirect(
method = "canRenderName(Lnet/minecraft/entity/EntityLivingBase;)Z",
at = @At(
Expand All @@ -30,7 +43,6 @@ public abstract class RendererLivingEntityMixin {
)
)
private Entity polyNametag$cancelSelfCheck(RenderManager renderManager) {
boolean shouldShowOwnNametag = ((ModConfig.INSTANCE.enabled && ModConfig.INSTANCE.getShowOwnNametag() && (ModConfig.INSTANCE.getShowInInventory() || !PolyNametag.INSTANCE.getDrawingInventory()) && (!PolyNametag.INSTANCE.getDrawingWorld() || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0)) || ModConfig.INSTANCE.getNametagPreview().getDrawing());
return shouldShowOwnNametag ? null : renderManager.livingPlayer;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.polyfrost.polynametag.render

import cc.polyfrost.oneconfig.renderer.TextRenderer
import cc.polyfrost.oneconfig.utils.dsl.getAlpha
import cc.polyfrost.oneconfig.utils.dsl.mc
import club.sk1er.patcher.config.PatcherConfig
import gg.essential.Essential
Expand All @@ -17,11 +19,10 @@ import org.polyfrost.polynametag.PolyNametag
import org.polyfrost.polynametag.config.ModConfig
import org.polyfrost.polynametag.mixin.FontRendererAccessor
import java.awt.Color
import java.util.regex.Pattern
import kotlin.math.cos
import kotlin.math.max
import kotlin.math.sin
import net.minecraft.client.renderer.GlStateManager as GL

var drawingText = false

internal fun shouldDrawBackground() =
ModConfig.background && (!PolyNametag.isPatcher || !PatcherConfig.disableNametagBoxes)
Expand Down Expand Up @@ -98,28 +99,6 @@ fun drawBackground(xStart: Double, xEnd: Double, color: Color, entity: Entity) {
GL11.glDisable(GL11.GL_LINE_SMOOTH)
}

private val regex = Pattern.compile("(?i)\u00A7[0-9a-f]")
var isDrawingBorder = false
fun FontRenderer.drawBorderedText(text: String, x: Float, y: Float, opacity: Int): Int {
if (this !is FontRendererAccessor) return -1
val noColors = regex.matcher(text).replaceAll("\u00A7r")
var yes = 0
if (opacity / 4 > 3) {
for (xOff in -2..2) {
for (yOff in -2..2) {
if (xOff * xOff != yOff * yOff) {
yes = max(
invokeRenderString(
noColors, xOff / 2f + x, yOff / 2f + y, opacity / 4 shl 24, false
), yes
)
}
}
}
}
return yes
}

fun drawIndicator(entity: Entity, string: String) {
if (entity !is EntityPlayer) return
OnlineIndicator.drawNametagIndicator(UMatrixStack(), entity, string, 0)
Expand All @@ -135,45 +114,18 @@ fun Entity.canDrawIndicator(): Boolean {
return false
}

internal fun FontRenderer.drawStringWithoutZFighting(text: String, x: Int, y: Float, color: Int): Int {
if (this !is FontRendererAccessor) return -1
GL.pushMatrix()
GL.translate(0f, 0f, -0.01f)

when (ModConfig.textType) {
0 -> {
val i = drawString(text, x.toFloat(), y, color, false)
GL.popMatrix()
return i
}

1 -> {
GL.enableAlpha()
invokeResetStyles()

val shadowX = invokeRenderString(text, x + 1f, y + 1f, color, true)
GL.translate(0f, 0f, -0.01f)
val normalX = drawString(text, x.toFloat(), y, color, false)
GL.popMatrix()

return max(shadowX, normalX)
}

2 -> {
GL.enableAlpha()
invokeResetStyles()

isDrawingBorder = true

val shadowX = drawBorderedText(text, x.toFloat(), y, 255)
GL.translate(0f, 0f, -0.01f)
val normalX = drawString(text, x.toFloat(), y, color, false)

isDrawingBorder = false
GL.popMatrix()

return max(shadowX, normalX)
}
internal fun FontRenderer.drawStringWithoutZFighting(text: String, x: Float, y: Float, color: Int): Int {
if (this !is FontRendererAccessor) return 0
GlStateManager.pushMatrix()
GlStateManager.translate(0f, 0f, -0.01f)
drawingText = true
return when (ModConfig.textType) {
0 -> drawString(text, x, y, color, false)
1 -> drawString(text, x, y, color, true)
2 -> TextRenderer.drawBorderedText(text, x, y, color, color.getAlpha())
else -> 0
}.apply {
drawingText = false
GlStateManager.popMatrix()
}
return -1
}
2 changes: 1 addition & 1 deletion src/main/resources/mixins.polynametag.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"client": [
"EntityRendererMixin",
"FontRendererAccessor",
"FontRendererMixin",
"GuiInventoryMixin",
"MinecraftAccessor",
"RenderAccessor",
Expand All @@ -17,7 +18,6 @@
"essential.OnlineIndicatorMixin",
"levelhead.AboveHeadRenderMixin",
"levelhead.AboveHeadRenderMixin_ModifyArgs",
"oneconfig.TextRendererMixin",
"patcher.NameTagRenderingHooksMixin"
],
"verbose": true
Expand Down

0 comments on commit b04c433

Please sign in to comment.