Skip to content

Commit

Permalink
something
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Feb 3, 2025
1 parent 6320858 commit dbb02c6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 31 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ toolkitLoomHelper {
}
}

useDevAuth("1.2.1")

// Turns off the server-side run configs, as we're building a client-sided mod.
disableRunConfigs(GameSide.SERVER)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import org.polyfrost.polynametag.NametagRenderer;
import org.polyfrost.polynametag.PolyNametagConfig;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(Render.class)
public class Mixin_Render_ReplaceRendering<T extends Entity> {
Expand All @@ -28,7 +26,7 @@ public class Mixin_Render_ReplaceRendering<T extends Entity> {
return original.call(instance, text, x, y, color);
}

return NametagRenderer.drawStringWithoutZFighting(instance, text, x, y, color);
return NametagRenderer.drawNametagString(instance, text, x, y, color);
}

@Inject(method = "renderLivingLabel", at = @At("HEAD"), cancellable = true)
Expand All @@ -38,6 +36,18 @@ public class Mixin_Render_ReplaceRendering<T extends Entity> {
}
}

@ModifyArgs(method = "renderLivingLabel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"))
private void polyNametag$changeScale(Args args) {
if (!PolyNametagConfig.INSTANCE.getEnabled()) {
return;
}

double scale = PolyNametagConfig.INSTANCE.getScale();
args.set(0, ((double) args.get(0)) * scale);
args.set(1, ((double) args.get(1)) * scale);
args.set(2, ((double) args.get(2)) * scale);
}

@Inject(method = "renderLivingLabel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()V"))
private void polynametag$replaceDefaultBackgroundRendering(T entity, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) {
if (!PolyNametagConfig.INSTANCE.getEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import org.polyfrost.polynametag.NametagRenderer;
import org.polyfrost.polynametag.PolyNametagConfig;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(RendererLivingEntity.class)
public class Mixin_RendererLivingEntity_ReplaceRendering<T extends EntityLivingBase> {
Expand All @@ -28,7 +26,7 @@ public class Mixin_RendererLivingEntity_ReplaceRendering<T extends EntityLivingB
return original.call(instance, text, x, y, color);
}

return NametagRenderer.drawStringWithoutZFighting(instance, text, x, y, color);
return NametagRenderer.drawNametagString(instance, text, x, y, color);
}

@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true)
Expand All @@ -38,6 +36,18 @@ public class Mixin_RendererLivingEntity_ReplaceRendering<T extends EntityLivingB
}
}

