diff --git a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java index 1bb390ca..488777ba 100644 --- a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java @@ -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; @@ -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(); } } @@ -70,15 +75,16 @@ 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); @@ -86,16 +92,14 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, 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(); @@ -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(); } - } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index 39480daf..0d7fc593 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -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; } @@ -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() { @@ -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; } @@ -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) { diff --git a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java index 742bbb4f..a346ba85 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java @@ -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); } }