diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java index 50690f5..510dad3 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java @@ -73,6 +73,7 @@ public abstract class RenderMixin { ) private void polyNametag$drawBackground(Entity entity, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; + NametagRenderingKt.setDrawingWithDepth(true); NametagRenderingKt.drawFrontBackground(str, entity); } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java index f60984b..bc90538 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java @@ -16,8 +16,6 @@ import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import static org.polyfrost.polynametag.render.NametagRenderingKt.drawFrontBackground; - @Mixin(value = RendererLivingEntity.class, priority = 1001) public abstract class RendererLivingEntityMixin { @@ -94,7 +92,7 @@ private void cancel(EntityLivingBase entity, double x, double y, double z, Callb private void drawBG(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; if (PolyNametag.INSTANCE.getShouldDrawIndicator() && ModConfig.INSTANCE.getEssentialOffset()) GlStateManager.translate(5f, 0f, 0f); - drawFrontBackground(entity.getDisplayName().getFormattedText(), NametagRenderingKt.getBackBackgroundGLColorOrEmpty(), entity); + NametagRenderingKt.drawFrontBackground(entity.getDisplayName().getFormattedText(), NametagRenderingKt.getBackBackgroundGLColorOrEmpty(), entity); } @Redirect( 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 23ca21e..11d3132 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/levelhead/AboveHeadRenderMixin.java @@ -63,6 +63,7 @@ private void drawBG(LevelheadTag tag, EntityPlayer entityIn, double x, double y, int stringWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(tag.getString()) / 2; NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, NametagRenderingKt.getBackBackgroundGLColorOrEmpty(), entityIn); GlStateManager.enableDepth(); + NametagRenderingKt.setDrawingWithDepth(true); NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, entityIn); GlStateManager.depthMask(true); } diff --git a/src/main/kotlin/org/polyfrost/polynametag/render/NametagRendering.kt b/src/main/kotlin/org/polyfrost/polynametag/render/NametagRendering.kt index c2229bf..595fc5e 100644 --- a/src/main/kotlin/org/polyfrost/polynametag/render/NametagRendering.kt +++ b/src/main/kotlin/org/polyfrost/polynametag/render/NametagRendering.kt @@ -25,13 +25,15 @@ import kotlin.math.sin var drawingText = false +var drawingWithDepth = false + internal fun shouldDrawBackground() = ModConfig.background && (!PolyNametag.isPatcher || !PatcherConfig.disableNametagBoxes) val NO_COLOR = Color(0f, 0f, 0f, 0f) fun getBackBackgroundGLColorOrEmpty(): Color = if (shouldDrawBackground()) with(ModConfig.backgroundColor) { - Color(red, green, blue, alpha.coerceAtMost(0x3F)) + Color(red, green, blue, alpha.coerceAtMost(63)) } else { NO_COLOR } @@ -68,12 +70,17 @@ fun drawBackground(xStart: Double, xEnd: Double, color: Color, entity: Entity) { GL11.glTranslated((realStart + xEnd) / 2f, 3.5, 0.01) GL11.glBegin(GL11.GL_TRIANGLE_FAN) with(color) { - GL11.glColor4f(red / 255f, green / 255f, blue / 255f, alpha / 255f) + val a = alpha.coerceAtMost(63) + val realAlpha = if (drawingWithDepth) (alpha - a) / (255 - a).toFloat() else alpha / 255f + GL11.glColor4f(red / 255f, green / 255f, blue / 255f, realAlpha) } + drawingWithDepth = false + + val halfWidth = (xEnd - realStart) / 2f + ModConfig.paddingX - val radius = if (ModConfig.rounded) ModConfig.cornerRadius.coerceAtMost(4.5f + ModConfig.paddingY) else 0f + val radius = if (ModConfig.rounded) ModConfig.cornerRadius.coerceAtMost(4.5f + ModConfig.paddingY).coerceAtMost(halfWidth.toFloat()) else 0f - val width = (xEnd - realStart) / 2f + ModConfig.paddingX - radius + val width = halfWidth - radius val distanceFromPlayer = entity.getDistanceToEntity(mc.thePlayer) val quality = ((distanceFromPlayer * 4 + 10).coerceAtMost(350f) / 4).toInt()