Skip to content

Commit

Permalink
Name tags get redder the more an entity is hurt
Browse files Browse the repository at this point in the history
  • Loading branch information
Arbee4ever committed May 8, 2022
1 parent 7b4c9ff commit 43145ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/net/arbee/addola/mixins/EntityRendererMixin.java
Original file line number Diff line number Diff line change
@@ -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<T extends Entity> {
@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();
}
}
Original file line number Diff line number Diff line change
@@ -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<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T> implements FeatureRendererContext<T, M> {
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));
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/addola.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"BoatEntityAccess",
"BoatEntityMixin",
"BoatItemAccess",
"EntityRendererMixin",
"LivingEntityRendererMixin",
"ServerWorldMixin",
"VillagerMixin"
],
Expand Down

1 comment on commit 43145ed

@Arbee4ever
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implements the feature described in #3

Please sign in to comment.