From 5621a2880d4ae99a05679736d9a11af1ef294439 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 15:23:03 +0530 Subject: [PATCH] WIP: Experimental patches for 1.21.2/1.21.3 # Conflicts: # src/main/java/net/torocraft/torohealth/display/BarDisplay.java --- .../torohealth/display/BarDisplay.java | 10 +++++---- .../torohealth/display/EntityDisplay.java | 21 +++++++------------ .../net/torocraft/torohealth/display/Hud.java | 5 +++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index cd8909d..ed44572 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -30,8 +31,9 @@ public void draw(DrawContext drawContext, LivingEntity entity) { RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX); RenderSystem.enableBlend(); - HealthBarRenderer.render(drawContext.getMatrices(), drawContext.getVertexConsumers(), entity, 63, 14, 130, false); - drawContext.draw(); + drawContext.draw(vertexConsumerProvider -> { + HealthBarRenderer.render(drawContext.getMatrices(), vertexConsumerProvider, entity, 63, 14, 130, false); + }); String name = getEntityName(entity); int healthMax = MathHelper.ceil(entity.getMaxHealth()); int healthCur = Math.min(MathHelper.ceil(entity.getHealth()), healthMax); @@ -59,10 +61,10 @@ public void draw(DrawContext drawContext, LivingEntity entity) { } private void renderArmorIcon(DrawContext drawContext, int x, int y) { - drawContext.drawGuiTexture(ARMOR_TEXTURE, x, y, 9, 9); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, ARMOR_TEXTURE, x, y, 9, 9); } private void renderHeartIcon(DrawContext drawContext, int x, int y) { - drawContext.drawGuiTexture(HEART_TEXTURE, x, y, 9, 9); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, HEART_TEXTURE, x, y, 9, 9); } } diff --git a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java index 67912e2..03d45ee 100644 --- a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java @@ -2,8 +2,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.DiffuseLighting; -import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; @@ -33,10 +33,10 @@ public void setEntity(LivingEntity entity) { updateScale(); } - public void draw(MatrixStack matrix, float scale) { + public void draw(DrawContext drawContext, MatrixStack matrix, float scale) { if (entity != null) { try { - drawEntity(matrix, (int) xOffset, (int) yOffset, entityScale, -80, -20, entity, scale); + drawEntity(drawContext, matrix, (int) xOffset, (int) yOffset, entityScale, -80, -20, entity, scale); } catch (Exception e) { e.printStackTrace(); } @@ -71,15 +71,14 @@ private void updateScale() { /** * copied from InventoryScreen.drawEntity() to expose the matrixStack */ - public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, float mouseX, - float mouseY, LivingEntity entity, float scale) { + public static void drawEntity(DrawContext drawContext, MatrixStack matrixStack2, int x, int y, int size, + float mouseX, float mouseY, LivingEntity entity, float scale) { float f = (float) Math.atan((double) (mouseX / 40.0F)); float g = (float) Math.atan((double) (mouseY / 40.0F)); Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); matrixStack.pushMatrix(); matrixStack.translate(x * scale, y * scale, 1050.0F * scale); matrixStack.scale(1.0F, 1.0F, -1.0F); - RenderSystem.applyModelViewMatrix(); matrixStack2.push(); matrixStack2.translate(0.0D, 0.0D, 1000.0D); matrixStack2.scale((float) size, (float) size, (float) size); @@ -102,13 +101,10 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, quaternion2.conjugate(); entityRenderDispatcher.setRotation(quaternion2); entityRenderDispatcher.setRenderShadows(false); - VertexConsumerProvider.Immediate immediate = - MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(); - RenderSystem.runAsFancy(() -> { - entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, matrixStack2, immediate, - 15728880); + drawContext.draw(vertexConsumerProvider -> { + entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 1.0F, matrixStack2, + vertexConsumerProvider, 15728880); }); - immediate.draw(); entityRenderDispatcher.setRenderShadows(true); entity.bodyYaw = h; entity.setYaw(i); @@ -117,7 +113,6 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, entity.headYaw = l; matrixStack.popMatrix(); matrixStack2.pop(); - RenderSystem.applyModelViewMatrix(); DiffuseLighting.enableGuiDepthLighting(); } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index 69eccb5..1d6ef9e 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.text.*; @@ -117,7 +118,7 @@ private void draw(DrawContext drawContext, float x, float y, float scale) { } matrix.translate(10, 10, 0); if (config.hud.showEntity) { - entityDisplay.draw(matrix, scale); + entityDisplay.draw(drawContext, matrix, scale); } matrix.translate(44, 0, 0); if (config.hud.showBar) { @@ -129,6 +130,6 @@ private void draw(DrawContext drawContext, float x, float y, float scale) { private void drawSkin(DrawContext drawContext) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int w = 160, h = 60; - drawContext.drawTexture(BACKGROUND_TEXTURE, 0, 0, 0.0f, 0.0f, w, h, w, h); + drawContext.drawTexture(RenderLayer::getGuiTextured, BACKGROUND_TEXTURE, 0, 0, 0.0f, 0.0f, w, h, w, h); } }