diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java index e733c5fbed..feaad32821 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java @@ -75,7 +75,7 @@ public abstract class GameRendererMixin { private final MatrixStack matrices = new MatrixStack(); @Inject(method = "renderWorld", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = {"ldc=hand"})) - private void onRenderWorld(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 2) Matrix4f matrix4f3, @Local(ordinal = 1) float tickDelta, @Local MatrixStack matrixStack) { + private void onRenderWorld(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 0) Matrix4f projection, @Local(ordinal = 2) Matrix4f view, @Local(ordinal = 1) float tickDelta, @Local MatrixStack matrixStack) { if (!Utils.canUpdate()) return; Profilers.get().push(MeteorClient.MOD_ID + "_render"); @@ -87,12 +87,12 @@ private void onRenderWorld(RenderTickCounter tickCounter, CallbackInfo ci, @Loca // Call utility classes - RenderUtils.updateScreenCenter(); - NametagUtils.onRender(matrix4f3); + RenderUtils.updateScreenCenter(projection, view); + NametagUtils.onRender(view); // Update model view matrix - RenderSystem.getModelViewStack().pushMatrix().mul(matrix4f3); + RenderSystem.getModelViewStack().pushMatrix().mul(view); matrices.push(); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java index 869325d74e..e0a0257da8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java @@ -13,17 +13,13 @@ import meteordevelopment.meteorclient.utils.misc.Pool; import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.orbit.EventHandler; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; -import org.joml.Vector3f; +import org.joml.Matrix4f; +import org.joml.Vector4f; import java.util.ArrayList; import java.util.Iterator; @@ -65,38 +61,15 @@ public static void drawItem(DrawContext drawContext, ItemStack itemStack, int x, drawItem(drawContext, itemStack, x, y, scale, overlay, null); } - public static void updateScreenCenter() { - MinecraftClient mc = MinecraftClient.getInstance(); + public static void updateScreenCenter(Matrix4f projection, Matrix4f view) { + Matrix4f invProjection = new Matrix4f(projection).invert(); + Matrix4f invView = new Matrix4f(view).invert(); - Vector3f pos = new Vector3f(0, 0, 1); + Vector4f center4 = new Vector4f(0, 0, 0, 1).mul(invProjection).mul(invView); + center4.div(center4.w); - if (mc.options.getBobView().getValue()) { - MatrixStack bobViewMatrices = new MatrixStack(); - - bobView(bobViewMatrices); - pos.mulPosition(bobViewMatrices.peek().getPositionMatrix().invert()); - } - - center = new Vec3d(pos.x, -pos.y, pos.z) - .rotateX(-(float) Math.toRadians(mc.gameRenderer.getCamera().getPitch())) - .rotateY(-(float) Math.toRadians(mc.gameRenderer.getCamera().getYaw())) - .add(mc.gameRenderer.getCamera().getPos()); - } - - private static void bobView(MatrixStack matrices) { - Entity cameraEntity = MinecraftClient.getInstance().getCameraEntity(); - - if (cameraEntity instanceof AbstractClientPlayerEntity abstractClientPlayerEntity) { - float tickDelta = mc.getRenderTickCounter().getTickDelta(true); - - float var7 = abstractClientPlayerEntity.distanceMoved - abstractClientPlayerEntity.lastDistanceMoved; - float g = -(abstractClientPlayerEntity.distanceMoved + var7 * tickDelta); - float h = MathHelper.lerp(tickDelta, abstractClientPlayerEntity.prevStrideDistance, abstractClientPlayerEntity.strideDistance); - - matrices.translate(MathHelper.sin(g * (float) Math.PI) * h * 0.5F, -Math.abs(MathHelper.cos(g * (float) Math.PI) * h), 0.0F); - matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(MathHelper.sin(g * (float) Math.PI) * h * 3f)); - matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(Math.abs(MathHelper.cos(g * (float) Math.PI - 0.2f) * h) * 5f)); - } + Vec3d camera = mc.gameRenderer.getCamera().getPos(); + center = new Vec3d(camera.x + center4.x, camera.y + center4.y, camera.z + center4.z); } public static void renderTickingBlock(BlockPos blockPos, Color sideColor, Color lineColor, ShapeMode shapeMode, int excludeDir, int duration, boolean fade, boolean shrink) {