Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix nametag background alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev committed Aug 5, 2024
1 parent 1877227 commit 0e75608
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.gradle.parallel=true
polyfrost.defaults.loom=3

# Mod Properties
mod_version=1.3.2
mod_version=1.3.3
maven_group=dev.microcontrollers.nametagtweaks
archives_base_name=nametagtweaks
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
package dev.microcontrollers.nametagtweaks.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
//#if MC <= 1.20.6
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
//$$ import dev.microcontrollers.nametagtweaks.NametagShadowFix;
//#endif
import com.llamalad7.mixinextras.sugar.Local;
import dev.microcontrollers.nametagtweaks.config.NametagTweaksConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
//#if MC <= 1.20.6
//$$ import org.joml.Matrix4f;
//#endif
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin<T extends Entity> {
@Shadow @Final private TextRenderer textRenderer;

@Inject(method = "renderLabelIfPresent", at = @At("HEAD"), cancellable = true)
//#if MC >= 1.20.6
public void hideNametags(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) {
Expand All @@ -39,7 +37,7 @@ public void hideNametags(T entity, Text text, MatrixStack matrices, VertexConsum
ci.cancel();
}

@Inject(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I", shift = At.Shift.BEFORE, ordinal = 0))
@Inject(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I", ordinal = 0))
//#if MC >= 1.20.6
public void nametagScale(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) {
//#else
Expand All @@ -57,7 +55,7 @@ public float changeNametagHeight(float y) {
//#if MC <= 1.20.6
//$$ @WrapOperation(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I"))
//$$ private int addNametagShadow(TextRenderer instance, Text text, float x, float y, int color, boolean shadow, Matrix4f matrix, VertexConsumerProvider vertexConsumers, TextRenderer.TextLayerType layerType, int backgroundColor, int light, Operation<Integer> original) {
//$$ if (NametagTweaksConfig.CONFIG.instance().nametagTextShadow) ((NametagShadowFix) textRenderer).nametagTweaks$drawNametagShadow(text.asOrderedText(), x, y, color, true, matrix, vertexConsumers, layerType, backgroundColor, light);
//$$ if (NametagTweaksConfig.CONFIG.instance().nametagTextShadow) ((NametagShadowFix) instance).nametagTweaks$drawNametagShadow(text.asOrderedText(), x, y, color, true, matrix, vertexConsumers, layerType, backgroundColor, light);
//$$ return original.call(instance, text, x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light);
//$$ }
//#endif
Expand All @@ -70,8 +68,10 @@ public boolean addNametagShadow(boolean shadow) {
//#endif

@ModifyArg(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I", ordinal = 0), index = 8)
public int changeNametagBackground(int color) {
public int changeNametagBackground(int color, @Local(ordinal = 0) boolean standing) {
if (!standing && NametagTweaksConfig.CONFIG.instance().nametagColor.getAlpha() > 0x20) { // if sneaking
return (0x20 << 24) | (NametagTweaksConfig.CONFIG.instance().nametagColor.getRGB() & 0x00FFFFFF);
}
return NametagTweaksConfig.CONFIG.instance().nametagColor.getRGB();
}

}

0 comments on commit 0e75608

Please sign in to comment.