Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
plugins {
id 'fabric-loom' version '1.7.+'
id 'io.github.juuxel.loom-quiltflower' version '1.8.0'
id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

dependencies {
//Versions in gradle.properties
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation fabricApi.module("fabric-resource-loader-v0", project.fabric_version)
}

loom {
mods {
"shader-reload" {
sourceSet sourceSets.main
}
}
}

processResources {
inputs.property "version", project.version

Expand All @@ -27,9 +37,12 @@ tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

//Generate source jar
java {
archivesBaseName = project.archives_base_name
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

Expand Down
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# https://modmuss50.me/fabric.html
minecraft_version=1.21
yarn_mappings=1.21+build.7
loader_version=0.15.11
fabric_version=0.100.4+1.21
minecraft_version=1.21.10
yarn_mappings=1.21.10+build.3
loader_version=0.18.4
fabric_version=0.138.4+1.21.10
loom_version=1.14-SNAPSHOT

# Mod Properties
mod_version=1.12
mod_version=1.13
maven_group=suso
archives_base_name=shader-reload
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/suso/shaderreload/CustomShaderLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package suso.shaderreload;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.*;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.DefaultResourcePack;
import net.minecraft.util.Identifier;

import java.io.FileNotFoundException;
import java.util.Set;

public class CustomShaderLoader extends ShaderLoader {
private final DefaultResourcePack defaultPack = MinecraftClient.getInstance().getDefaultResourcePack();

public CustomShaderLoader(TextureManager textureManager) {
super(textureManager, CustomShaderLoader::onShaderError);
}

@Override
public PostEffectProcessor loadPostEffect(Identifier id, Set<Identifier> availableExternalTargets) {
PostEffectProcessor result = super.loadPostEffect(id, availableExternalTargets);
if(result != null) return result;
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing in the if condition. Opening braces should be on the same line as the if statement to match Java conventions.

Suggested change
if(result != null) return result;
if (result != null) {
return result;
}

Copilot uses AI. Check for mistakes.

try {
return loadDefaultPostEffect(id, availableExternalTargets);
} catch (Exception e) {
ShaderReload.printShaderException(e, true);
}

return null;
}

static void onShaderError(Exception e) {
ShaderReload.tripError();
ShaderReload.printShaderException(e, false);
}

private ShaderProgram loadDefaultProgram(ShaderProgram key) throws FileNotFoundException {
return null;
}

private PostEffectProcessor loadDefaultPostEffect(Identifier id, Set<Identifier> availableExternalTargets) {
return null;
Comment on lines +39 to +43
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method loadDefaultProgram is declared but never implemented - it only returns null. If this is a placeholder for future implementation, consider adding a TODO comment or throwing an UnsupportedOperationException to make the intent clearer.

Suggested change
return null;
}
private PostEffectProcessor loadDefaultPostEffect(Identifier id, Set<Identifier> availableExternalTargets) {
return null;
// TODO: Implement loading of default shader program if needed
throw new UnsupportedOperationException("loadDefaultProgram is not yet implemented");
}
private PostEffectProcessor loadDefaultPostEffect(Identifier id, Set<Identifier> availableExternalTargets) {
// TODO: Implement loading of default post effect if needed
throw new UnsupportedOperationException("loadDefaultPostEffect is not yet implemented");

Copilot uses AI. Check for mistakes.
}
Comment on lines +42 to +44
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method loadDefaultPostEffect is declared but only returns null without any implementation. This appears to be called in the exception handler on line 25, which means it will always return null when there's an error loading a post-effect. If this is intentional, the try-catch block on lines 24-28 serves no purpose since loadDefaultPostEffect always returns null. Either implement the method properly or remove the dead code.

Copilot uses AI. Check for mistakes.
}
134 changes: 47 additions & 87 deletions src/main/java/suso/shaderreload/ShaderReload.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
package suso.shaderreload;

import com.google.gson.JsonSyntaxException;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.PostEffectProcessor;
import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.*;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
import suso.shaderreload.mixin.KeyboardInvoker;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

import static net.minecraft.resource.ResourceType.CLIENT_RESOURCES;

@Environment(EnvType.CLIENT)
public class ShaderReload implements ClientModInitializer {
public static final int GLFW_KEY = GLFW.GLFW_KEY_R;
public static final Logger LOGGER = LogManager.getLogger("Shader Reload");

private static final StopException STOP = new StopException();
private static boolean reloading = false;
private static boolean stopReloading = false;
private static boolean expectError = false;
private static ResourceReloader shaderLoader;

@Override
Expand All @@ -41,95 +30,66 @@ public void onInitializeClient() {
}

public static void reloadShaders() {
if (reloading) return;
var client = MinecraftClient.getInstance();
if(reloading) {
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing in the if condition. The opening brace should be on the same line as the if statement to match Java conventions and the style used elsewhere in the file (e.g., line 43).

Suggested change
if(reloading) {
if (reloading) {

Copilot uses AI. Check for mistakes.
return;
}

reloading = true;
stopReloading = false;
SimpleResourceReload.start(client.getResourceManager(), List.of(shaderLoader, client.worldRenderer),
Util.getMainWorkerExecutor(), client, CompletableFuture.completedFuture(Unit.INSTANCE), false)
.whenComplete()
.whenComplete((result, throwable) -> {
reloading = false;
if (throwable == null) {
((KeyboardInvoker) client.keyboard).invokeDebugLog("debug.reload_shaders.message");
return;
}
if (throwable instanceof CompletionException ex && ex.getCause() != null) {
throwable = ex.getCause();
}
if (!(throwable instanceof StopException)) {
((KeyboardInvoker) client.keyboard).invokeDebugError("debug.reload_shaders.unknown_error");
throwable.printStackTrace();
}
});
}
expectError = false;
MinecraftClient client = MinecraftClient.getInstance();

// Print a shader exception in chat.
private static void printShaderException(Exception exception, boolean builtin) {
var client = MinecraftClient.getInstance();
var throwable = (Throwable) exception;
while (!(throwable instanceof InvalidHierarchicalFileException)) {
var cause = throwable.getCause();
if (cause != null) throwable = cause;
else {
var translationKey = "debug.reload_shaders.unknown_error" + (builtin ? ".builtin" : "");
((KeyboardInvoker) client.keyboard).invokeDebugError(translationKey);
throwable.printStackTrace();
SimpleResourceReload.start(client.getResourceManager(), List.of(shaderLoader, client.worldRenderer), Util.getMainWorkerExecutor(), client, CompletableFuture.completedFuture(Unit.INSTANCE), false).whenComplete().whenComplete((result, throwable) -> {
reloading = false;
if(throwable == null) {
debugLog(Text.translatable("debug.reload_shaders.message"));
expectError = false;
return;
}
}
var translationKey = "debug.reload_shaders.error" + (builtin ? ".builtin" : "");
((KeyboardInvoker) client.keyboard).invokeDebugError(translationKey);
client.inGameHud.getChatHud().addMessage(Text.literal(throwable.getMessage()).formatted(Formatting.GRAY));
}

// Try loading a core shader; if it fails, stop shader reloading or try loading a built-in core shader.
public static ShaderProgram onLoadShaders$new(ResourceFactory factory, String name, VertexFormat format) throws IOException {
try {
return new ShaderProgram(factory, name, format);
} catch (IOException e) {
printShaderException(e, false);
if (reloading) throw STOP;
}
try {
var defaultPack = MinecraftClient.getInstance().getDefaultResourcePack();
return new ShaderProgram(defaultPack.getFactory(), name, format);
} catch (IOException e) {
printShaderException(e, true);
throw e;
}
if(throwable instanceof CompletionException ex && ex.getCause() != null) {
throwable = ex.getCause();
}
Comment on lines +43 to +51
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing in the if conditions. Opening braces should be on the same line as the if statement to match Java conventions and the style used in the same file (e.g., line 66).

Copilot uses AI. Check for mistakes.

if(!expectError) {
debugLog(Text.translatable("debug.reload_shaders.unknown_error"));
LOGGER.error(throwable);
}

expectError = false;
});
}

// Try loading a shader effect; if it fails, request stopping and try loading a built-in shader effect.
@SuppressWarnings("resource")
public static PostEffectProcessor onLoadShader$new(TextureManager textureManager, ResourceFactory resourceFactory,
Framebuffer framebuffer, Identifier location) throws IOException {
try {
return new PostEffectProcessor(textureManager, resourceFactory, framebuffer, location);
} catch (IOException | JsonSyntaxException e) {
printShaderException(e, false);
stopReloading = true;
}
try {
var defaultPack = MinecraftClient.getInstance().getDefaultResourcePack();
resourceFactory = new LifecycledResourceManagerImpl(CLIENT_RESOURCES, List.of(defaultPack));
return new PostEffectProcessor(textureManager, resourceFactory, framebuffer, location);
} catch (IOException | JsonSyntaxException e) {
printShaderException(e, true);
throw e;
// Print a shader exception in chat.
public static void printShaderException(Exception exception, boolean builtin) {
MinecraftClient client = MinecraftClient.getInstance();
Throwable throwable = exception;
while (!(throwable instanceof InvalidHierarchicalFileException)) {
Throwable cause = throwable.getCause();
if(cause != null) {
throwable = cause;
} else {
Comment on lines +68 to +70
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing in the if condition. Opening braces should be on the same line as the if statement to match Java conventions.

Copilot uses AI. Check for mistakes.
String translationKey = "debug.reload_shaders.unknown_error" + (builtin ? ".builtin" : "");
debugLog(Text.translatable(translationKey));
LOGGER.error(throwable);
return;
}
}
}

// Stop shader reloading if it's requested.
public static void onLoadShader$end() {
if (reloading && stopReloading) throw STOP;
String translationKey = "debug.reload_shaders.error" + (builtin ? ".builtin" : "");
debugLog(Text.translatable(translationKey));
client.inGameHud.getChatHud().addMessage(Text.literal(throwable.getMessage()).formatted(Formatting.GRAY));
}

public static void setShaderLoader(ResourceReloader value) {
shaderLoader = value;
}

private static class StopException extends RuntimeException {
private StopException() {}
public static void tripError() {
expectError = true;
}

private static void debugLog(Text text) {
MinecraftClient client = MinecraftClient.getInstance();
client.inGameHud.getChatHud().addMessage(text);
}
}
57 changes: 0 additions & 57 deletions src/main/java/suso/shaderreload/mixin/GameRendererMixin.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/suso/shaderreload/mixin/GlProgramManagerMixin.java

This file was deleted.

Loading
Loading