mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-16 11:45:09 +01:00
Compare commits
9 Commits
1.0.5-19w3
...
v2.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a520948fff | ||
|
|
40d63109f3 | ||
|
|
a6b70f1c6a | ||
|
|
d42905746b | ||
|
|
432934b056 | ||
|
|
f8a4dd71fd | ||
|
|
d117c98de2 | ||
|
|
fd84d68897 | ||
|
|
7e8194a529 |
122
build.gradle
122
build.gradle
@@ -1,46 +1,42 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'fabric-loom' version '0.5-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
id 'idea'
|
|
||||||
id 'eclipse'
|
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.9'
|
|
||||||
id 'fabric-loom' version '0.2.5-SNAPSHOT'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false');
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
ext.buildnumber = System.getenv().BUILD_NUMBER ?: 'custom';
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
group = 'com.tterrag.blur'
|
archivesBaseName = project.archives_base_name
|
||||||
archivesBaseName = "Blur"
|
version = project.mod_version
|
||||||
version = "${mod_version}-${minecraft_version}[fabric]"
|
group = project.maven_group
|
||||||
|
|
||||||
sourceCompatibility = '1.8'
|
|
||||||
targetCompatibility = '1.8'
|
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url "https://jitpack.io" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||||
mappings "net.fabricmc:yarn:${mappings_version}"
|
mappings "net.fabricmc:yarn:${yarn_mappings}"
|
||||||
modCompile "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
modCompile "net.fabricmc:fabric-loader:${loader_version}"
|
||||||
modCompile "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
modCompile "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
||||||
modCompile "com.github.Ladysnake:Satin:${satin_version}"
|
modCompile "io.github.ladysnake:Satin:${satin_version}"
|
||||||
include "com.github.Ladysnake:Satin:${satin_version}"
|
include "io.github.ladysnake:Satin:${satin_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'
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", project.version
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include "fabric.mod.json"
|
include "fabric.mod.json"
|
||||||
expand "version": mod_version
|
expand "version": project.version
|
||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
@@ -48,69 +44,43 @@ processResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||||
import groovy.json.JsonSlurper
|
// this fixes some edge cases with special characters not displaying correctly
|
||||||
|
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||||
task createResourcePacks {
|
tasks.withType(JavaCompile) {
|
||||||
def inputFile = new File("resource_packs.json")
|
options.encoding = "UTF-8"
|
||||||
def json = new JsonSlurper().parseText(inputFile.text)
|
|
||||||
json.each {
|
|
||||||
def pack_id = it.key
|
|
||||||
def pack_name = it.value.name
|
|
||||||
def pack_desc = it.value.description
|
|
||||||
def pack_radius = it.value.radius
|
|
||||||
|
|
||||||
def taskName = "createPack" + pack_id.capitalize();
|
|
||||||
task "${taskName}" (type: Zip) {
|
|
||||||
from ('pack_template') {
|
|
||||||
filter(ReplaceTokens, tokens: [
|
|
||||||
mod_version: project.version.toString(),
|
|
||||||
pack_version: '3',
|
|
||||||
description: pack_desc.toString(),
|
|
||||||
radius: pack_radius.toString()
|
|
||||||
])
|
|
||||||
|
|
||||||
rename(/(.+)\.template/, '$1')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
from ('pack_icons') {
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
include "${pack_id}.png"
|
// if it is present.
|
||||||
rename '.+', 'icon.png'
|
// If you remove this task, sources will not be generated.
|
||||||
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
|
classifier = "sources"
|
||||||
|
from sourceSets.main.allSource
|
||||||
}
|
}
|
||||||
|
|
||||||
baseName = "Blur " + pack_name
|
jar {
|
||||||
|
from "LICENSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
createResourcePacks.finalizedBy taskName
|
// configure the maven publication
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
// add all the jars that should be included when publishing to maven
|
||||||
|
artifact(remapJar) {
|
||||||
|
builtBy remapJar
|
||||||
}
|
}
|
||||||
}
|
artifact(sourcesJar) {
|
||||||
|
builtBy remapSourcesJar
|
||||||
// Not necessary atm
|
|
||||||
// tasks.build.dependsOn createResourcePacks
|
|
||||||
|
|
||||||
tasks.curseforge.enabled = !dev && project.hasProperty('curseforge_key')
|
|
||||||
|
|
||||||
curseforge {
|
|
||||||
if (project.hasProperty('curseforge_key')) {
|
|
||||||
apiKey = project.curseforge_key
|
|
||||||
}
|
|
||||||
|
|
||||||
project {
|
|
||||||
id = project.project_id
|
|
||||||
changelogType = 'html'
|
|
||||||
changelog = System.getenv('CHANGELOG')
|
|
||||||
if (changelog == null || 'none'.equals(changelog)) {
|
|
||||||
changelog = getChangelog() ?: ''
|
|
||||||
changelogType = 'text'
|
|
||||||
}
|
|
||||||
releaseType = project.release_type
|
|
||||||
addGameVersion '1.9.4'
|
|
||||||
addGameVersion '1.11.2'
|
|
||||||
addGameVersion '1.12'
|
|
||||||
addGameVersion '1.12.1'
|
|
||||||
mainArtifact(jar) {
|
|
||||||
displayName = "Blur ${mod_version}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// select the repositories you want to publish to
|
||||||
|
repositories {
|
||||||
|
// uncomment to publish to the local maven
|
||||||
|
// mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
minecraft_version=19w34a
|
# Done to increase the memory available to gradle.
|
||||||
|
org.gradle.jvmargs=-Xmx1G
|
||||||
|
|
||||||
mod_version=1.0.5
|
# Fabric Properties
|
||||||
|
# check these on https://fabricmc.net/use
|
||||||
|
minecraft_version=21w08b
|
||||||
|
yarn_mappings=21w08b+build.20
|
||||||
|
loader_version=0.11.2
|
||||||
|
|
||||||
fabric_loader_version=0.5.0+build.162
|
# Mod Properties
|
||||||
fabric_version=0.3.1+build.208
|
mod_version = 2.1.0-21w08b+fabric
|
||||||
mappings_version=19w34a+build.10
|
maven_group = com.tterrag.blur
|
||||||
|
archives_base_name = Blur
|
||||||
|
|
||||||
# Satin library
|
# Dependencies
|
||||||
satin_version = 1.15-SNAPSHOT
|
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||||
|
fabric_version=0.31.2+1.17
|
||||||
project_id=268324
|
mod_menu_version = 2.0.0-beta.1+build.2
|
||||||
release_type=release
|
satin_version = 1.6.0-nightly.20w48a
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 60 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 63 KiB |
@@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"targets": [
|
|
||||||
"swap"
|
|
||||||
],
|
|
||||||
"passes": [
|
|
||||||
{
|
|
||||||
"name": "fade_in_blur",
|
|
||||||
"intarget": "minecraft:main",
|
|
||||||
"outtarget": "swap",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 1.0, 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ @radius@.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fade_in_blur",
|
|
||||||
"intarget": "swap",
|
|
||||||
"outtarget": "minecraft:main",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 0.0, 1.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ @radius@.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fade_in_blur",
|
|
||||||
"intarget": "minecraft:main",
|
|
||||||
"outtarget": "swap",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 1.0, 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ @radius@.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fade_in_blur",
|
|
||||||
"intarget": "swap",
|
|
||||||
"outtarget": "minecraft:main",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 0.0, 1.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ @radius@.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"pack": {
|
|
||||||
"_comment": "This pack was made for Blur version @mod_version@",
|
|
||||||
"pack_format": @pack_version@,
|
|
||||||
"description": "@description@"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"ultra_lite": {
|
|
||||||
"name": "Ultra Lite",
|
|
||||||
"radius": 2,
|
|
||||||
"description": "Least passes, weakest effect, greatest performance. It's like having a smudge on your glasses."
|
|
||||||
},
|
|
||||||
"lite": {
|
|
||||||
"name": "Lite",
|
|
||||||
"radius": 8,
|
|
||||||
"description": "Less passes, weaker effect, greater performance."
|
|
||||||
},
|
|
||||||
"strong": {
|
|
||||||
"name": "Strong",
|
|
||||||
"radius": 32,
|
|
||||||
"description" : "More passes, stronger effect, lesser performance."
|
|
||||||
},
|
|
||||||
"ultra_strong": {
|
|
||||||
"name": "Ultra Strong",
|
|
||||||
"radius": 64,
|
|
||||||
"description": "Too many passes, strongest effect, worst performance. It's like having Vaseline in your eyes."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +1,34 @@
|
|||||||
package com.tterrag.blur;
|
package com.tterrag.blur;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.tterrag.blur.config.BlurConfig;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.tterrag.blur.config.MidnightConfig;
|
||||||
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
|
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
|
||||||
import ladysnake.satin.api.experimental.managed.Uniform1f;
|
|
||||||
import ladysnake.satin.api.managed.ManagedShaderEffect;
|
import ladysnake.satin.api.managed.ManagedShaderEffect;
|
||||||
import ladysnake.satin.api.managed.ShaderEffectManager;
|
import ladysnake.satin.api.managed.ShaderEffectManager;
|
||||||
|
import ladysnake.satin.api.managed.uniform.Uniform1f;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
|
||||||
|
|
||||||
public class Blur implements ClientModInitializer {
|
public class Blur implements ClientModInitializer {
|
||||||
|
|
||||||
public static final String MODID = "blur";
|
public static final String MODID = "blur";
|
||||||
public static final String MOD_NAME = "Blur";
|
|
||||||
public static final String VERSION = "@VERSION@";
|
|
||||||
|
|
||||||
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;
|
private long start;
|
||||||
|
|
||||||
public ConfigJson configs = new ConfigJson();
|
|
||||||
public int colorFirst, colorSecond;
|
public int colorFirst, colorSecond;
|
||||||
|
|
||||||
private final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"),
|
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");
|
private final Uniform1f blurProgress = blur.findUniform1f("Progress");
|
||||||
|
|
||||||
public static final Blur INSTANCE = new Blur();
|
public static final Blur INSTANCE = new Blur();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
File configFile = new File(FabricLoader.getInstance().getConfigDirectory(), Blur.MODID + ".json");
|
MidnightConfig.init("blur", BlurConfig.class);
|
||||||
try {
|
|
||||||
if (!configFile.exists()) {
|
|
||||||
configFile.getParentFile().mkdirs();
|
|
||||||
Files.write(configFile.toPath(), new GsonBuilder().setPrettyPrinting().create().toJson(configs).getBytes(), StandardOpenOption.CREATE_NEW);
|
|
||||||
} else {
|
|
||||||
configs = new Gson().fromJson(new FileReader(configFile), ConfigJson.class);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
colorFirst = Integer.parseUnsignedInt(configs.gradientStartColor, 16);
|
|
||||||
colorSecond = Integer.parseUnsignedInt(configs.gradientEndColor, 16);
|
|
||||||
ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
|
ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
|
||||||
if (start > 0) {
|
if (start > 0) {
|
||||||
blurProgress.set(getProgress());
|
blurProgress.set(getProgress());
|
||||||
@@ -68,23 +37,27 @@ public class Blur implements ClientModInitializer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean doFade = false;
|
||||||
public void onScreenChange(Screen newGui) {
|
public void onScreenChange(Screen newGui) {
|
||||||
if (MinecraftClient.getInstance().world != null) {
|
if (MinecraftClient.getInstance().world != null) {
|
||||||
boolean excluded = newGui == null || ArrayUtils.contains(configs.blurExclusions, newGui.getClass().getName());
|
boolean excluded = newGui == null || ArrayUtils.contains(BlurConfig.blurExclusions, newGui.getClass().getName());
|
||||||
if (!excluded) {
|
if (!excluded) {
|
||||||
|
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();
|
start = System.currentTimeMillis();
|
||||||
|
doFade = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
start = -1;
|
start = -1;
|
||||||
|
doFade = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRadius() {
|
|
||||||
return configs.radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float getProgress() {
|
private float getProgress() {
|
||||||
return Math.min((System.currentTimeMillis() - start) / (float) configs.fadeTimeMillis, 1);
|
return Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBackgroundColor(boolean second) {
|
public int getBackgroundColor(boolean second) {
|
||||||
|
|||||||
16
src/main/java/com/tterrag/blur/config/BlurConfig.java
Normal file
16
src/main/java/com/tterrag/blur/config/BlurConfig.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.tterrag.blur.config;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screen.ChatScreen;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
293
src/main/java/com/tterrag/blur/config/MidnightConfig.java
Normal file
293
src/main/java/com/tterrag/blur/config/MidnightConfig.java
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
package com.tterrag.blur.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.tterrag.blur.Blur;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.screen.ScreenTexts;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import net.minecraft.client.resource.language.I18n;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.*;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
// MidnightConfig v0.1.0 - Modified for Blur //
|
||||||
|
|
||||||
|
/* Based on https://github.com/Minenash/TinyConfig
|
||||||
|
Credits to Minenash - CC0-1.0
|
||||||
|
You can copy this class to get a standalone version of MidnightConfig */
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public class MidnightConfig {
|
||||||
|
|
||||||
|
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
|
||||||
|
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||||
|
|
||||||
|
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||||
|
|
||||||
|
protected static class EntryInfo {
|
||||||
|
Field field;
|
||||||
|
Object widget;
|
||||||
|
int width;
|
||||||
|
Method dynamicTooltip;
|
||||||
|
Map.Entry<TextFieldWidget,Text> error;
|
||||||
|
Object defaultValue;
|
||||||
|
Object value;
|
||||||
|
String tempValue;
|
||||||
|
boolean inLimits = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class configClass;
|
||||||
|
private static String translationPrefix;
|
||||||
|
private static Path path;
|
||||||
|
|
||||||
|
private static final Gson gson = new GsonBuilder()
|
||||||
|
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||||
|
.excludeFieldsWithModifiers(Modifier.PRIVATE)
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public static void init(String modid, Class<?> config) {
|
||||||
|
translationPrefix = modid + ".midnightconfig.";
|
||||||
|
path = FabricLoader.getInstance().getConfigDir().resolve(modid + ".json");
|
||||||
|
configClass = config;
|
||||||
|
|
||||||
|
for (Field field : config.getFields()) {
|
||||||
|
Class<?> type = field.getType();
|
||||||
|
EntryInfo info = new EntryInfo();
|
||||||
|
|
||||||
|
Entry e;
|
||||||
|
try { e = field.getAnnotation(Entry.class); }
|
||||||
|
catch (Exception ignored) { continue; }
|
||||||
|
|
||||||
|
info.width = e.width();
|
||||||
|
info.field = field;
|
||||||
|
|
||||||
|
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true);
|
||||||
|
else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false);
|
||||||
|
else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true);
|
||||||
|
else if (type == boolean.class) {
|
||||||
|
Function<Object,Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
||||||
|
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||||
|
info.value = !(Boolean) info.value;
|
||||||
|
button.setMessage(func.apply(info.value));
|
||||||
|
}, func);
|
||||||
|
}
|
||||||
|
else if (type.isEnum()) {
|
||||||
|
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||||
|
Function<Object,Text> func = value -> new TranslatableText(translationPrefix + "enum." + type.getSimpleName() + "." + info.value.toString());
|
||||||
|
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object,Text>>( button -> {
|
||||||
|
int index = values.indexOf(info.value) + 1;
|
||||||
|
info.value = values.get(index >= values.size()? 0 : index);
|
||||||
|
button.setMessage(func.apply(info.value));
|
||||||
|
}, func);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
entries.add(info);
|
||||||
|
|
||||||
|
try { info.defaultValue = field.get(null); }
|
||||||
|
catch (IllegalAccessException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
info.dynamicTooltip = config.getMethod(e.dynamicTooltip());
|
||||||
|
info.dynamicTooltip.setAccessible(true);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try { gson.fromJson(Files.newBufferedReader(path), config); }
|
||||||
|
catch (Exception e) { write(); }
|
||||||
|
|
||||||
|
for (EntryInfo info : entries) {
|
||||||
|
try {
|
||||||
|
info.value = info.field.get(null);
|
||||||
|
info.tempValue = info.value.toString();
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
|
||||||
|
boolean isNumber = pattern != null;
|
||||||
|
info.widget = (BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) (t, b) -> s -> {
|
||||||
|
s = s.trim();
|
||||||
|
if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Number value = 0;
|
||||||
|
boolean inLimits = false;
|
||||||
|
System.out.println(((isNumber ^ s.isEmpty())));
|
||||||
|
System.out.println(!s.equals("-") && !s.equals("."));
|
||||||
|
info.error = null;
|
||||||
|
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".") && Double.parseDouble(s) < 999999999) {
|
||||||
|
value = f.apply(s);
|
||||||
|
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
|
||||||
|
info.error = inLimits? null : new AbstractMap.SimpleEntry<>(t, new LiteralText(value.doubleValue() < min ?
|
||||||
|
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
|
||||||
|
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
|
||||||
|
}
|
||||||
|
|
||||||
|
info.tempValue = s;
|
||||||
|
t.setEditableColor(inLimits? 0xFFFFFFFF : 0xFFFF7777);
|
||||||
|
info.inLimits = inLimits;
|
||||||
|
b.active = entries.stream().allMatch(e -> e.inLimits);
|
||||||
|
|
||||||
|
if (inLimits)
|
||||||
|
info.value = isNumber? value : s;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write() {
|
||||||
|
try {
|
||||||
|
if (!Files.exists(path)) Files.createFile(path);
|
||||||
|
Files.write(path, gson.toJson(configClass.newInstance()).getBytes());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen getScreen(Screen parent) {
|
||||||
|
return new TinyConfigScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TinyConfigScreen extends Screen {
|
||||||
|
protected TinyConfigScreen(Screen parent) {
|
||||||
|
super(new TranslatableText(MidnightConfig.translationPrefix + "title"));
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
private final Screen parent;
|
||||||
|
|
||||||
|
// Real Time config update //
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
for (EntryInfo info : entries)
|
||||||
|
try { info.field.set(null, info.value); }
|
||||||
|
catch (IllegalAccessException ignore) {}
|
||||||
|
Blur.INSTANCE.onScreenChange(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.addButton(new ButtonWidget(this.width / 2 - 154, this.height - 28, 150, 20, ScreenTexts.CANCEL, button -> {
|
||||||
|
try { gson.fromJson(Files.newBufferedReader(path), configClass); }
|
||||||
|
catch (Exception e) { write(); }
|
||||||
|
|
||||||
|
for (EntryInfo info : entries) {
|
||||||
|
try {
|
||||||
|
info.value = info.field.get(null);
|
||||||
|
info.tempValue = info.value.toString();
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException ignored) {}
|
||||||
|
}
|
||||||
|
Objects.requireNonNull(client).openScreen(parent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
ButtonWidget done = this.addButton(new ButtonWidget(this.width / 2 + 4, this.height - 28, 150, 20, ScreenTexts.DONE, (button) -> {
|
||||||
|
for (EntryInfo info : entries)
|
||||||
|
try { info.field.set(null, info.value); }
|
||||||
|
catch (IllegalAccessException ignore) {}
|
||||||
|
write();
|
||||||
|
Objects.requireNonNull(client).openScreen(parent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
int y = 45;
|
||||||
|
for (EntryInfo info : entries) {
|
||||||
|
addButton(new ButtonWidget(width - 155, y, 40,20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
|
||||||
|
info.value = info.defaultValue;
|
||||||
|
info.tempValue = info.value.toString();
|
||||||
|
Objects.requireNonNull(client).openScreen(this);
|
||||||
|
})));
|
||||||
|
|
||||||
|
if (info.widget instanceof Map.Entry) {
|
||||||
|
Map.Entry<ButtonWidget.PressAction,Function<Object,Text>> widget = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.widget;
|
||||||
|
addButton(new ButtonWidget(width-110,y,info.width,20, widget.getValue().apply(info.value), widget.getKey()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TextFieldWidget widget = addButton(new TextFieldWidget(textRenderer, width-110, y, info.width, 20, null));
|
||||||
|
widget.setText(info.tempValue);
|
||||||
|
|
||||||
|
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget,done);
|
||||||
|
|
||||||
|
widget.setTextPredicate(processor);
|
||||||
|
|
||||||
|
children.add(widget);
|
||||||
|
}
|
||||||
|
y += 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
int aniX = this.width / 2;
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
this.renderBackground(matrices);
|
||||||
|
|
||||||
|
if (aniX < this.width / 2) {
|
||||||
|
aniX = aniX +40;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stringWidth = (int) (title.getString().length() * 2.75f);
|
||||||
|
this.fillGradient(matrices, this.width / 2 - stringWidth, 10, this.width /2 + stringWidth, 29, -1072689136, -804253680);
|
||||||
|
if (client.world == null) {
|
||||||
|
this.fillGradient(matrices, this.width / 2 - aniX, 35, width / 2 + aniX, this.height - 40, -1072689136, -804253680);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
|
||||||
|
|
||||||
|
int y = 40;
|
||||||
|
for (EntryInfo info : entries) {
|
||||||
|
drawTextWithShadow(matrices, textRenderer, new TranslatableText(translationPrefix + info.field.getName()), 12, y + 10, 0xFFFFFF);
|
||||||
|
|
||||||
|
if (info.error != null && info.error.getKey().isMouseOver(mouseX,mouseY))
|
||||||
|
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||||
|
else if (mouseY >= y && mouseY < (y + 25)) {
|
||||||
|
if (info.dynamicTooltip != null) {
|
||||||
|
try {
|
||||||
|
renderTooltip(matrices, (List<Text>) info.dynamicTooltip.invoke(null, entries), mouseX, mouseY);
|
||||||
|
y += 25;
|
||||||
|
continue;
|
||||||
|
} catch (Exception e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
String key = translationPrefix + info.field.getName() + ".tooltip";
|
||||||
|
if (I18n.hasTranslation(key)) {
|
||||||
|
List<Text> list = new ArrayList<>();
|
||||||
|
for (String str : I18n.translate(key).split("\n"))
|
||||||
|
list.add(new LiteralText(str));
|
||||||
|
renderTooltip(matrices, list, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y += 25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface Entry {
|
||||||
|
String dynamicTooltip() default "";
|
||||||
|
int width() default 100;
|
||||||
|
double min() default Double.MIN_NORMAL;
|
||||||
|
double max() default Double.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.tterrag.blur.config;
|
||||||
|
|
||||||
|
import io.github.prospector.modmenu.api.ConfigScreenFactory;
|
||||||
|
import io.github.prospector.modmenu.api.ModMenuApi;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public class ModMenuIntegration implements ModMenuApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return parent -> new BlurConfig().getScreen(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ public class MixinMinecraftClient {
|
|||||||
at = @At(value = "FIELD",
|
at = @At(value = "FIELD",
|
||||||
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
||||||
opcode = Opcodes.PUTFIELD))
|
opcode = Opcodes.PUTFIELD))
|
||||||
public void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
private void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
||||||
Blur.INSTANCE.onScreenChange(newScreen);
|
Blur.INSTANCE.onScreenChange(newScreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ import net.minecraft.client.gui.screen.Screen;
|
|||||||
public class MixinScreen {
|
public class MixinScreen {
|
||||||
|
|
||||||
@ModifyConstant(
|
@ModifyConstant(
|
||||||
method = "renderBackground(I)V",
|
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||||
constant = @Constant(intValue = -1072689136))
|
constant = @Constant(intValue = -1072689136))
|
||||||
public int getFirstBackgroundColor(int color) {
|
private int getFirstBackgroundColor(int color) {
|
||||||
return Blur.INSTANCE.getBackgroundColor(false);
|
return Blur.INSTANCE.getBackgroundColor(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModifyConstant(
|
@ModifyConstant(
|
||||||
method = "renderBackground(I)V",
|
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||||
constant = @Constant(intValue = -804253680))
|
constant = @Constant(intValue = -804253680))
|
||||||
public int getSecondBackgroundColor(int color) {
|
private int getSecondBackgroundColor(int color) {
|
||||||
return Blur.INSTANCE.getBackgroundColor(true);
|
return Blur.INSTANCE.getBackgroundColor(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 18 KiB |
7
src/main/resources/assets/blur/lang/de_de.json
Normal file
7
src/main/resources/assets/blur/lang/de_de.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"blur.midnightconfig.title": "Blur Konfiguration",
|
||||||
|
"blur.midnightconfig.fadeTimeMillis": "Überblendzeit (in Millisekunden)",
|
||||||
|
"blur.midnightconfig.radius": "Radius",
|
||||||
|
"blur.midnightconfig.gradientStartColor": "Farbverlauf-Anfangsfarbe",
|
||||||
|
"blur.midnightconfig.gradientEndColor": "Farbverlauf-Endfarbe"
|
||||||
|
}
|
||||||
7
src/main/resources/assets/blur/lang/en_gb.json
Normal file
7
src/main/resources/assets/blur/lang/en_gb.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"blur.midnightconfig.title": "Blur Config",
|
||||||
|
"blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)",
|
||||||
|
"blur.midnightconfig.radius": "Radius",
|
||||||
|
"blur.midnightconfig.gradientStartColor": "Gradient Start Colour",
|
||||||
|
"blur.midnightconfig.gradientEndColor": "Gradient End Colour"
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"blur.config.title": "Blur Config"
|
"blur.midnightconfig.title": "Blur Config",
|
||||||
|
"blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)",
|
||||||
|
"blur.midnightconfig.radius": "Radius",
|
||||||
|
"blur.midnightconfig.gradientStartColor": "Gradient Start Color",
|
||||||
|
"blur.midnightconfig.gradientEndColor": "Gradient End Color"
|
||||||
}
|
}
|
||||||
7
src/main/resources/assets/blur/lang/zh_cn.json
Normal file
7
src/main/resources/assets/blur/lang/zh_cn.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"blur.midnightconfig.title": "模糊配置",
|
||||||
|
"blur.midnightconfig.fadeTimeMillis": "淡入时间(毫秒)",
|
||||||
|
"blur.midnightconfig.radius": "半径",
|
||||||
|
"blur.midnightconfig.gradientStartColor": "渐变起始色",
|
||||||
|
"blur.midnightconfig.gradientEndColor": "渐变结束色"
|
||||||
|
}
|
||||||
@@ -1,28 +1,30 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "blur",
|
"id": "blur",
|
||||||
"name": "Blur",
|
"name": "Blur (Fabric)",
|
||||||
"version": "$version",
|
"version": "2.1.0",
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/blur/icon.png",
|
"icon": "assets/blur/icon.png",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"client": [
|
||||||
"com.tterrag.blur.Blur::INSTANCE"
|
"com.tterrag.blur.Blur::INSTANCE"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"com.tterrag.blur.config.ModMenuIntegration"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://minecraft.curseforge.com/projects/blur",
|
"homepage": "https://www.curseforge.com/minecraft/mc-mods/blur-fabric",
|
||||||
"issues": "https://github.com/tterrag1098/Blur/issues"
|
"issues": "https://github.com/Motschen/Blur/issues"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
"tterrag1098"
|
"tterrag1098",
|
||||||
|
"Pyrofab",
|
||||||
|
"Motschen"
|
||||||
],
|
],
|
||||||
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
|
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"mixins.blur.json"
|
"mixins.blur.json"
|
||||||
],
|
]
|
||||||
"custom": {
|
|
||||||
"modmenu:clientsideOnly": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user