package cc.polyfrost.oneconfig.internal.gui; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.RenderEvent; import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent; import cc.polyfrost.oneconfig.events.event.Stage; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.config.Preferences; import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.shader.Shader; import net.minecraft.client.shader.ShaderUniform; import net.minecraft.util.ResourceLocation; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.List; /** * An implementation of the BlurMC mod by tterrag1098. *
* For the original source see ... * For the public license, see ... *
* License available under ... * * @author tterrag1098, boomboompower *
* Taken from ToggleChat
* ...
*/
public class BlurHandler {
public static BlurHandler INSTANCE = new BlurHandler();
private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json");
private final Logger logger = LogManager.getLogger("OneConfig - Blur");
private long start;
private float lastProgress = 0;
/**
* Simply initializes the blur mod so events are properly handled by forge.
*/
public void load() {
EventManager.INSTANCE.register(this);
}
@Subscribe
private void onGuiChange(ScreenOpenEvent event) {
reloadBlur(event.screen);
}
@Subscribe
private void onRenderTick(RenderEvent event) {
if (event.stage != Stage.END) {
return;
}
// Only blur on our own menus
if (UScreen.getCurrentScreen() == null) {
return;
}
// Only update the shader if one is active
if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) {
return;
}
float progress = getBlurStrengthProgress();
// If the new progress value matches the old one this
// will skip the frame update, which (hopefully) resolves the issue
// with the heavy computations after the "animation" is complete.
if (progress == this.lastProgress) {
return;
}
// Store it for the next iteration!
this.lastProgress = progress;
// This is hilariously bad, and could cause frame issues on low-end computers.
// Why is this being computed every tick? Surely there is a better way?
// This needs to be optimized.
try {
final List
* The strength of the blur does not go below 5.0F.
*/
private float getBlurStrengthProgress() {
return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F);
}
}