Files
src
build.gradle
gradle.properties
saturation
settings.gradle
Code
11 221
src/client/java/com/kodari/colorsaturation/client/SaturationEffect.java
package com.kodari.colorsaturation.client;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.PostEffectProcessor;
import net.minecraft.client.render.DefaultFramebufferSet;
import net.minecraft.util.Identifier;
import java.lang.reflect.Method;
public final class SaturationEffect {
private static final Identifier EFFECT_ID = Identifier.of("colorsaturation", "saturation");
private static boolean attemptedLoad;
private static PostEffectProcessor processor;
private static Method renderMethod;
private static Object framebufferPool;
private SaturationEffect() {
}
public static void apply() {
MinecraftClient client = MinecraftClient.getInstance();
if (!attemptedLoad) {
attemptedLoad = true;
processor = client.getShaderLoader().loadPostEffect(EFFECT_ID, DefaultFramebufferSet.MAIN_ONLY);
}
if (processor != null) {
try {
if (renderMethod == null) {
Class<?> objectPoolClass = Class.forName("net.minecraft.client.util.memory.ObjectPool");
framebufferPool = objectPoolClass.getConstructor(int.class).newInstance(3);
for (Method method : PostEffectProcessor.class.getMethods()) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (method.getName().equals("render") && parameterTypes.length == 2
&& parameterTypes[1] == objectPoolClass) {
renderMethod = method;
break;
}
}
if (renderMethod == null) {
throw new NoSuchMethodException("PostEffectProcessor.render(Framebuffer, ObjectAllocator)");
}
}
renderMethod.invoke(processor, client.getFramebuffer(), framebufferPool);
} catch (ReflectiveOperationException exception) {
throw new IllegalStateException("Unable to apply saturation post effect", exception);
}
}
}
}