@ModifyArgs(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"))
private void polyNametag$changeScale(Args args) {
if (!PolyNametagConfig.INSTANCE.getEnabled()) {
return;
}

double scale = PolyNametagConfig.INSTANCE.getScale();
args.set(0, ((double) args.get(0)) * scale);
args.set(1, ((double) args.get(1)) * scale);
args.set(2, ((double) args.get(2)) * scale);
}

@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()V"))
private void polynametag$replaceDefaultBackgroundRendering(T entity, double x, double y, double z, CallbackInfo ci) {
if (!PolyNametagConfig.INSTANCE.getEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class Mixin_AboveHeadRender_FixLevelheadRendering {
return original.call(instance);
}

return NametagRenderer.drawStringWithoutZFighting(text, x, y, color);
return NametagRenderer.drawNametagString(text, x, y, color);
}

@Dynamic("Levelhead")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class Mixin_NameTagRenderingHooks_OverwriteNametagTextRendering
return;
}

cir.setReturnValue(NametagRenderer.drawStringWithoutZFighting(fontRenderer, text, x, y, color));
cir.setReturnValue(NametagRenderer.drawNametagString(fontRenderer, text, x, y, color));
}

}
17 changes: 8 additions & 9 deletions src/main/kotlin/org/polyfrost/polynametag/NametagRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ object NametagRenderer {
private val essentialBSManager = EssentialBSManager()

@JvmStatic
fun drawStringWithoutZFighting(fontRenderer: FontRenderer, text: String, x: Float, y: Float, color: Int): Int {
fun drawNametagString(fontRenderer: FontRenderer, text: String, x: Float, y: Float, color: Int): Int {
if (fontRenderer !is Accessor_FontRenderer_DrawString) {
return 0
}

UGraphics.GL.pushMatrix()
UGraphics.GL.translate(0f, 0f, -0.01f)
return when (PolyNametagConfig.textType) {
return when (PolyNametagConfig.textType) { //TODO FULL SHADOW
0 -> fontRenderer.invokeRenderString(text, x, y, color, false)
1 -> fontRenderer.invokeRenderString(text, x, y, color, true)
else -> 0
Expand All @@ -39,8 +38,8 @@ object NametagRenderer {
}

@JvmStatic
fun drawStringWithoutZFighting(text: String, x: Float, y: Float, color: Int): Int {
return drawStringWithoutZFighting(mc.fontRendererObj, text, x, y, color)
fun drawNametagString(text: String, x: Float, y: Float, color: Int): Int {
return drawNametagString(mc.fontRendererObj, text, x, y, color)
}

@JvmStatic
Expand All @@ -53,22 +52,22 @@ object NametagRenderer {
UGraphics.disableTexture2D()
GL11.glPushMatrix()
val realX1 = x1 - if (canDrawEssentialIndicator(entity)) 10 else 0
GL11.glTranslated((realX1 + x2) / 2f, 3.5, 0.01)
GL11.glTranslated((realX1 + x2) / 2f, 3.5, 0.0)
GL11.glBegin(GL11.GL_TRIANGLE_FAN)
with(PolyNametagConfig.backgroundColor) {
GL11.glColor4f(r / 255f, g / 255f, b / 255f, a.coerceAtMost(63) / 255f)
}

val halfWidth = (x2 - realX1) / 2f + PolyNametagConfig.paddingX
val radius = if (PolyNametagConfig.rounded) PolyNametagConfig.cornerRadius.coerceAtMost(4.5f + PolyNametagConfig.paddingY).coerceAtMost(halfWidth.toFloat()) else 0f
val halfWidth = (x2 - realX1) / 2f + PolyNametagConfig.paddingX.coerceIn(0f, 10f)
val radius = if (PolyNametagConfig.rounded) PolyNametagConfig.cornerRadius.coerceIn(0f, 10f).coerceAtMost(4.5f + PolyNametagConfig.paddingY.coerceIn(0f, 10f)).coerceAtMost(halfWidth.toFloat()) else 0f
val width = halfWidth - radius
val distanceFromPlayer = entity.getDistanceToEntity(mc.thePlayer)
val quality = ((distanceFromPlayer * 4 + 10).coerceAtMost(350f) / 4f).toInt()
for (a in 0..3) {
val (transX, transY) = translate[a]
val (pointX, pointY) = points[a]
val x = pointX * width
val y = pointY * (4.5 + PolyNametagConfig.paddingY - radius)
val y = pointY * (4.5 + PolyNametagConfig.paddingY.coerceIn(0f, 10f) - radius)
if (PolyNametagConfig.rounded) {
for (b in 0 until 90 / quality) {
val angle = Math.toRadians((a * 90 + b * quality).toDouble())
Expand Down
11 changes: 1 addition & 10 deletions src/main/kotlin/org/polyfrost/polynametag/PolyNametagConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@ object PolyNametagConfig : Config("nametag.json", "/polynametag.svg", PolyNameta
get() = field.coerceIn(-0.5f, 0.5f)

@Slider(title = "Scale", min = 0f, max = 1f, description = "How much to scale the nametag")
var scale = 1f
var scale = 1f //todo
get() = field.coerceIn(0f, 1f)

@Switch(title = "Rounded Corners")
var rounded = false

@Slider(title = "Corner Radius", min = 0f, max = 10f)
var cornerRadius = 0f
get() = field.coerceIn(0f, 10f)

@Slider(title = "Padding X", min = 0f, max = 10f)
var paddingX = 0f
get() = field.coerceIn(0f, 10f)

@Slider(title = "Padding Y", min = 0f, max = 10f)
var paddingY = 0f
get() = field.coerceIn(0f, 10f)

@Dropdown(title = "Text Type", options = ["No Shadow", "Shadow", "Full Shadow"], description = "The type of shadow to render")
var textType = 0
Expand All @@ -62,9 +59,6 @@ object PolyNametagConfig : Config("nametag.json", "/polynametag.svg", PolyNameta
@Color(title = "Background color", description = "The color of the background")
var backgroundColor = rgba(0, 0, 0, 0.247F) // 0,0,0,63

@Switch(title = "Offset Essential Indicator", description = "Offset nametag to center if the player has essential indicator drawn")
var essentialOffset = true

/*
@CustomOption
@Transient
Expand Down Expand Up @@ -92,9 +86,6 @@ object PolyNametagConfig : Config("nametag.json", "/polynametag.svg", PolyNameta
addDependency("cornerRadius", "rounded")
addDependency("showInInventory", "showOwnNametag")

// TODO
//hideIf("essentialOffset") { !PolyNametag.isEssential }

if (!hasMigratedPatcher) {
try {
Class.forName("club.sk1er.patcher.config.OldPatcherConfig")
Expand Down

0 comments on commit dbb02c6

Please sign in to comment.