mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-16 11:45:09 +01:00
Update to 1.14.4
This commit is contained in:
@@ -1,5 +1,27 @@
|
||||
package com.tterrag.blur;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.tterrag.blur.mixin.MixinGameRenderer;
|
||||
import com.tterrag.blur.util.ReflectionHelper;
|
||||
import com.tterrag.blur.util.ShaderResourcePack;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.GlUniform;
|
||||
import net.minecraft.client.gl.PostProcessShader;
|
||||
import net.minecraft.client.gl.ShaderEffect;
|
||||
import net.minecraft.client.gui.screen.ChatScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.resource.ClientResourcePackContainer;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.resource.ResourcePackContainer.Factory;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
@@ -11,45 +33,14 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
public class Blur implements ClientModInitializer {
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.tterrag.blur.mixin.MixinWorldRenderer;
|
||||
import com.tterrag.blur.util.ReflectionHelper;
|
||||
import com.tterrag.blur.util.ShaderResourcePack;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.class_279;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.GlUniform;
|
||||
import net.minecraft.client.gl.Shader;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ingame.ChatGui;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.client.resource.ClientResourcePackContainer;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.ResourcePackCompatibility;
|
||||
import net.minecraft.resource.ResourcePackContainer;
|
||||
import net.minecraft.resource.ResourcePackContainer.Factory;
|
||||
import net.minecraft.resource.ResourcePackContainer.SortingDirection;
|
||||
import net.minecraft.resource.ResourcePackContainerManager;
|
||||
import net.minecraft.resource.ResourcePackCreator;
|
||||
import net.minecraft.text.StringTextComponent;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class Blur implements ModInitializer {
|
||||
|
||||
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[] { ChatGui.class.getName() };
|
||||
String[] blurExclusions = new String[]{ChatScreen.class.getName()};
|
||||
int fadeTimeMillis = 200;
|
||||
int radius = 8;
|
||||
String gradientStartColor = "75000000";
|
||||
@@ -61,10 +52,9 @@ public class Blur implements ModInitializer {
|
||||
|
||||
public ConfigJson configs = new ConfigJson();
|
||||
public int colorFirst, colorSecond;
|
||||
|
||||
@Nonnull
|
||||
|
||||
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
||||
|
||||
|
||||
public static Blur instance;
|
||||
|
||||
public Blur() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
@@ -75,13 +65,13 @@ public class Blur implements ModInitializer {
|
||||
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
||||
NativeImage img = null;
|
||||
try {
|
||||
img = NativeImage.fromInputStream(dummyPack.openRoot("pack.png"));
|
||||
img = NativeImage.read(dummyPack.openRoot("icon.png"));
|
||||
} catch (IOException e) {
|
||||
LogManager.getLogger().error("Could not load blur's pack.png", e);
|
||||
LogManager.getLogger().error("Could not load blur's icon.png", e);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
T var3 = (T) new ClientResourcePackContainer("blur", true, () -> dummyPack, new StringTextComponent(dummyPack.getName()), new StringTextComponent("Default shaders for Blur"),
|
||||
ResourcePackCompatibility.COMPATIBLE, SortingDirection.BOTTOM, true, img);
|
||||
T var3 = (T) new ClientResourcePackContainer("blur", true, () -> dummyPack, new LiteralText(dummyPack.getName()), new LiteralText("Default shaders for Blur"),
|
||||
ResourcePackCompatibility.COMPATIBLE, ResourcePackContainer.InsertionPosition.BOTTOM, true, img);
|
||||
if (var3 != null) {
|
||||
var1.put("blur", var3);
|
||||
}
|
||||
@@ -90,9 +80,9 @@ public class Blur implements ModInitializer {
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
public void onInitializeClient() {
|
||||
Path config = MinecraftClient.getInstance().runDirectory.toPath().resolve(Paths.get("config", "blur.cfg"));
|
||||
File configFile = config.toFile();
|
||||
try {
|
||||
@@ -110,43 +100,43 @@ public class Blur implements ModInitializer {
|
||||
}
|
||||
|
||||
public void registerReloadListeners(ReloadableResourceManager manager) {
|
||||
manager.addListener(dummyPack);
|
||||
manager.addPack(dummyPack);
|
||||
}
|
||||
|
||||
public void onGuiChange(Gui newGui) {
|
||||
public void onScreenChange(Screen newGui) {
|
||||
if (_listShaders == null) {
|
||||
_listShaders = ReflectionHelper.getField(class_279.class, "field_1497");
|
||||
_listShaders = ReflectionHelper.getField(ShaderEffect.class, "field_1497", "passes");
|
||||
}
|
||||
if (MinecraftClient.getInstance().world != null) {
|
||||
WorldRenderer er = MinecraftClient.getInstance().worldRenderer;
|
||||
GameRenderer er = MinecraftClient.getInstance().gameRenderer;
|
||||
boolean excluded = newGui == null || ArrayUtils.contains(configs.blurExclusions, newGui.getClass().getName());
|
||||
if (!er.method_3175() && !excluded) {
|
||||
((MixinWorldRenderer)er).invokeLoadShader(new Identifier("shaders/post/fade_in_blur.json"));
|
||||
if (!er.isShaderEnabled() && !excluded) {
|
||||
((MixinGameRenderer) er).invokeLoadShader(new Identifier("shaders/post/fade_in_blur.json"));
|
||||
start = System.currentTimeMillis();
|
||||
} else if (er.method_3175() && excluded) {
|
||||
er.method_3207();
|
||||
} else if (er.isShaderEnabled() && excluded) {
|
||||
er.disableShader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getRadius() {
|
||||
return configs.radius;
|
||||
}
|
||||
|
||||
|
||||
private float getProgress() {
|
||||
return Math.min((System.currentTimeMillis() - start) / (float) configs.fadeTimeMillis, 1);
|
||||
}
|
||||
|
||||
|
||||
public void onPostRenderTick() {
|
||||
if (MinecraftClient.getInstance().currentGui != null && MinecraftClient.getInstance().worldRenderer.method_3175()) {
|
||||
class_279 sg = MinecraftClient.getInstance().worldRenderer.method_3183();
|
||||
if (MinecraftClient.getInstance().currentScreen != null && MinecraftClient.getInstance().gameRenderer.isShaderEnabled()) {
|
||||
ShaderEffect sg = MinecraftClient.getInstance().gameRenderer.getShader();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Shader> shaders = (List<Shader>) _listShaders.get(sg);
|
||||
for (Shader s : shaders) {
|
||||
GlUniform su = s.method_1295().getUniformByName("Progress");
|
||||
List<PostProcessShader> shaders = (List<PostProcessShader>) _listShaders.get(sg);
|
||||
for (PostProcessShader s : shaders) {
|
||||
GlUniform su = s.getProgram().getUniformByName("Progress");
|
||||
if (su != null) {
|
||||
su.method_1251(getProgress());
|
||||
su.set(getProgress());
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
@@ -154,7 +144,7 @@ public class Blur implements ModInitializer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getBackgroundColor(boolean second) {
|
||||
int color = second ? colorSecond : colorFirst;
|
||||
int a = color >>> 24;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(WorldRenderer.class)
|
||||
public interface MixinWorldRenderer {
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public interface MixinGameRenderer {
|
||||
|
||||
@Invoker
|
||||
void invokeLoadShader(Identifier loc);
|
||||
|
||||
@@ -1,42 +1,40 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MixinMinecraftClient {
|
||||
|
||||
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
||||
|
||||
@Inject(method = "openScreen",
|
||||
at = @At(value = "FIELD",
|
||||
target = "Lnet/minecraft/client/MinecraftClient;currentGui:Lnet/minecraft/client/gui/Gui;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
public void onGuiOpen(Gui newGui, CallbackInfo info) {
|
||||
Blur.instance.onGuiChange(newGui);
|
||||
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
public void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
||||
Blur.instance.onScreenChange(newScreen);
|
||||
}
|
||||
|
||||
@Inject(method = "method_1523(Z)V",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "net/minecraft/client/toast/ToastManager.draw()V"),
|
||||
@Inject(method = "render",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "net/minecraft/client/toast/ToastManager.draw()V"),
|
||||
require = 1)
|
||||
public void onPostRenderTick(CallbackInfo info) {
|
||||
Blur.instance.onPostRenderTick();
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "init()V",
|
||||
at = @At(value = "FIELD",
|
||||
target = "Lnet/minecraft/client/MinecraftClient;resourceManager:Lnet/minecraft/resource/ReloadableResourceManager;",
|
||||
opcode = Opcodes.PUTFIELD,
|
||||
shift = Shift.AFTER))
|
||||
target = "Lnet/minecraft/client/MinecraftClient;resourceManager:Lnet/minecraft/resource/ReloadableResourceManager;",
|
||||
opcode = Opcodes.PUTFIELD,
|
||||
shift = Shift.AFTER))
|
||||
public void onResourceManagerAssign(CallbackInfo info) {
|
||||
Blur.instance.registerReloadListeners((ReloadableResourceManager) MinecraftClient.getInstance().getResourceManager());
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
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.Gui;
|
||||
|
||||
@Mixin(Gui.class)
|
||||
public class MixinGui {
|
||||
@Mixin(Screen.class)
|
||||
public class MixinScreen {
|
||||
|
||||
@ModifyConstant(
|
||||
method = "drawBackground(I)V",
|
||||
method = "renderBackground(I)V",
|
||||
constant = @Constant(intValue = -1072689136))
|
||||
public int getFirstBackgroundColor(int color) {
|
||||
return Blur.instance.getBackgroundColor(false);
|
||||
}
|
||||
|
||||
|
||||
@ModifyConstant(
|
||||
method = "drawBackground(I)V",
|
||||
method = "renderBackground(I)V",
|
||||
constant = @Constant(intValue = -804253680))
|
||||
public int getSecondBackgroundColor(int color) {
|
||||
return Blur.instance.getBackgroundColor(true);
|
||||
@@ -1,40 +1,37 @@
|
||||
package com.tterrag.blur.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.tterrag.blur.Blur;
|
||||
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.resource.ResourceReloadListener;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.resource.metadata.PackResourceMetadata;
|
||||
import net.minecraft.resource.metadata.ResourceMetadataReader;
|
||||
import net.minecraft.text.StringTextComponent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ShaderResourcePack implements ResourcePack, ResourceReloadListener {
|
||||
|
||||
|
||||
protected boolean validPath(Identifier location) {
|
||||
return location.getNamespace().equals("minecraft") && location.getPath().startsWith("shaders/");
|
||||
}
|
||||
|
||||
|
||||
private final Map<Identifier, String> loadedData = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
||||
if (type == ResourceType.ASSETS && validPath(location)) {
|
||||
if (type == ResourceType.CLIENT_RESOURCES && validPath(location)) {
|
||||
String s = loadedData.computeIfAbsent(location, loc -> {
|
||||
InputStream in = Blur.class.getResourceAsStream("/" + location.getPath());
|
||||
StringBuilder data = new StringBuilder();
|
||||
@@ -56,7 +53,7 @@ public class ShaderResourcePack implements ResourcePack, ResourceReloadListener
|
||||
|
||||
@Override
|
||||
public boolean contains(ResourceType type, Identifier location) {
|
||||
return type == ResourceType.ASSETS && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
||||
return type == ResourceType.CLIENT_RESOURCES && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,11 +61,11 @@ public class ShaderResourcePack implements ResourcePack, ResourceReloadListener
|
||||
return ImmutableSet.of("minecraft");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "null" })
|
||||
@SuppressWarnings({"unchecked", "null"})
|
||||
@Override
|
||||
public <T> T parseMetadata(ResourceMetadataReader<T> var1) throws IOException {
|
||||
if ("pack".equals(var1.getKey())) {
|
||||
return (T) new PackResourceMetadata(new StringTextComponent("Blur's default shaders"), 4);
|
||||
return (T) new PackResourceMetadata(new LiteralText("Blur's default shaders"), 4);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -77,14 +74,15 @@ public class ShaderResourcePack implements ResourcePack, ResourceReloadListener
|
||||
public String getName() {
|
||||
return "Blur Shaders";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResourceReload(ResourceManager resourceManager) {
|
||||
loadedData.clear();
|
||||
public CompletableFuture<Void> reload(Synchronizer var1, ResourceManager var2, Profiler var3, Profiler var4, Executor var5, Executor var6) {
|
||||
return new CompletableFuture<>().thenRun(loadedData::clear);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {}
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openRoot(String var1) throws IOException {
|
||||
|
||||
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 182 KiB |
@@ -1 +0,0 @@
|
||||
blur.config.title=Blur Config
|
||||
3
src/main/resources/assets/blur/lang/en_us.json
Normal file
3
src/main/resources/assets/blur/lang/en_us.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"blur.config.title": "Blur Config"
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "blur",
|
||||
"name": "Blur",
|
||||
"version": "1.0.0",
|
||||
"side": "client",
|
||||
"initializer": "com.tterrag.blur.Blur",
|
||||
"mixins": {
|
||||
"client": "blur.client.json"
|
||||
"version": "$version",
|
||||
"environment": "client",
|
||||
"license": "MIT",
|
||||
"icon": "assets/blur/icon.png",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"com.tterrag.blur.Blur"
|
||||
]
|
||||
},
|
||||
"contact": {
|
||||
"homepage": "https://minecraft.curseforge.com/projects/blur",
|
||||
"issues": "https://github.com/tterrag1098/Blur/issues"
|
||||
},
|
||||
"authors": [
|
||||
"tterrag1098"
|
||||
],
|
||||
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
|
||||
"mixins": [
|
||||
"mixins.blur.json"
|
||||
],
|
||||
"custom": {
|
||||
"modmenu:clientsideOnly": true
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
"required": true,
|
||||
"package": "com.tterrag.blur.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinGui",
|
||||
"client": [
|
||||
"MixinScreen",
|
||||
"MixinMinecraftClient",
|
||||
"MixinWorldRenderer"
|
||||
"MixinGameRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
Reference in New Issue
Block a user