From 43145ed7d9e20c654e51405c27455f128dd93743 Mon Sep 17 00:00:00 2001 From: Arbee4ever Date: Mon, 9 May 2022 00:24:37 +0200 Subject: [PATCH] Name tags get redder the more an entity is hurt --- .../addola/mixins/EntityRendererMixin.java | 28 +++++++++++++++ .../mixins/LivingEntityRendererMixin.java | 34 +++++++++++++++++++ src/main/resources/addola.mixins.json | 2 ++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/net/arbee/addola/mixins/EntityRendererMixin.java create mode 100644 src/main/java/net/arbee/addola/mixins/LivingEntityRendererMixin.java diff --git a/src/main/java/net/arbee/addola/mixins/EntityRendererMixin.java b/src/main/java/net/arbee/addola/mixins/EntityRendererMixin.java new file mode 100644 index 0000000..9747265 --- /dev/null +++ b/src/main/java/net/arbee/addola/mixins/EntityRendererMixin.java @@ -0,0 +1,28 @@ +package net.arbee.addola.mixins; + +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.LivingEntity; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +import java.awt.*; + +@Mixin(EntityRenderer.class) +public abstract class EntityRendererMixin { + @ModifyArgs(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLnet/minecraft/util/math/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;ZII)I", ordinal = 1)) + public void draw (Args args, T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { + float healthPercent = ((LivingEntity)entity).getHealth() / ((LivingEntity)entity).getMaxHealth(); + args.set(3, getCol(healthPercent)); + } + + public int getCol(float percent) { + int p = (int)(255 * percent); + return new Color(255, p, p).hashCode(); + } +} \ No newline at end of file diff --git a/src/main/java/net/arbee/addola/mixins/LivingEntityRendererMixin.java b/src/main/java/net/arbee/addola/mixins/LivingEntityRendererMixin.java new file mode 100644 index 0000000..190fde3 --- /dev/null +++ b/src/main/java/net/arbee/addola/mixins/LivingEntityRendererMixin.java @@ -0,0 +1,34 @@ +package net.arbee.addola.mixins; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.LivingEntityRenderer; +import net.minecraft.client.render.entity.PlayerModelPart; +import net.minecraft.client.render.entity.feature.FeatureRendererContext; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.util.math.Vector3f; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Formatting; +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(LivingEntityRenderer.class) +public abstract class LivingEntityRendererMixin> extends EntityRenderer implements FeatureRendererContext { + protected LivingEntityRendererMixin(EntityRenderDispatcher dispatcher) { + super(dispatcher); + } + + @Inject(method = "setupTransforms", at = @At(value = "TAIL")) + protected void setupTransforms(T entity, MatrixStack matrices, float animationProgress, float bodyYaw, float tickDelta, CallbackInfo ci) { + if (entity.hasCustomName() || entity instanceof PlayerEntity) { + String string = Formatting.strip(entity.getName().getString()); + if ("guendahr".equals(string) && (!(entity instanceof PlayerEntity) || ((PlayerEntity)entity).isPartVisible(PlayerModelPart.CAPE))) { + matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180.0F)); + } + } + } +} diff --git a/src/main/resources/addola.mixins.json b/src/main/resources/addola.mixins.json index 91b4c1d..4ebd93b 100644 --- a/src/main/resources/addola.mixins.json +++ b/src/main/resources/addola.mixins.json @@ -8,6 +8,8 @@ "BoatEntityAccess", "BoatEntityMixin", "BoatItemAccess", + "EntityRendererMixin", + "LivingEntityRendererMixin", "ServerWorldMixin", "VillagerMixin" ],