Skip to content

Commit

Permalink
2.0.0 - AutoConfig and Fade Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Motschen committed Nov 8, 2020
1 parent f8a4dd7 commit 432934b
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 145 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ext.buildnumber = System.getenv().BUILD_NUMBER ?: 'custom';

group = 'com.tterrag.blur'
archivesBaseName = "Blur"
version = "${mod_version}-${minecraft_version}[fabric]"
version = "${mod_version}-${minecraft_version}+fabric"

sourceCompatibility = '1.8'
targetCompatibility = '1.8'
Expand All @@ -32,6 +32,12 @@ 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}")

implementation 'com.google.code.findbugs:jsr305:3.0.2'
}

Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
minecraft_version=1.16.2

mod_version=1.0.7
mod_version=2.0.0

fabric_loader_version=0.9.1+build.205
fabric_version=0.18.0+build.397-1.16
mappings_version=1.16.2+build.19

auto_config_version = 3.2.0-unstable
cloth_config_version = 4.7.0-unstable
mod_menu_version = 1.14.6+build.31

# Satin library
satin_version = 1.4.1
satin_version = 1.5.1

project_id=268324
release_type=release
Binary file removed pack_icons/lite.png
Binary file not shown.
Binary file removed pack_icons/strong.png
Binary file not shown.
Binary file removed pack_icons/ultra_lite.png
Binary file not shown.
Binary file removed pack_icons/ultra_strong.png
Binary file not shown.

This file was deleted.

7 changes: 0 additions & 7 deletions pack_template/pack.mcmeta.template

This file was deleted.

22 changes: 0 additions & 22 deletions resource_packs.json

This file was deleted.

54 changes: 18 additions & 36 deletions src/main/java/com/tterrag/blur/Blur.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
package com.tterrag.blur;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tterrag.blur.config.BlurConfig;
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.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.ArrayUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class Blur implements ClientModInitializer {
public static BlurConfig BLUR_CONFIG;

public static final String MODID = "blur";
public static final String MOD_NAME = "Blur";

static class ConfigJson {
String[] blurExclusions = new String[]{ ChatScreen.class.getName() };
int fadeTimeMillis = 200;
int radius = 8;
String gradientStartColor = "75000000";
String gradientEndColor = "75000000";
}

private long start;

public ConfigJson configs = new ConfigJson();
public int colorFirst, colorSecond;

private final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"),
Expand All @@ -45,19 +30,8 @@ static class ConfigJson {

@Override
public void onInitializeClient() {
Path configFile = FabricLoader.getInstance().getConfigDir().resolve(Blur.MODID + ".json");
try {
if (!Files.exists(configFile)) {
Files.createDirectories(configFile.getParent());
Files.write(configFile, new GsonBuilder().setPrettyPrinting().create().toJson(configs).getBytes(), StandardOpenOption.CREATE_NEW);
} else {
configs = new Gson().fromJson(Files.newBufferedReader(configFile), ConfigJson.class);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
colorFirst = Integer.parseUnsignedInt(configs.gradientStartColor, 16);
colorSecond = Integer.parseUnsignedInt(configs.gradientEndColor, 16);
AutoConfig.register(BlurConfig.class, JanksonConfigSerializer::new);
BLUR_CONFIG = AutoConfig.getConfigHolder(BlurConfig.class).getConfig();

ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
if (start > 0) {
Expand All @@ -67,23 +41,31 @@ public void onInitializeClient() {
});
}

private boolean doFade = false;
public void onScreenChange(Screen newGui) {
if (MinecraftClient.getInstance().world != null) {
boolean excluded = newGui == null || ArrayUtils.contains(configs.blurExclusions, newGui.getClass().getName());
boolean excluded = newGui == null || ArrayUtils.contains(BLUR_CONFIG.blurExclusions, newGui.getClass().getName());
if (!excluded) {
start = System.currentTimeMillis();
blur.setUniformValue("Radius", (float) getRadius());
colorFirst = Integer.parseUnsignedInt(BLUR_CONFIG.gradientStartColor, 16);
colorSecond = Integer.parseUnsignedInt(BLUR_CONFIG.gradientEndColor, 16);
if (doFade == true) {
start = System.currentTimeMillis();
doFade = false;
}
} else {
start = -1;
doFade = true;
}
}
}

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

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

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

import com.sun.org.apache.xerces.internal.xs.StringList;
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
import me.sargunvohra.mcmods.autoconfig1u.ConfigHolder;
import me.sargunvohra.mcmods.autoconfig1u.ConfigManager;
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
import me.sargunvohra.mcmods.autoconfig1u.gui.registry.DefaultGuiRegistryAccess;
import me.shedaniel.clothconfig2.api.ConfigScreen;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.List;

@Config(name = "blur")
@SuppressWarnings("No GUI provider registered")
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";
}
17 changes: 17 additions & 0 deletions src/main/java/com/tterrag/blur/config/ModMenuIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tterrag.blur.config;

import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
@SuppressWarnings("No GUI provider registered")
public class ModMenuIntegration implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(BlurConfig.class, parent).get();
}
}
Binary file modified src/main/resources/assets/blur/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/main/resources/assets/blur/lang/de_de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"text.autoconfig.blur.title": "Blur Konfiguration",
"text.autoconfig.blur.option.fadeTimeMillis": "Überblendzeit (in Millisekunden)",
"text.autoconfig.blur.option.radius": "Radius",
"text.autoconfig.blur.option.gradientStartColor": "Farbverlauf-Anfangsfarbe",
"text.autoconfig.blur.option.gradientEndColor": "Farbverlauf-Endfarbe"
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/blur/lang/en_gb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"text.autoconfig.blur.title": "Blur Config",
"text.autoconfig.blur.option.fadeTimeMillis": "Fade Time (in milliseconds)",
"text.autoconfig.blur.option.radius": "Radius",
"text.autoconfig.blur.option.gradientStartColor": "Gradient Start Colour",
"text.autoconfig.blur.option.gradientEndColor": "Gradient End Colour"
}
6 changes: 5 additions & 1 deletion src/main/resources/assets/blur/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"blur.config.title": "Blur Config"
"text.autoconfig.blur.title": "Blur Config",
"text.autoconfig.blur.option.fadeTimeMillis": "Fade Time (in milliseconds)",
"text.autoconfig.blur.option.radius": "Radius",
"text.autoconfig.blur.option.gradientStartColor": "Gradient Start Color",
"text.autoconfig.blur.option.gradientEndColor": "Gradient End Color"
}
20 changes: 11 additions & 9 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
{
"schemaVersion": 1,
"id": "blur",
"name": "Blur",
"version": "1.0.6",
"name": "Blur (Fabric)",
"version": "2.0.0",
"environment": "client",
"license": "MIT",
"icon": "assets/blur/icon.png",
"entrypoints": {
"client": [
"com.tterrag.blur.Blur::INSTANCE"
],
"modmenu": [
"com.tterrag.blur.config.ModMenuIntegration"
]
},
"contact": {
"homepage": "https://minecraft.curseforge.com/projects/blur",
"issues": "https://github.com/tterrag1098/Blur/issues"
"homepage": "https://www.curseforge.com/minecraft/mc-mods/blur-fabric",
"issues": "https://github.com/Motschen/Blur/issues"
},
"authors": [
"tterrag1098"
"tterrag1098",
"Pyrofab",
"Motschen"
],
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
"mixins": [
"mixins.blur.json"
],
"custom": {
"modmenu:clientsideOnly": true
}
]
}

0 comments on commit 432934b

Please sign in to comment.