diff --git a/build.gradle b/build.gradle index d5ca7b0..607442f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,12 +6,16 @@ buildscript { } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true + // MixinGradle: + classpath 'org.spongepowered:mixingradle:0.7.+' } } apply plugin: 'net.minecraftforge.gradle' // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. apply plugin: 'eclipse' apply plugin: 'maven-publish' +// MixinGradle: +apply plugin: 'org.spongepowered.mixin' version = '1.20.5-mc1.18' group = 'at.ridgo8.moreoverlays' // http://maven.apache.org/guides/mini/guide-naming-conventions.html @@ -34,7 +38,7 @@ minecraft { // Use non-default mappings at your own risk. They may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. mappings channel: 'official', version: '1.18.1' - + // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default. // Default run configurations. @@ -54,6 +58,7 @@ minecraft { // You can set various levels here. // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels property 'forge.logging.console.level', 'debug' + arg "-mixin.config=moreoverlays.mixin.json" mods { moreoverlays { @@ -129,10 +134,13 @@ dependencies { implementation fg.deobf("mezz.jei:jei-${jei_version}") //runtimeOnly fg.deobf("mezz.jei:jei-${jei_version}") - + implementation fg.deobf("slimeknights.mantle:Mantle:${mantle_version}") //provided files("libs/CustomMobSpawner-3.11.4.jar") + // Apply Mixin AP + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' + // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" // compile "some.group:artifact:version" @@ -153,6 +161,11 @@ dependencies { } +//This is the better way to define the Mixin refmap name +mixin { + add sourceSets.main, "moreoverlays.mixin-refmap.json" +} + // Example for how to get properties into the manifest for reading by the runtime.. jar { manifest { @@ -163,9 +176,14 @@ jar { "Implementation-Title" : project.name, "Implementation-Version" : "${version}", "Implementation-Vendor" : "ridgo8", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + "TweakClass": "org.spongepowered.asm.launch.MixinTweaker", + "TweakOrder": 0, + "MixinConfigs" : "moreoverlays.mixin.json" ]) } + +// rename 'mixin.refmap.json', 'moreoverlays.mixin-refmap.json' } // Example configuration to allow publishing using the maven-publish task diff --git a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsHandler.java b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsHandler.java index 9002648..17bf650 100644 --- a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsHandler.java +++ b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsHandler.java @@ -1,5 +1,6 @@ package at.ridgo8.moreoverlays.chunkbounds; +import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; import net.minecraft.world.entity.player.Player; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -47,7 +48,7 @@ public static void toggleMode() { @SubscribeEvent public void renderWorldLastEvent(RenderLevelLastEvent event) { - if (mode != RenderMode.NONE) { + if (mode != RenderMode.NONE && Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { ChunkBoundsRenderer.renderOverlays(event.getPoseStack()); } } diff --git a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java index 479f443..a24772f 100644 --- a/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java +++ b/src/main/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java @@ -2,10 +2,14 @@ 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 com.mojang.math.Matrix4f; +import com.mojang.math.Quaternion; +import com.mojang.math.Vector3f; import net.minecraft.client.Camera; +import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; @@ -25,28 +29,28 @@ public static void renderOverlays(PoseStack matrixstack) { } Minecraft.getInstance().getTextureManager().bindForSetup(BLANK_TEX); -// if (Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { + RenderSystem.enableDepthTest(); RenderSystem.disableTexture(); RenderSystem.disableBlend(); - - RenderSystem.depthMask(false); - - RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth.get()); + RenderSystem.setShader(GameRenderer::getPositionColorShader); + + Quaternion cameraRotation = Minecraft.getInstance().gameRenderer.getMainCamera().rotation(); - RenderSystem.enableCull(); + if (Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { + // Use old renderer + RenderSystem.depthMask(false); + RenderSystem.enableCull(); + } else { + // Use new renderer + matrixstack.pushPose(); -// } else { -// RenderSystem.setShader(GameRenderer::getPositionColorShader); -// RenderSystem.disableTexture(); -// RenderSystem.enableBlend(); -// RenderSystem.defaultBlendFunc(); -// -// RenderSystem.bindTexture(103); -// RenderSystem.depthMask(true); -// RenderSystem.enableCull(); -// } + // Rotate yaw by 180 degrees. Parameters: (pitch, yaw, roll), angle, usingDegrees + cameraRotation.mul(new Quaternion(new Vector3f(0, -1, 0), 180, true)); + Matrix4f translateMatrix = new Matrix4f(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); + } final int h = player.level.getHeight(); @@ -114,9 +118,24 @@ public static void renderOverlays(PoseStack matrixstack) { renderGrid(matrixstack, regionBorderX0 - 0.005f, regionBorderY0 - 0.005f, regionBorderZ0 - 0.005f, regionBorderX1 + 0.005f, regionBorderY1 + 0.005f, regionBorderZ1 + 0.005f, 16.0f, renderColorGrid); } + + // restore render settings RenderSystem.enableTexture(); - RenderSystem.disableCull(); - RenderSystem.depthMask(true); + if (Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { + RenderSystem.disableCull(); + RenderSystem.depthMask(true); + } else { + RenderSystem.lineWidth(1.0F); + RenderSystem.enableBlend(); + + if(!LightOverlayHandler.isEnabled()){ + cameraRotation.mul(new Quaternion(new Vector3f(0, -1, 0), -180, true)); + Matrix4f translateMatrix = new Matrix4f(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); + } + + matrixstack.popPose(); + } } public static void renderEdge(PoseStack matrixstack, double x, double z, double h3, double h, int color) { diff --git a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayHandler.java b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayHandler.java index 40061d3..8774508 100644 --- a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayHandler.java +++ b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayHandler.java @@ -5,6 +5,7 @@ import at.ridgo8.moreoverlays.api.lightoverlay.ILightScanner; import at.ridgo8.moreoverlays.api.lightoverlay.LightOverlayReloadHandlerEvent; import at.ridgo8.moreoverlays.config.Config; +import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.RenderLevelLastEvent; import net.minecraftforge.common.MinecraftForge; @@ -16,8 +17,8 @@ public class LightOverlayHandler { private static boolean enabled = false; - private static ILightRenderer renderer = null; - private static ILightScanner scanner = null; + public static ILightRenderer renderer = null; + public static ILightScanner scanner = null; public static void init() { MinecraftForge.EVENT_BUS.register(new LightOverlayHandler()); @@ -80,7 +81,7 @@ public void onWorldUnload(final WorldEvent.Unload event) { @SubscribeEvent public void renderWorldLastEvent(RenderLevelLastEvent event) { - if (enabled) { + if (enabled && Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { renderer.renderOverlays(scanner, event.getPoseStack()); } } diff --git a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java index 9f90295..46d0900 100644 --- a/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java +++ b/src/main/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java @@ -3,11 +3,15 @@ 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.*; import com.mojang.math.Matrix4f; +import com.mojang.math.Quaternion; +import com.mojang.math.Vector3f; import net.minecraft.client.Camera; +import net.minecraft.client.GraphicsStatus; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; @@ -90,12 +94,27 @@ public void renderOverlays(ILightScanner scanner, PoseStack matrixstack) { RenderSystem.enableDepthTest(); RenderSystem.disableTexture(); RenderSystem.disableBlend(); + RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth.get()); + RenderSystem.setShader(GameRenderer::getPositionColorShader); - RenderSystem.depthMask(false); + Quaternion cameraRotation = Minecraft.getInstance().gameRenderer.getMainCamera().rotation(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth.get()); - RenderSystem.enableCull(); + if (Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { + // Use old renderer + RenderSystem.depthMask(false); + RenderSystem.enableCull(); + } 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. Parameters: (pitch, yaw, roll), angle, usingDegrees + cameraRotation.mul(new Quaternion(new Vector3f(0, -1, 0), 180, true)); + } + Matrix4f translateMatrix = new Matrix4f(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); + } float ar = ((float) ((Config.render_spawnAColor.get() >> 16) & 0xFF)) / 255F; float ag = ((float) ((Config.render_spawnAColor.get() >> 8) & 0xFF)) / 255F; @@ -116,8 +135,20 @@ else if (mode == 2) renderCross(matrixstack, entry.getKey(), ar, ag, ab); } tess.end(); + // restore render settings RenderSystem.enableTexture(); - RenderSystem.disableCull(); - RenderSystem.depthMask(true); + if (Minecraft.getInstance().options.graphicsMode != GraphicsStatus.FABULOUS) { + RenderSystem.disableCull(); + RenderSystem.depthMask(true); + } else { + RenderSystem.lineWidth(1.0F); + RenderSystem.enableBlend(); + + cameraRotation.mul(new Quaternion(new Vector3f(0, -1, 0), -180, true)); + Matrix4f translateMatrix = new Matrix4f(cameraRotation); + matrixstack.mulPoseMatrix(translateMatrix); + + matrixstack.popPose(); + } } } diff --git a/src/main/java/at/ridgo8/moreoverlays/mixin/MixinDebugRenderer.java b/src/main/java/at/ridgo8/moreoverlays/mixin/MixinDebugRenderer.java new file mode 100644 index 0000000..5f48deb --- /dev/null +++ b/src/main/java/at/ridgo8/moreoverlays/mixin/MixinDebugRenderer.java @@ -0,0 +1,29 @@ +package at.ridgo8.moreoverlays.mixin; + +import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsHandler; +import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsRenderer; +import at.ridgo8.moreoverlays.lightoverlay.LightOverlayHandler; +import net.minecraft.client.GraphicsStatus; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.debug.DebugRenderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DebugRenderer.class) +public class MixinDebugRenderer { + @Inject(method = "render", at = @At("HEAD")) + private void render(PoseStack poseStack, MultiBufferSource.BufferSource buffer, double a, double b, double c, CallbackInfo callback) { + if (ChunkBoundsHandler.getMode() != ChunkBoundsHandler.RenderMode.NONE && Minecraft.getInstance().options.graphicsMode == GraphicsStatus.FABULOUS) { + ChunkBoundsRenderer.renderOverlays(poseStack); + } + if(LightOverlayHandler.isEnabled() && Minecraft.getInstance().options.graphicsMode == GraphicsStatus.FABULOUS){ + LightOverlayHandler.renderer.renderOverlays(LightOverlayHandler.scanner, poseStack); + } + } +} diff --git a/src/main/resources/moreoverlays.mixin.json b/src/main/resources/moreoverlays.mixin.json new file mode 100644 index 0000000..8004bcc --- /dev/null +++ b/src/main/resources/moreoverlays.mixin.json @@ -0,0 +1,12 @@ +{ + "required": false, + "package": "at.ridgo8.moreoverlays.mixin", + "compatibilityLevel": "JAVA_8", + "client": [ + "MixinDebugRenderer" + ], + "injectors": { + "defaultRequire": 1 + }, + "refmap": "moreoverlays.mixin-refmap.json" +} \ No newline at end of file