mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-15 19:25:09 +01:00
Compare commits
25 Commits
1.0.6-1.16
...
v2.0.0-1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
432934b056 | ||
|
|
f8a4dd71fd | ||
|
|
d117c98de2 | ||
|
|
fd84d68897 | ||
|
|
7e8194a529 | ||
|
|
28a8530c52 | ||
|
|
cb98527f94 | ||
|
|
3cf6a03361 | ||
|
|
d1d9468482 | ||
|
|
a7c8ff7526 | ||
|
|
c4e1d33ade | ||
|
|
fd386e7585 | ||
|
|
978380b6fd | ||
|
|
e983ab5dee | ||
|
|
19085b6496 | ||
|
|
a6d95dbb45 | ||
|
|
7ee13a4435 | ||
|
|
4dc9e52793 | ||
|
|
f28de240fe | ||
|
|
0450c9238a | ||
|
|
65d9375bfe | ||
|
|
3bffe56f39 | ||
|
|
12c5daa5f6 | ||
|
|
20fdff17ff | ||
|
|
a75f9f8570 |
74
build.gradle
74
build.gradle
@@ -1,61 +1,57 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = "http://files.minecraftforge.net/maven" }
|
||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
}
|
||||
dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' }
|
||||
}
|
||||
plugins {
|
||||
id 'com.matthewprenger.cursegradle' version '1.0.9'
|
||||
id 'java'
|
||||
id 'maven-publish'
|
||||
id 'idea'
|
||||
id 'eclipse'
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0'
|
||||
id 'fabric-loom' version '0.4-SNAPSHOT'
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false');
|
||||
ext.buildnumber = System.getenv().BUILD_NUMBER ?: 'custom';
|
||||
|
||||
group = 'com.tterrag.blur'
|
||||
archivesBaseName = "Blur"
|
||||
version = "${mod_version}-${buildnumber}"
|
||||
version = "${mod_version}-${minecraft_version}+fabric"
|
||||
|
||||
sourceCompatibility = '1.8'
|
||||
targetCompatibility = '1.8'
|
||||
|
||||
minecraft {
|
||||
version = "${minecraft_version}-${forge_version}"
|
||||
mappings = 'stable_29'
|
||||
|
||||
runDir = 'run'
|
||||
}
|
||||
|
||||
clientJvmArgs += '-Dfml.coreMods.load=com.tterrag.blur.BlurPlugin'
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${mappings_version}"
|
||||
modCompile "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modCompile "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
||||
modCompile "io.github.ladysnake:Satin:${satin_version}"
|
||||
include "io.github.ladysnake:Satin:${satin_version}"
|
||||
|
||||
replace "@VERSION@", project.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'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.minecraft.version
|
||||
inputs.property "version", mod_version
|
||||
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include '**/*.info'
|
||||
include '**/*.properties'
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": mod_version
|
||||
}
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version': project.version, 'mcversion': project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude '**/*.info'
|
||||
exclude '**/*.properties'
|
||||
}
|
||||
}
|
||||
|
||||
jar.manifest {
|
||||
attributes 'FMLCorePlugin': 'com.tterrag.blur.BlurPlugin'
|
||||
attributes 'FMLCorePluginContainsFMLMod': 'true'
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
@@ -85,7 +81,7 @@ task createResourcePacks {
|
||||
|
||||
from ('pack_icons') {
|
||||
include "${pack_id}.png"
|
||||
rename '.+', 'pack.png'
|
||||
rename '.+', 'icon.png'
|
||||
}
|
||||
|
||||
baseName = "Blur " + pack_name
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
minecraft_version=1.10.2
|
||||
forge_version=12.18.3.2297
|
||||
mod_version=1.0.4
|
||||
minecraft_version=1.16.2
|
||||
|
||||
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.5.1
|
||||
|
||||
project_id=268324
|
||||
release_type=release
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
||||
#Wed Aug 20 15:17:58 CDT 2014
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.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."
|
||||
}
|
||||
}
|
||||
12
settings.gradle
Normal file
12
settings.gradle
Normal file
@@ -0,0 +1,12 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "blur"
|
||||
@@ -1,164 +1,80 @@
|
||||
package com.tterrag.blur;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.tterrag.blur.util.ShaderResourcePack;
|
||||
public class Blur implements ClientModInitializer {
|
||||
public static BlurConfig BLUR_CONFIG;
|
||||
|
||||
import static com.tterrag.blur.Blur.*;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiChat;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.client.shader.Shader;
|
||||
import net.minecraft.client.shader.ShaderGroup;
|
||||
import net.minecraft.client.shader.ShaderUniform;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
@Mod(modid = MODID, name = MOD_NAME, version = VERSION, acceptedMinecraftVersions = "[1.9, 1.13)", clientSideOnly = true, guiFactory = "com.tterrag.blur.config.BlurGuiFactory")
|
||||
public class Blur {
|
||||
|
||||
public static final String MODID = "blur";
|
||||
public static final String MOD_NAME = "Blur";
|
||||
public static final String VERSION = "@VERSION@";
|
||||
|
||||
@Instance
|
||||
public static Blur instance;
|
||||
|
||||
public Configuration config;
|
||||
|
||||
private String[] blurExclusions;
|
||||
|
||||
private Field _listShaders;
|
||||
private long start;
|
||||
private int fadeTime;
|
||||
|
||||
public int radius; // Store default so we don't trigger an extra reload
|
||||
private int colorFirst, colorSecond;
|
||||
|
||||
@Nonnull
|
||||
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Blur() {
|
||||
((List<IResourcePack>)ReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "field_110449_ao", "defaultResourcePacks")).add(dummyPack);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
// Add our dummy resourcepack
|
||||
((SimpleReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener(dummyPack);
|
||||
|
||||
config = new Configuration(new File(event.getModConfigurationDirectory(), "blur.cfg"));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
|
||||
blurExclusions = config.getStringList("guiExclusions", Configuration.CATEGORY_GENERAL, new String[] {
|
||||
GuiChat.class.getName(),
|
||||
}, "A list of classes to be excluded from the blur shader.");
|
||||
|
||||
fadeTime = config.getInt("fadeTime", Configuration.CATEGORY_GENERAL, 200, 0, Integer.MAX_VALUE, "The time it takes for the blur to fade in, in ms.");
|
||||
|
||||
int r = config.getInt("radius", Configuration.CATEGORY_GENERAL, 12, 1, 100, "The radius of the blur effect. This controls how \"strong\" the blur is.");
|
||||
if (r != radius) {
|
||||
radius = r;
|
||||
dummyPack.onResourceManagerReload(Minecraft.getMinecraft().getResourceManager());
|
||||
if (Minecraft.getMinecraft().world != null) {
|
||||
Minecraft.getMinecraft().entityRenderer.stopUseShader();
|
||||
}
|
||||
}
|
||||
|
||||
colorFirst = Integer.parseUnsignedInt(
|
||||
config.getString("gradientStartColor", Configuration.CATEGORY_GENERAL, "75000000", "The start color of the background gradient. Given in ARGB hex."),
|
||||
16
|
||||
);
|
||||
|
||||
colorSecond = Integer.parseUnsignedInt(
|
||||
config.getString("gradientEndColor", Configuration.CATEGORY_GENERAL, "75000000", "The end color of the background gradient. Given in ARGB hex."),
|
||||
16
|
||||
);
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(OnConfigChangedEvent event) {
|
||||
if (event.getModID().equals(MODID)) {
|
||||
saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiChange(GuiOpenEvent event) {
|
||||
if (_listShaders == null) {
|
||||
_listShaders = ReflectionHelper.findField(ShaderGroup.class, "field_148031_d", "listShaders");
|
||||
}
|
||||
if (Minecraft.getMinecraft().world != null) {
|
||||
EntityRenderer er = Minecraft.getMinecraft().entityRenderer;
|
||||
boolean excluded = event.getGui() == null || ArrayUtils.contains(blurExclusions, event.getGui().getClass().getName());
|
||||
if (!er.isShaderActive() && !excluded) {
|
||||
er.loadShader(new ResourceLocation("shaders/post/fade_in_blur.json"));
|
||||
start = System.currentTimeMillis();
|
||||
} else if (er.isShaderActive() && excluded) {
|
||||
er.stopUseShader();
|
||||
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()));
|
||||
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();
|
||||
|
||||
ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
|
||||
if (start > 0) {
|
||||
blurProgress.set(getProgress());
|
||||
blur.render(deltaTick);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private float getProgress() {
|
||||
return Math.min((System.currentTimeMillis() - start) / (float) fadeTime, 1);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(RenderTickEvent event) {
|
||||
if (event.phase == Phase.END && Minecraft.getMinecraft().currentScreen != null && Minecraft.getMinecraft().entityRenderer.isShaderActive()) {
|
||||
ShaderGroup sg = Minecraft.getMinecraft().entityRenderer.getShaderGroup();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Shader> shaders = (List<Shader>) _listShaders.get(sg);
|
||||
for (Shader s : shaders) {
|
||||
ShaderUniform su = s.getShaderManager().getShaderUniform("Progress");
|
||||
if (su != null) {
|
||||
su.set(getProgress());
|
||||
}
|
||||
|
||||
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());
|
||||
if (!excluded) {
|
||||
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;
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
Throwables.propagate(e);
|
||||
} else {
|
||||
start = -1;
|
||||
doFade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBackgroundColor(boolean second) {
|
||||
int color = second ? instance.colorSecond : instance.colorFirst;
|
||||
|
||||
public int getRadius() {
|
||||
return BLUR_CONFIG.radius;
|
||||
}
|
||||
|
||||
private float getProgress() {
|
||||
return Math.min((System.currentTimeMillis() - start) / (float) BLUR_CONFIG.fadeTimeMillis, 1);
|
||||
}
|
||||
|
||||
public int getBackgroundColor(boolean second) {
|
||||
int color = second ? colorSecond : colorFirst;
|
||||
int a = color >>> 24;
|
||||
int r = (color >> 16) & 0xFF;
|
||||
int b = (color >> 8) & 0xFF;
|
||||
int g = color & 0xFF;
|
||||
float prog = instance.getProgress();
|
||||
float prog = INSTANCE.getProgress();
|
||||
a *= prog;
|
||||
r *= prog;
|
||||
g *= prog;
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.tterrag.blur;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
|
||||
@IFMLLoadingPlugin.SortingIndex(Integer.MAX_VALUE)
|
||||
public class BlurPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return new String[] { "com.tterrag.blur.BlurTransformer" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.tterrag.blur;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class BlurTransformer implements IClassTransformer {
|
||||
|
||||
private static final String GUI_SCREEN_CLASS_NAME = "net.minecraft.client.gui.GuiScreen";
|
||||
|
||||
private static final String DRAW_WORLD_BAGKGROUND_METHOD = "drawWorldBackground";
|
||||
private static final String DRAW_WORLD_BAGKGROUND_METHOD_OBF = "func_146270_b";
|
||||
|
||||
private static final String BLUR_MAIN_CLASS = "com/tterrag/blur/Blur";
|
||||
private static final String COLOR_HOOK_METHOD_NAME = "getBackgroundColor";
|
||||
private static final String COLOR_HOOK_METHOD_DESC = "(Z)I";
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass) {
|
||||
if (transformedName.equals(GUI_SCREEN_CLASS_NAME)) {
|
||||
System.out.println("Transforming Class [" + transformedName + "], Method [" + DRAW_WORLD_BAGKGROUND_METHOD + "]");
|
||||
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader(basicClass);
|
||||
classReader.accept(classNode, 0);
|
||||
|
||||
Iterator<MethodNode> methods = classNode.methods.iterator();
|
||||
|
||||
while (methods.hasNext()) {
|
||||
MethodNode m = methods.next();
|
||||
if (m.name.equals(DRAW_WORLD_BAGKGROUND_METHOD) || m.name.equals(DRAW_WORLD_BAGKGROUND_METHOD_OBF)) {
|
||||
for (int i = 0; i < m.instructions.size(); i++) {
|
||||
AbstractInsnNode next = m.instructions.get(i);
|
||||
|
||||
// if (next.getOpcode() == Opcodes.INVOKEVIRTUAL && ((MethodInsnNode)next).name.equals(DRAW_GRADIENT_RECT_METHOD_NAME)) {
|
||||
// while (!(next instanceof LabelNode)) {
|
||||
// m.instructions.remove(next);
|
||||
// next = m.instructions.get(--i);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
if (next.getOpcode() == Opcodes.LDC) {
|
||||
System.out.println("Modifying GUI background darkness... ");
|
||||
AbstractInsnNode colorHook = new MethodInsnNode(Opcodes.INVOKESTATIC, BLUR_MAIN_CLASS, COLOR_HOOK_METHOD_NAME, COLOR_HOOK_METHOD_DESC, false);
|
||||
AbstractInsnNode colorHook2 = colorHook.clone(null);
|
||||
|
||||
// Replace LDC with hooks
|
||||
m.instructions.set(next, colorHook);
|
||||
m.instructions.set(colorHook.getNext(), colorHook2);
|
||||
|
||||
// Load boolean constants for method param
|
||||
m.instructions.insertBefore(colorHook, new InsnNode(Opcodes.ICONST_1));
|
||||
m.instructions.insertBefore(colorHook2, new InsnNode(Opcodes.ICONST_0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
classNode.accept(cw);
|
||||
System.out.println("Transforming " + transformedName + " Finished.");
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
}
|
||||
26
src/main/java/com/tterrag/blur/config/BlurConfig.java
Normal file
26
src/main/java/com/tterrag/blur/config/BlurConfig.java
Normal file
@@ -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";
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.tterrag.blur.config;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries;
|
||||
|
||||
public class BlurConfigGui extends GuiConfig {
|
||||
|
||||
public BlurConfigGui(GuiScreen parentScreen) {
|
||||
super(parentScreen, new ConfigElement(Blur.instance.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), Blur.MODID, false, false, I18n.format(Blur.MODID + ".config.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if (this.entryList == null || this.needsRefresh)
|
||||
{
|
||||
this.entryList = new GuiConfigEntries(this, mc) {
|
||||
@SuppressWarnings({ "unused", "null" })
|
||||
@Override
|
||||
protected void drawContainerBackground(@Nonnull Tessellator tessellator) {
|
||||
if (mc.world == null) {
|
||||
super.drawContainerBackground(tessellator);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.needsRefresh = false;
|
||||
}
|
||||
super.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDefaultBackground() {
|
||||
drawWorldBackground(0);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.tterrag.blur.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||
|
||||
public class BlurGuiFactory implements IModGuiFactory {
|
||||
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance) {}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return BlurConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1.12
|
||||
// @Override
|
||||
public boolean hasConfigGui() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 1.12
|
||||
// @Override
|
||||
public GuiScreen createConfigGui(GuiScreen parentScreen) {
|
||||
return new BlurConfigGui(parentScreen);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MixinMinecraftClient {
|
||||
|
||||
@Inject(method = "openScreen",
|
||||
at = @At(value = "FIELD",
|
||||
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
private void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
||||
Blur.INSTANCE.onScreenChange(newScreen);
|
||||
}
|
||||
}
|
||||
27
src/main/java/com/tterrag/blur/mixin/MixinScreen.java
Normal file
27
src/main/java/com/tterrag/blur/mixin/MixinScreen.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
@Mixin(Screen.class)
|
||||
public class MixinScreen {
|
||||
|
||||
@ModifyConstant(
|
||||
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||
constant = @Constant(intValue = -1072689136))
|
||||
private int getFirstBackgroundColor(int color) {
|
||||
return Blur.INSTANCE.getBackgroundColor(false);
|
||||
}
|
||||
|
||||
@ModifyConstant(
|
||||
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||
constant = @Constant(intValue = -804253680))
|
||||
private int getSecondBackgroundColor(int color) {
|
||||
return Blur.INSTANCE.getBackgroundColor(true);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.tterrag.blur.util;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.data.IMetadataSection;
|
||||
import net.minecraft.client.resources.data.MetadataSerializer;
|
||||
import net.minecraft.client.resources.data.PackMetadataSection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
public class ShaderResourcePack implements IResourcePack, IResourceManagerReloadListener {
|
||||
|
||||
protected boolean validPath(ResourceLocation location) {
|
||||
return location.getResourceDomain().equals("minecraft") && location.getResourcePath().startsWith("shaders/");
|
||||
}
|
||||
|
||||
private final Map<ResourceLocation, String> loadedData = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream(ResourceLocation location) throws IOException {
|
||||
if (validPath(location)) {
|
||||
String s = loadedData.computeIfAbsent(location, loc -> {
|
||||
InputStream in = Blur.class.getResourceAsStream("/" + location.getResourcePath());
|
||||
StringBuilder data = new StringBuilder();
|
||||
Scanner scan = new Scanner(in);
|
||||
try {
|
||||
while (scan.hasNextLine()) {
|
||||
data.append(scan.nextLine().replaceAll("@radius@", Integer.toString(Blur.instance.radius))).append('\n');
|
||||
}
|
||||
} finally {
|
||||
scan.close();
|
||||
}
|
||||
return data.toString();
|
||||
});
|
||||
|
||||
return new ByteArrayInputStream(s.getBytes());
|
||||
}
|
||||
throw new FileNotFoundException(location.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation location) {
|
||||
return validPath(location) && Blur.class.getResource("/" + location.getResourcePath()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getResourceDomains() {
|
||||
return ImmutableSet.of("minecraft");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "null" })
|
||||
@Override
|
||||
public <T extends IMetadataSection> T getPackMetadata(MetadataSerializer metadataSerializer, String metadataSectionName) throws IOException {
|
||||
if ("pack".equals(metadataSectionName)) {
|
||||
return (T) new PackMetadataSection(new TextComponentString("Blur's default shaders"), 3);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getPackImage() throws IOException {
|
||||
throw new FileNotFoundException("pack.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackName() {
|
||||
return "Blur dummy resource pack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
loadedData.clear();
|
||||
}
|
||||
|
||||
}
|
||||
BIN
src/main/resources/assets/blur/icon.png
Normal file
BIN
src/main/resources/assets/blur/icon.png
Normal file
Binary file not shown.
|
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 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
blur.config.title=Blur Config
|
||||
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 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
7
src/main/resources/assets/blur/lang/en_us.json
Normal file
7
src/main/resources/assets/blur/lang/en_us.json
Normal file
@@ -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 Color",
|
||||
"text.autoconfig.blur.option.gradientEndColor": "Gradient End Color"
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
],
|
||||
"passes": [
|
||||
{
|
||||
"name": "fade_in_blur",
|
||||
"name": "blur:fade_in_blur",
|
||||
"intarget": "minecraft:main",
|
||||
"outtarget": "swap",
|
||||
"uniforms": [
|
||||
@@ -14,12 +14,12 @@
|
||||
},
|
||||
{
|
||||
"name": "Radius",
|
||||
"values": [ @radius@.0 ]
|
||||
"values": [ 8.0 ]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fade_in_blur",
|
||||
"name": "blur:fade_in_blur",
|
||||
"intarget": "swap",
|
||||
"outtarget": "minecraft:main",
|
||||
"uniforms": [
|
||||
@@ -29,12 +29,12 @@
|
||||
},
|
||||
{
|
||||
"name": "Radius",
|
||||
"values": [ @radius@.0 ]
|
||||
"values": [ 8.0 ]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fade_in_blur",
|
||||
"name": "blur:fade_in_blur",
|
||||
"intarget": "minecraft:main",
|
||||
"outtarget": "swap",
|
||||
"uniforms": [
|
||||
@@ -44,12 +44,12 @@
|
||||
},
|
||||
{
|
||||
"name": "Radius",
|
||||
"values": [ @radius@.0 ]
|
||||
"values": [ 8.0 ]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fade_in_blur",
|
||||
"name": "blur:fade_in_blur",
|
||||
"intarget": "swap",
|
||||
"outtarget": "minecraft:main",
|
||||
"uniforms": [
|
||||
@@ -59,7 +59,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Radius",
|
||||
"values": [ @radius@.0 ]
|
||||
"values": [ 8.0 ]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"dstrgb": "zero"
|
||||
},
|
||||
"vertex": "sobel",
|
||||
"fragment": "fade_in_blur",
|
||||
"fragment": "blur:fade_in_blur",
|
||||
"attributes": [ "Position" ],
|
||||
"samplers": [
|
||||
{ "name": "DiffuseSampler" }
|
||||
30
src/main/resources/fabric.mod.json
Normal file
30
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "blur",
|
||||
"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://www.curseforge.com/minecraft/mc-mods/blur-fabric",
|
||||
"issues": "https://github.com/Motschen/Blur/issues"
|
||||
},
|
||||
"authors": [
|
||||
"tterrag1098",
|
||||
"Pyrofab",
|
||||
"Motschen"
|
||||
],
|
||||
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
|
||||
"mixins": [
|
||||
"mixins.blur.json"
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
[
|
||||
{
|
||||
"modid": "blur",
|
||||
"name": "Blur",
|
||||
"description": "Adds a blurry background when viewing GUIs",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"url": "http://tterrag.com",
|
||||
"updateUrl": "http://ci.tterrag.com/job/BlurBG",
|
||||
"authorList": ["tterrag"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
||||
12
src/main/resources/mixins.blur.json
Normal file
12
src/main/resources/mixins.blur.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.tterrag.blur.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"MixinScreen",
|
||||
"MixinMinecraftClient"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user