Skip to content

Commit

Permalink
entities rendered through BER no longer render healthbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Sep 29, 2024
1 parent aef0686 commit e7e52b7
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
8 changes: 7 additions & 1 deletion NeoForge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java-library'
id 'idea'
id 'net.neoforged.gradle.userdev'
id 'net.neoforged.gradle.userdev' version '7.0.165'
id 'eclipse'
}

Expand All @@ -27,6 +27,12 @@ runs {
}
}

repositories {
maven {
url "https://cursemaven.com"
}
}

dependencies {
implementation "net.neoforged:neoforge:${neoforge_version}"
implementation project(":Xplat")
Expand Down
24 changes: 15 additions & 9 deletions Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.mojang.math.Axis;

import net.minecraft.ChatFormatting;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -208,15 +210,14 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity)
}

public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSource buffers,
Quaternionf cameraOrientation) {
Camera camera, EntityRenderer<? super Entity> entityRenderer,
float partialTicks, double x, double y, double z) {
final Minecraft mc = Minecraft.getInstance();

if (!(entity instanceof LivingEntity living)) {
return;
}

//This was previously mc.gameRenderer.getMainCamera().getEntity() but that caused an incompatibility with RealCamera
if (!shouldShowPlate(living, mc.cameraEntity)) {
if (!shouldShowPlate(living, camera.getEntity())) {
return;
}

Expand All @@ -232,16 +233,22 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
final float nameLen = mc.font.width(name) * textScale;
final float halfSize = Math.max(NeatConfig.instance.plateSize(), nameLen / 2.0F + 10.0F);

Vec3 vec3 = entityRenderer.getRenderOffset(entity, partialTicks);
double d2 = x + vec3.x();
double d3 = y + vec3.y();
double d0 = z + vec3.z();

poseStack.pushPose();
poseStack.translate(d2, d3, d0);
poseStack.translate(0, living.getBbHeight() + NeatConfig.instance.heightAbove(), 0);
poseStack.mulPose(cameraOrientation);
poseStack.mulPose(camera.rotation());
poseStack.mulPose(Axis.YP.rotationDegrees(180));

// Plate background, bars, and text operate with globalScale, but icons don't
poseStack.pushPose();
poseStack.scale(-globalScale, -globalScale, globalScale);

VertexConsumer builder = buffers.getBuffer(NeatRenderType.BAR_TEXTURE_TYPE);


// Background
if (NeatConfig.instance.drawBackground()) {
Expand All @@ -250,7 +257,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
if (!NeatConfig.instance.showEntityName()) {
bgHeight -= (int) 4F;
}

VertexConsumer builder = buffers.getBuffer(NeatRenderType.BAR_TEXTURE_TYPE);
builder.addVertex(poseStack.last().pose(), -halfSize - padding, -bgHeight, 0.01F).setColor(0, 0, 0, 60).setUv(0.0F, 0.0F).setLight(light);
builder.addVertex(poseStack.last().pose(), -halfSize - padding, barHeight + padding, 0.01F).setColor(0, 0, 0, 60).setUv(0.0F, 0.5F).setLight(light);
builder.addVertex(poseStack.last().pose(), halfSize + padding, barHeight + padding, 0.01F).setColor(0, 0, 0, 60).setUv(1.0F, 0.5F).setLight(light);
Expand All @@ -268,8 +275,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
float maxHealth = Math.max(living.getHealth(), living.getMaxHealth());
float healthHalfSize = halfSize * (living.getHealth() / maxHealth);

//VertexConsumer builder = buffers.getBuffer(NeatRenderType.BAR_TEXTURE_TYPE);
//VertexConsumer builder = buffers.getBuffer(RenderType.LINES);
VertexConsumer builder = buffers.getBuffer(NeatRenderType.BAR_TEXTURE_TYPE);
builder.addVertex(poseStack.last().pose(), -halfSize, 0, 0.001F).setColor(r, g, b, 127).setUv(0.0F, 0.75F).setLight(light);
builder.addVertex(poseStack.last().pose(), -halfSize, barHeight, 0.001F).setColor(r, g, b, 127).setUv(0.0F, 1.0F).setLight(light);
builder.addVertex(poseStack.last().pose(), -halfSize + 2 * healthHalfSize, barHeight, 0.001F).setColor(r, g, b, 127).setUv(1.0F, 1.0F).setLight(light);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.world.entity.Entity;

import org.joml.Quaternionf;
Expand Down Expand Up @@ -33,6 +34,6 @@ public abstract class EntityRenderDispatcherMixin {
)
)
private void neat_renderHealthBar(Entity entity, double worldX, double worldY, double worldZ, float entityYRot, float partialTicks, PoseStack poseStack, MultiBufferSource buffers, int light, CallbackInfo ci) {
HealthBarRenderer.hookRender(entity, poseStack, buffers, cameraOrientation());
//HealthBarRenderer.hookRender(entity, poseStack, buffers, cameraOrientation());
}
}
36 changes: 36 additions & 0 deletions Xplat/src/main/java/vazkii/neat/mixin/LevelRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package vazkii.neat.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Final;
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.callback.CallbackInfo;
import vazkii.neat.HealthBarRenderer;

@Mixin(LevelRenderer.class)
public class LevelRendererMixin {

@Shadow @Final private EntityRenderDispatcher entityRenderDispatcher;

/**
* This hooks right after the EntityRenderDispatcher
*
*/
@Inject(method = "renderEntity(Lnet/minecraft/world/entity/Entity;DDDFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderDispatcher;render(Lnet/minecraft/world/entity/Entity;DDDFFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V",
shift = At.Shift.AFTER))
private void neat_renderHealthBar(Entity entity, double camX, double camY, double camZ, float partialTick, PoseStack poseStack, MultiBufferSource buffers, CallbackInfo ci) {
double d0 = Mth.lerp(partialTick, entity.xOld, entity.getX());
double d1 = Mth.lerp(partialTick, entity.yOld, entity.getY());
double d2 = Mth.lerp(partialTick, entity.zOld, entity.getZ());
HealthBarRenderer.hookRender(entity, poseStack, buffers, entityRenderDispatcher.camera, entityRenderDispatcher.getRenderer(entity), partialTick, d0 - camX, d1 - camY, d2 - camZ);
}
}
2 changes: 1 addition & 1 deletion Xplat/src/main/resources/neat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
],
"client": [
"AccessorRenderType",
"EntityRenderDispatcherMixin",
"EntityRendererMixin",
"LevelRendererMixin",
"MinecraftMixin"
],
"injectors": {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

group=vazkii.neat
neoforge_version=21.1.1
neoforge_version=21.1.63
mod_id=neat
build_number=39
mod_name=Neat
Expand Down

0 comments on commit e7e52b7

Please sign in to comment.