mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-15 19:25:09 +01:00
Basic port to fabric - no configs yet
This commit is contained in:
53
build.gradle
53
build.gradle
@@ -1,16 +1,17 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
jcenter()
|
||||||
maven { url = "http://files.minecraftforge.net/maven" }
|
maven { url = 'http://maven.modmuss50.me' }
|
||||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
}
|
||||||
}
|
dependencies {
|
||||||
dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' }
|
classpath 'net.fabricmc:fabric-loom:0.1.0-SNAPSHOT'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.9'
|
id 'com.matthewprenger.cursegradle' version '1.0.9'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
apply plugin: 'fabric-loom'
|
||||||
|
|
||||||
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false');
|
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false');
|
||||||
ext.buildnumber = System.getenv().BUILD_NUMBER ?: 'custom';
|
ext.buildnumber = System.getenv().BUILD_NUMBER ?: 'custom';
|
||||||
@@ -23,39 +24,17 @@ sourceCompatibility = '1.8'
|
|||||||
targetCompatibility = '1.8'
|
targetCompatibility = '1.8'
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "${minecraft_version}-${forge_version}"
|
|
||||||
mappings = 'stable_29'
|
|
||||||
|
|
||||||
runDir = 'run'
|
|
||||||
|
|
||||||
clientJvmArgs += '-Dfml.coreMods.load=com.tterrag.blur.BlurPlugin'
|
|
||||||
|
|
||||||
replace "@VERSION@", project.version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
dependencies {
|
||||||
inputs.property "version", project.version
|
minecraft "com.mojang:minecraft:18w49a"
|
||||||
inputs.property "mcversion", project.minecraft.version
|
mappings "net.fabricmc:yarn:18w49a.10"
|
||||||
|
modCompile "net.fabricmc:fabric-loader:0.2.0.62"
|
||||||
|
|
||||||
// replace stuff in mcmod.info, nothing else
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
modCompile "net.fabricmc:fabric:0.1.0.37"
|
||||||
include '**/*.info'
|
|
||||||
include '**/*.properties'
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
|
|
||||||
// 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'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
minecraft_version=1.10.2
|
minecraft_version=1.10.2
|
||||||
forge_version=12.18.3.2297
|
forge_version=12.18.3.2297
|
||||||
mod_version=1.0.4
|
mod_version=1.0.4-fabric
|
||||||
|
|
||||||
project_id=268324
|
project_id=268324
|
||||||
release_type=release
|
release_type=release
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,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-2.14-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
|
||||||
|
|||||||
@@ -1,81 +1,85 @@
|
|||||||
package com.tterrag.blur;
|
package com.tterrag.blur;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.tterrag.blur.mixin.MixinWorldRenderer;
|
||||||
import com.tterrag.blur.util.ShaderResourcePack;
|
import com.tterrag.blur.util.ShaderResourcePack;
|
||||||
|
|
||||||
import static com.tterrag.blur.Blur.*;
|
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.render.WorldRenderer;
|
||||||
|
import net.minecraft.client.resource.ClientResourcePackContainer;
|
||||||
|
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;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
public class Blur implements ModInitializer {
|
||||||
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 MODID = "blur";
|
||||||
public static final String MOD_NAME = "Blur";
|
public static final String MOD_NAME = "Blur";
|
||||||
public static final String VERSION = "@VERSION@";
|
public static final String VERSION = "@VERSION@";
|
||||||
|
|
||||||
@Instance
|
private String[] blurExclusions = new String[] {
|
||||||
public static Blur instance;
|
"net.minecraft.client.gui.ingame.ChatGui"
|
||||||
|
};
|
||||||
public Configuration config;
|
|
||||||
|
|
||||||
private String[] blurExclusions;
|
|
||||||
|
|
||||||
private Field _listShaders;
|
private Field _listShaders;
|
||||||
private long start;
|
private long start;
|
||||||
private int fadeTime;
|
private int fadeTime = 250;
|
||||||
|
|
||||||
public int radius; // Store default so we don't trigger an extra reload
|
public int radius = 10; // Store default so we don't trigger an extra reload
|
||||||
private int colorFirst, colorSecond;
|
public int colorFirst, colorSecond;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public static Blur instance;
|
||||||
public Blur() {
|
|
||||||
((List<IResourcePack>)ReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "field_110449_ao", "defaultResourcePacks")).add(dummyPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
public Blur() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
Field _rps = MinecraftClient.class.getDeclaredField("resourcePackContainerManager");
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
_rps.setAccessible(true);
|
||||||
|
ResourcePackContainerManager<ClientResourcePackContainer> rps = (ResourcePackContainerManager<ClientResourcePackContainer>)_rps.get(MinecraftClient.getInstance());
|
||||||
|
rps.addCreator(new ResourcePackCreator() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
||||||
|
|
||||||
|
T var3 = (T) new ClientResourcePackContainer("blur", true, () -> dummyPack, new StringTextComponent(dummyPack.getName()), new StringTextComponent(dummyPack.getName()), ResourcePackCompatibility.COMPATIBLE, SortingDirection.BOTTOM, true, null);
|
||||||
|
if (var3 != null) {
|
||||||
|
var1.put("blur", var3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
// Add our dummy resourcepack
|
// Add our dummy resourcepack
|
||||||
((SimpleReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener(dummyPack);
|
// ((ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager()).addListener(dummyPack);
|
||||||
|
|
||||||
config = new Configuration(new File(event.getModConfigurationDirectory(), "blur.cfg"));
|
// config = new Configuration(new File(event.getModConfigurationDirectory(), "blur.cfg"));
|
||||||
saveConfig();
|
// saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveConfig() {
|
/* private void saveConfig() {
|
||||||
|
|
||||||
blurExclusions = config.getStringList("guiExclusions", Configuration.CATEGORY_GENERAL, new String[] {
|
blurExclusions = config.getStringList("guiExclusions", Configuration.CATEGORY_GENERAL, new String[] {
|
||||||
GuiChat.class.getName(),
|
GuiChat.class.getName(),
|
||||||
@@ -103,28 +107,32 @@ public class Blur {
|
|||||||
);
|
);
|
||||||
|
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@SubscribeEvent
|
/* @SubscribeEvent
|
||||||
public void onConfigChanged(OnConfigChangedEvent event) {
|
public void onConfigChanged(OnConfigChangedEvent event) {
|
||||||
if (event.getModID().equals(MODID)) {
|
if (event.getModID().equals(MODID)) {
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@SubscribeEvent
|
public void onGuiChange(Gui newGui) {
|
||||||
public void onGuiChange(GuiOpenEvent event) {
|
|
||||||
if (_listShaders == null) {
|
if (_listShaders == null) {
|
||||||
_listShaders = ReflectionHelper.findField(ShaderGroup.class, "field_148031_d", "listShaders");
|
try {
|
||||||
|
_listShaders = class_279.class.getDeclaredField("field_1497");
|
||||||
|
_listShaders.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException | SecurityException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Minecraft.getMinecraft().world != null) {
|
if (MinecraftClient.getInstance().world != null) {
|
||||||
EntityRenderer er = Minecraft.getMinecraft().entityRenderer;
|
WorldRenderer er = MinecraftClient.getInstance().worldRenderer;
|
||||||
boolean excluded = event.getGui() == null || ArrayUtils.contains(blurExclusions, event.getGui().getClass().getName());
|
boolean excluded = newGui == null || ArrayUtils.contains(blurExclusions, newGui.getClass().getName());
|
||||||
if (!er.isShaderActive() && !excluded) {
|
if (!er.method_3175() && !excluded) {
|
||||||
er.loadShader(new ResourceLocation("shaders/post/fade_in_blur.json"));
|
((MixinWorldRenderer)er).invokeLoadShader(new Identifier("shaders/post/fade_in_blur.json"));
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
} else if (er.isShaderActive() && excluded) {
|
} else if (er.method_3175() && excluded) {
|
||||||
er.stopUseShader();
|
er.method_3207();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,17 +141,16 @@ public class Blur {
|
|||||||
return Math.min((System.currentTimeMillis() - start) / (float) fadeTime, 1);
|
return Math.min((System.currentTimeMillis() - start) / (float) fadeTime, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
public void onPostRenderTick() {
|
||||||
public void onRenderTick(RenderTickEvent event) {
|
if (MinecraftClient.getInstance().currentGui != null && MinecraftClient.getInstance().worldRenderer.method_3175()) {
|
||||||
if (event.phase == Phase.END && Minecraft.getMinecraft().currentScreen != null && Minecraft.getMinecraft().entityRenderer.isShaderActive()) {
|
class_279 sg = MinecraftClient.getInstance().worldRenderer.method_3183();
|
||||||
ShaderGroup sg = Minecraft.getMinecraft().entityRenderer.getShaderGroup();
|
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Shader> shaders = (List<Shader>) _listShaders.get(sg);
|
List<Shader> shaders = (List<Shader>) _listShaders.get(sg);
|
||||||
for (Shader s : shaders) {
|
for (Shader s : shaders) {
|
||||||
ShaderUniform su = s.getShaderManager().getShaderUniform("Progress");
|
GlUniform su = s.method_1295().getUniformByName("Progress");
|
||||||
if (su != null) {
|
if (su != null) {
|
||||||
su.set(getProgress());
|
su.method_1251(getProgress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
@@ -152,8 +159,8 @@ public class Blur {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBackgroundColor(boolean second) {
|
public int getBackgroundColor(boolean second) {
|
||||||
int color = second ? instance.colorSecond : instance.colorFirst;
|
int color = second ? colorSecond : colorFirst;
|
||||||
int a = color >>> 24;
|
int a = color >>> 24;
|
||||||
int r = (color >> 16) & 0xFF;
|
int r = (color >> 16) & 0xFF;
|
||||||
int b = (color >> 8) & 0xFF;
|
int b = (color >> 8) & 0xFF;
|
||||||
|
|||||||
@@ -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,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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
27
src/main/java/com/tterrag/blur/mixin/MixinGui.java
Normal file
27
src/main/java/com/tterrag/blur/mixin/MixinGui.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.Gui;
|
||||||
|
|
||||||
|
@Mixin(Gui.class)
|
||||||
|
public class MixinGui {
|
||||||
|
|
||||||
|
@ModifyConstant(
|
||||||
|
method = "drawBackground(I)V",
|
||||||
|
constant = @Constant(intValue = -1072689136))
|
||||||
|
public int getFirstBackgroundColor(int color) {
|
||||||
|
return Blur.instance.colorFirst;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyConstant(
|
||||||
|
method = "drawBackground(I)V",
|
||||||
|
constant = @Constant(intValue = -804253680))
|
||||||
|
public int getSecondBackgroundColor(int color) {
|
||||||
|
return Blur.instance.colorSecond;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.tterrag.blur.Blur;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
|
||||||
|
@Mixin(MinecraftClient.class)
|
||||||
|
public class MixinMinecraftClient {
|
||||||
|
|
||||||
|
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
||||||
|
at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentGui:Lnet/minecraft/client/gui/Gui;", opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||||
|
public void onGuiOpen(Gui newGui, CallbackInfo info) {
|
||||||
|
Blur.instance.onGuiChange(newGui);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "method_1523(Z)V",
|
||||||
|
|
||||||
|
at = @At(value = "INVOKE", target = "net/minecraft/client/toast/ToastManager.draw()V"),
|
||||||
|
require = 1)
|
||||||
|
public void onPostRenderTick(CallbackInfo info) {
|
||||||
|
Blur.instance.onPostRenderTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/main/java/com/tterrag/blur/mixin/MixinWorldRenderer.java
Normal file
15
src/main/java/com/tterrag/blur/mixin/MixinWorldRenderer.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package com.tterrag.blur.mixin;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
@Invoker
|
||||||
|
void invokeLoadShader(Identifier loc);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,40 +1,42 @@
|
|||||||
package com.tterrag.blur.util;
|
package com.tterrag.blur.util;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.tterrag.blur.Blur;
|
import com.tterrag.blur.Blur;
|
||||||
|
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
import net.minecraft.resource.ResourcePack;
|
||||||
import net.minecraft.client.resources.IResourcePack;
|
import net.minecraft.resource.ResourceReloadListener;
|
||||||
import net.minecraft.client.resources.data.IMetadataSection;
|
import net.minecraft.resource.ResourceType;
|
||||||
import net.minecraft.client.resources.data.MetadataSerializer;
|
import net.minecraft.resource.metadata.PackResourceMetadata;
|
||||||
import net.minecraft.client.resources.data.PackMetadataSection;
|
import net.minecraft.resource.metadata.ResourceMetadataReader;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.text.StringTextComponent;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ShaderResourcePack implements IResourcePack, IResourceManagerReloadListener {
|
public class ShaderResourcePack implements ResourcePack, ResourceReloadListener {
|
||||||
|
|
||||||
protected boolean validPath(ResourceLocation location) {
|
protected boolean validPath(Identifier location) {
|
||||||
return location.getResourceDomain().equals("minecraft") && location.getResourcePath().startsWith("shaders/");
|
return location.getNamespace().equals("minecraft") && location.getPath().startsWith("shaders/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<ResourceLocation, String> loadedData = new HashMap<>();
|
private final Map<Identifier, String> loadedData = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream(ResourceLocation location) throws IOException {
|
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
||||||
if (validPath(location)) {
|
if (type == ResourceType.ASSETS && validPath(location)) {
|
||||||
String s = loadedData.computeIfAbsent(location, loc -> {
|
String s = loadedData.computeIfAbsent(location, loc -> {
|
||||||
InputStream in = Blur.class.getResourceAsStream("/" + location.getResourcePath());
|
InputStream in = Blur.class.getResourceAsStream("/" + location.getPath());
|
||||||
StringBuilder data = new StringBuilder();
|
StringBuilder data = new StringBuilder();
|
||||||
Scanner scan = new Scanner(in);
|
Scanner scan = new Scanner(in);
|
||||||
try {
|
try {
|
||||||
@@ -53,37 +55,45 @@ public class ShaderResourcePack implements IResourcePack, IResourceManagerReload
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean resourceExists(ResourceLocation location) {
|
public boolean contains(ResourceType type, Identifier location) {
|
||||||
return validPath(location) && Blur.class.getResource("/" + location.getResourcePath()) != null;
|
return type == ResourceType.ASSETS && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getResourceDomains() {
|
public Set<String> getNamespaces(ResourceType type) {
|
||||||
return ImmutableSet.of("minecraft");
|
return ImmutableSet.of("minecraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "null" })
|
@SuppressWarnings({ "unchecked", "null" })
|
||||||
@Override
|
@Override
|
||||||
public <T extends IMetadataSection> T getPackMetadata(MetadataSerializer metadataSerializer, String metadataSectionName) throws IOException {
|
public <T> T parseMetadata(ResourceMetadataReader<T> var1) throws IOException {
|
||||||
if ("pack".equals(metadataSectionName)) {
|
if ("pack".equals(var1.getKey())) {
|
||||||
return (T) new PackMetadataSection(new TextComponentString("Blur's default shaders"), 3);
|
return (T) new PackResourceMetadata(new StringTextComponent("Blur's default shaders"), 4);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage getPackImage() throws IOException {
|
public String getName() {
|
||||||
throw new FileNotFoundException("pack.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPackName() {
|
|
||||||
return "Blur dummy resource pack";
|
return "Blur dummy resource pack";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
public void onResourceReload(ResourceManager resourceManager) {
|
||||||
loadedData.clear();
|
loadedData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream openRoot(String var1) throws IOException {
|
||||||
|
return open(ResourceType.ASSETS, new Identifier(var1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Identifier> findResources(ResourceType var1, String var2, int var3, Predicate<String> var4) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/main/resources/blur.client.json
Normal file
13
src/main/resources/blur.client.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"package": "com.tterrag.blur.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"mixins": [
|
||||||
|
"MixinGui",
|
||||||
|
"MixinMinecraftClient",
|
||||||
|
"MixinWorldRenderer"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/main/resources/fabric.mod.json
Normal file
10
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"id": "blur",
|
||||||
|
"name": "Blur",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"side": "client",
|
||||||
|
"initializer": "com.tterrag.blur.Blur",
|
||||||
|
"mixins": {
|
||||||
|
"client": "blur.client.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": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
Reference in New Issue
Block a user