Skip to content

Commit

Permalink
Merge pull request #23 from r8420/#8-fix-overlay-on-fabulous
Browse files Browse the repository at this point in the history
#8 Fix graphical issue and overlay on fabulous graphics
  • Loading branch information
r8420 authored Feb 6, 2022
2 parents 8649032 + 9ac386a commit b892fcb
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 31 deletions.
24 changes: 21 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/at/ridgo8/moreoverlays/mixin/MixinDebugRenderer.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
12 changes: 12 additions & 0 deletions src/main/resources/moreoverlays.mixin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": false,
"package": "at.ridgo8.moreoverlays.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinDebugRenderer"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "moreoverlays.mixin-refmap.json"
}

0 comments on commit b892fcb

Please sign in to comment.