Skip to content

Commit

Permalink
WIP: Experimental patches for 1.21.2/1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Dec 5, 2024
1 parent 196a585 commit b3e8a04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +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(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);
Expand Down Expand Up @@ -58,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);
}
}
21 changes: 8 additions & 13 deletions src/main/java/net/torocraft/torohealth/display/EntityDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/torocraft/torohealth/display/Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}

0 comments on commit b3e8a04

Please sign in to comment.