Skip to content

Commit

Permalink
Blur 2.1.0 - MidnightConfig
Browse files Browse the repository at this point in the history
Switch to MidnightConfig:
- Much smaller file size
- Live preview
- Fixed #4

Chinise translation by @Enaium
Update to 21w08b
  • Loading branch information
Motschen committed Mar 5, 2021
1 parent 40d6310 commit a520948
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 65 deletions.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ dependencies {
modCompile "io.github.ladysnake:Satin:${satin_version}"
include "io.github.ladysnake:Satin:${satin_version}"

modImplementation ("me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}")
include ("me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}")
modImplementation ("me.shedaniel.cloth:config-2:${project.cloth_config_version}")
include ("me.shedaniel.cloth:config-2:${project.cloth_config_version}")
modImplementation ("io.github.prospector:modmenu:${project.mod_menu_version}")
modImplementation ("io.github.prospector:modmenu:${project.mod_menu_version}") {
exclude group: "net.fabricmc.fabric-api"
}

implementation 'com.google.code.findbugs:jsr305:3.0.2'
}
Expand Down
16 changes: 6 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=20w51a
yarn_mappings=20w51a+build.5
loader_version=0.10.8
fabric_version=0.28.3+1.17
minecraft_version=21w08b
yarn_mappings=21w08b+build.20
loader_version=0.11.2

# Mod Properties
mod_version = 2.0.0-20w51a+fabric
mod_version = 2.1.0-21w08b+fabric
maven_group = com.tterrag.blur
archives_base_name = Blur

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.26.1+1.16

auto_config_version = 3.2.0-unstable
cloth_config_version = 4.7.0-unstable
mod_menu_version = 1.14.6+build.31
fabric_version=0.31.2+1.17
mod_menu_version = 2.0.0-beta.1+build.2
satin_version = 1.6.0-nightly.20w48a
25 changes: 9 additions & 16 deletions src/main/java/com/tterrag/blur/Blur.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
package com.tterrag.blur;

import com.tterrag.blur.config.BlurConfig;
import com.tterrag.blur.config.MidnightConfig;
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
import ladysnake.satin.api.managed.ManagedShaderEffect;
import ladysnake.satin.api.managed.ShaderEffectManager;
import ladysnake.satin.api.managed.uniform.Uniform1f;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.ArrayUtils;

public class Blur implements ClientModInitializer {
public static BlurConfig BLUR_CONFIG;

public static final String MODID = "blur";

private long start;
public int colorFirst, colorSecond;

private final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"),
shader -> shader.setUniformValue("Radius", (float) getRadius()));
shader -> shader.setUniformValue("Radius", BlurConfig.radius));
private final Uniform1f blurProgress = blur.findUniform1f("Progress");

public static final Blur INSTANCE = new Blur();

@Override
public void onInitializeClient() {
AutoConfig.register(BlurConfig.class, JanksonConfigSerializer::new);
BLUR_CONFIG = AutoConfig.getConfigHolder(BlurConfig.class).getConfig();
MidnightConfig.init("blur", BlurConfig.class);

ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
if (start > 0) {
Expand All @@ -43,12 +40,12 @@ public void onInitializeClient() {
private boolean doFade = false;
public void onScreenChange(Screen newGui) {
if (MinecraftClient.getInstance().world != null) {
boolean excluded = newGui == null || ArrayUtils.contains(BLUR_CONFIG.blurExclusions, newGui.getClass().getName());
boolean excluded = newGui == null || ArrayUtils.contains(BlurConfig.blurExclusions, newGui.getClass().getName());
if (!excluded) {
blur.setUniformValue("Radius", (float) getRadius());
colorFirst = Integer.parseUnsignedInt(BLUR_CONFIG.gradientStartColor, 16);
colorSecond = Integer.parseUnsignedInt(BLUR_CONFIG.gradientEndColor, 16);
if (doFade == true) {
blur.setUniformValue("Radius", BlurConfig.radius);
colorFirst = Integer.parseUnsignedInt(String.valueOf(BlurConfig.gradientStartColor), 16);
colorSecond = Integer.parseUnsignedInt(String.valueOf(BlurConfig.gradientEndColor), 16);
if (doFade) {
start = System.currentTimeMillis();
doFade = false;
}
Expand All @@ -59,12 +56,8 @@ public void onScreenChange(Screen newGui) {
}
}

public int getRadius() {
return BLUR_CONFIG.radius;
}

private float getProgress() {
return Math.min((System.currentTimeMillis() - start) / (float) BLUR_CONFIG.fadeTimeMillis, 1);
return Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
}

public int getBackgroundColor(boolean second) {
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/tterrag/blur/config/BlurConfig.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.tterrag.blur.config;

import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
import net.minecraft.client.gui.screen.ChatScreen;

@Config(name = "blur")
public class BlurConfig implements ConfigData {
@ConfigEntry.Gui.Excluded
public String[] blurExclusions = new String[]{ ChatScreen.class.getName() };
public int fadeTimeMillis = 200;
public int radius = 8;
public String gradientStartColor = "75000000";
public String gradientEndColor = "75000000";
public class BlurConfig extends MidnightConfig {
@Entry
public static String[] blurExclusions = new String[]{ ChatScreen.class.getName() };
@Entry(min = 0, max = 5000)
public static int fadeTimeMillis = 200;
@Entry(min = 0, max = 500)
public static int radius = 8;
@Entry(min = 0, max = 99999999)
public static int gradientStartColor = 75000000;
@Entry(min = 0, max = 99999999)
public static int gradientEndColor = 75000000;
}
Loading

0 comments on commit a520948

Please sign in to comment.