Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions src/main/java/net/torocraft/torohealth/display/EntityDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.entity.passive.ChickenEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.Vec3f;

Expand All @@ -32,13 +33,17 @@ public void setEntity(LivingEntity entity) {
updateScale();
}

public void draw(MatrixStack matrix, float scale) {
public void draw(MatrixStack matrix, float tickDelta) {
if (entity != null) {
try {
drawEntity(matrix, (int) xOffset, (int) yOffset, entityScale, -80, -20, entity, scale);
} catch (Exception e) {
e.printStackTrace();
}
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix();
Matrix4f positionMatrix2 = matrix.peek().getPositionMatrix();
positionMatrix.multiply(positionMatrix2);
RenderSystem.applyModelViewMatrix();
drawEntity((int) xOffset, (int) yOffset, entityScale, -80, -20, entity, tickDelta);
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
}
}

Expand Down Expand Up @@ -70,32 +75,31 @@ 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) {
float f = (float) Math.atan((double) (mouseX / 40.0F));
float g = (float) Math.atan((double) (mouseY / 40.0F));
public static void drawEntity(int x, int y, int size, float mouseX,
float mouseY, LivingEntity entity, float tickDelta) {
float f = (float) Math.atan(mouseX / 40.0F);
float g = (float) Math.atan(mouseY / 40.0F);
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate((double) x * scale, (double) y * scale, 1050.0D * scale);
matrixStack.translate(x ,y ,1050.0D);
matrixStack.scale(1.0F, 1.0F, -1.0F);
RenderSystem.applyModelViewMatrix();
MatrixStack matrixStack2 = new MatrixStack();
matrixStack2.push();
matrixStack2.translate(0.0D, 0.0D, 1000.0D);
matrixStack2.scale((float) size, (float) size, (float) size);
Quaternion quaternion = Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0F);
Quaternion quaternion2 = Vec3f.POSITIVE_X.getDegreesQuaternion(g * 20.0F);
quaternion.hamiltonProduct(quaternion2);
matrixStack2.multiply(quaternion);
float h = entity.bodyYaw;
float i = entity.getYaw();
float j = entity.getPitch();
float k = entity.prevHeadYaw;
float l = entity.headYaw;
entity.bodyYaw = 180.0F + f * 20.0F;
entity.setYaw(180.0F + f * 40.0F);
entity.setPitch(-g * 20.0F);
entity.headYaw = entity.getYaw();
entity.prevHeadYaw = entity.getYaw();
float i = entity.bodyYaw;
float j = entity.prevBodyYaw;
float k = entity.headYaw;
float l = entity.prevHeadYaw;
entity.bodyYaw = 180.0f + f * 20.0f;
entity.prevBodyYaw = 180.0f + f * 20.0f;
entity.headYaw = 180.0f + f * 20.0f + k - i;
entity.prevHeadYaw = 180.0f + f * 20.0f + l - j;
DiffuseLighting.method_34742();
EntityRenderDispatcher entityRenderDispatcher =
MinecraftClient.getInstance().getEntityRenderDispatcher();
Expand All @@ -104,21 +108,15 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size,
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);
});
RenderSystem.runAsFancy(() -> entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 0.0f, tickDelta, matrixStack2, immediate, 0xF000F0));
immediate.draw();
entityRenderDispatcher.setRenderShadows(true);
entity.bodyYaw = h;
entity.setYaw(i);
entity.setPitch(j);
entity.prevHeadYaw = k;
entity.headYaw = l;
entity.bodyYaw = i;
entity.prevBodyYaw = j;
entity.headYaw = k;
entity.prevHeadYaw = l;
matrixStack.pop();
matrixStack2.pop();
RenderSystem.applyModelViewMatrix();
DiffuseLighting.enableGuiDepthLighting();
}

}
8 changes: 4 additions & 4 deletions src/main/java/net/torocraft/torohealth/display/Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Hud() {
barDisplay = new BarDisplay(MinecraftClient.getInstance(), this);
}

public void draw(MatrixStack matrix, Config config) {
public void draw(MatrixStack matrix, float tickDelta, Config config) {
if (this.client.options.debugEnabled) {
return;
}
Expand All @@ -36,7 +36,7 @@ public void draw(MatrixStack matrix, Config config) {
}
float x = determineX();
float y = determineY();
draw(matrix, x, y, config.hud.scale);
draw(matrix, x, y, config.hud.scale, tickDelta);
}

private float determineX() {
Expand Down Expand Up @@ -98,7 +98,7 @@ public LivingEntity getEntity() {
return entity;
}

private void draw(MatrixStack matrix, float x, float y, float scale) {
private void draw(MatrixStack matrix, float x, float y, float scale, float tickDelta) {
if (entity == null) {
return;
}
Expand All @@ -115,7 +115,7 @@ private void draw(MatrixStack matrix, float x, float y, float scale) {
}
matrix.translate(10, 10, 0);
if (config.hud.showEntity) {
entityDisplay.draw(matrix, scale);
entityDisplay.draw(matrix, tickDelta);
}
matrix.translate(44, 0, 0);
if (config.hud.showBar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public class InGameHudMixin {

@Inject(method = "render", at = @At("RETURN"))
private void render(MatrixStack matrixStack, float partial, CallbackInfo info) {
ToroHealth.HUD.draw(matrixStack, ToroHealth.CONFIG);
private void render(MatrixStack matrixStack, float tickDelta, CallbackInfo info) {
ToroHealth.HUD.draw(matrixStack, tickDelta, ToroHealth.CONFIG);
}

}