diff --git a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java index 8bedd4e..08d88d1 100644 --- a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java +++ b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java @@ -2,6 +2,7 @@ import at.ridgo8.moreoverlays.MoreOverlays; import at.ridgo8.moreoverlays.config.Config; +import at.ridgo8.moreoverlays.lightoverlay.LightOverlayHandler; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import org.joml.Matrix4f; @@ -11,6 +12,7 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; +import org.joml.Quaternionf; import static net.minecraft.client.CameraType.THIRD_PERSON_FRONT; @@ -31,6 +33,8 @@ public static void renderOverlays(PoseStack matrixstack) { RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth.get()); RenderSystem.setShader(GameRenderer::getPositionColorShader); + Quaternionf cameraRotation = Minecraft.getInstance().gameRenderer.getMainCamera().rotation(); + if (Minecraft.getInstance().options.graphicsMode().get() != GraphicsStatus.FABULOUS) { // Use old renderer RenderSystem.depthMask(false); @@ -38,6 +42,12 @@ public static void renderOverlays(PoseStack matrixstack) { } else { // Use new renderer matrixstack.pushPose(); + + // Rotate yaw by 180 degrees. + cameraRotation.rotateY((float) Math.toRadians(180 % 360)); + Matrix4f translateMatrix = new Matrix4f().rotation(cameraRotation); + + matrixstack.mulPoseMatrix(translateMatrix); } @@ -116,6 +126,14 @@ public static void renderOverlays(PoseStack matrixstack) { RenderSystem.lineWidth(1.0F); RenderSystem.enableBlend(); + if(!LightOverlayHandler.isEnabled()) { + // Rotate yaw by 180 degrees. + cameraRotation.rotateY((float) Math.toRadians(-180 % 360)); + Matrix4f translateMatrix = new Matrix4f().rotation(cameraRotation); + + matrixstack.mulPoseMatrix(translateMatrix); + } + matrixstack.popPose(); } } diff --git a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java index 7961dfc..5d7a8a8 100644 --- a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java +++ b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java @@ -3,6 +3,7 @@ import at.ridgo8.moreoverlays.MoreOverlays; import at.ridgo8.moreoverlays.api.lightoverlay.ILightRenderer; import at.ridgo8.moreoverlays.api.lightoverlay.ILightScanner; +import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsHandler; import at.ridgo8.moreoverlays.config.Config; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; @@ -17,6 +18,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import org.apache.commons.lang3.tuple.Pair; +import org.joml.Quaternionf; + import static net.minecraft.client.CameraType.THIRD_PERSON_FRONT; @@ -95,6 +98,8 @@ public void renderOverlays(ILightScanner scanner, PoseStack matrixstack) { RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth.get()); RenderSystem.setShader(GameRenderer::getPositionColorShader); + Quaternionf cameraRotation = Minecraft.getInstance().gameRenderer.getMainCamera().rotation(); + if (Minecraft.getInstance().options.graphicsMode().get() != GraphicsStatus.FABULOUS) { // Use old renderer RenderSystem.depthMask(false); @@ -102,6 +107,14 @@ public void renderOverlays(ILightScanner scanner, PoseStack matrixstack) { } else { // Use new renderer matrixstack.pushPose(); + + // Only rotate when pose is not already rotated by ChunkBoundsRenderer + if(ChunkBoundsHandler.getMode() == ChunkBoundsHandler.RenderMode.NONE) { + // Rotate yaw by 180 degrees. + cameraRotation.rotateY((float) Math.toRadians(180 % 360)); + } + Matrix4f translateMatrix = new Matrix4f().rotation(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); } float ar = ((float) ((Config.render_spawnAColor.get() >> 16) & 0xFF)) / 255F; @@ -132,6 +145,14 @@ else if (mode == 2) RenderSystem.lineWidth(1.0F); RenderSystem.enableBlend(); + // Only rotate when pose is not already rotated by ChunkBoundsRenderer + if(ChunkBoundsHandler.getMode() == ChunkBoundsHandler.RenderMode.NONE) { + // Rotate yaw by 180 degrees. + cameraRotation.rotateY((float) Math.toRadians(-180 % 360)); + } + Matrix4f translateMatrix = new Matrix4f().rotation(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); + matrixstack.popPose(); } }