From e7e52b764bef77414e1c721b26c5854b660d5d35 Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Mon, 30 Sep 2024 01:39:09 +0200 Subject: [PATCH] entities rendered through BER no longer render healthbar --- NeoForge/build.gradle | 8 ++++- .../java/vazkii/neat/HealthBarRenderer.java | 24 ++++++++----- .../mixin/EntityRenderDispatcherMixin.java | 3 +- .../vazkii/neat/mixin/LevelRendererMixin.java | 36 +++++++++++++++++++ Xplat/src/main/resources/neat.mixins.json | 2 +- gradle.properties | 2 +- 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 Xplat/src/main/java/vazkii/neat/mixin/LevelRendererMixin.java diff --git a/NeoForge/build.gradle b/NeoForge/build.gradle index 64fc1ea..935ec9b 100644 --- a/NeoForge/build.gradle +++ b/NeoForge/build.gradle @@ -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' } @@ -27,6 +27,12 @@ runs { } } +repositories { + maven { + url "https://cursemaven.com" + } +} + dependencies { implementation "net.neoforged:neoforge:${neoforge_version}" implementation project(":Xplat") diff --git a/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java b/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java index c2695d1..8301f26 100644 --- a/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java +++ b/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java @@ -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; @@ -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 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; } @@ -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()) { @@ -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); @@ -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); diff --git a/Xplat/src/main/java/vazkii/neat/mixin/EntityRenderDispatcherMixin.java b/Xplat/src/main/java/vazkii/neat/mixin/EntityRenderDispatcherMixin.java index edb6599..0e195ec 100644 --- a/Xplat/src/main/java/vazkii/neat/mixin/EntityRenderDispatcherMixin.java +++ b/Xplat/src/main/java/vazkii/neat/mixin/EntityRenderDispatcherMixin.java @@ -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; @@ -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()); } } diff --git a/Xplat/src/main/java/vazkii/neat/mixin/LevelRendererMixin.java b/Xplat/src/main/java/vazkii/neat/mixin/LevelRendererMixin.java new file mode 100644 index 0000000..ff8809c --- /dev/null +++ b/Xplat/src/main/java/vazkii/neat/mixin/LevelRendererMixin.java @@ -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); + } +} diff --git a/Xplat/src/main/resources/neat.mixins.json b/Xplat/src/main/resources/neat.mixins.json index 8bad1fb..1081d02 100644 --- a/Xplat/src/main/resources/neat.mixins.json +++ b/Xplat/src/main/resources/neat.mixins.json @@ -7,8 +7,8 @@ ], "client": [ "AccessorRenderType", - "EntityRenderDispatcherMixin", "EntityRendererMixin", + "LevelRendererMixin", "MinecraftMixin" ], "injectors": { diff --git a/gradle.properties b/gradle.properties index 23378d0..f05ecb2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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