Add config for radius, using a custom resourcepack

This commit is contained in:
tterrag1098
2017-05-29 17:16:00 -04:00
parent 50ce18eacc
commit 558f3c0091
6 changed files with 82 additions and 6 deletions

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip

View File

@@ -7,12 +7,13 @@ import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import com.google.common.base.Throwables;
import com.tterrag.blur.util.ShaderResourcePack;
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.shader.Shader;
import net.minecraft.client.shader.ShaderGroup;
import net.minecraft.client.shader.ShaderUniform;
@@ -48,12 +49,16 @@ public class Blur {
private long start;
private int fadeTime;
public int radius;
private int colorFirst, colorSecond;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
// Add our dummy resourcepack
((List<IResourcePack>)ReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "field_110449_ao", "defaultResourcePacks")).add(new ShaderResourcePack());
config = new Configuration(new File(event.getModConfigurationDirectory(), "blur.cfg"));
saveConfig();
}
@@ -66,6 +71,7 @@ public class Blur {
fadeTime = config.getInt("fadeTime", Configuration.CATEGORY_GENERAL, 200, 0, Integer.MAX_VALUE, "The time it takes for the blur to fade in, in ms.");
radius = config.getInt("radius", Configuration.CATEGORY_GENERAL, 12, 1, 100, "The radius of the blur effect. This controls how \"strong\" the blur is.");
colorFirst = Integer.parseUnsignedInt(
config.getString("gradientStartColor", Configuration.CATEGORY_GENERAL, "75000000", "The start color of the background gradient. Given in ARGB hex."),
16

View File

@@ -0,0 +1,70 @@
package com.tterrag.blur.util;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import java.util.Set;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.data.IMetadataSection;
import net.minecraft.client.resources.data.MetadataSerializer;
import net.minecraft.util.ResourceLocation;
import com.google.common.collect.ImmutableSet;
import com.tterrag.blur.Blur;
public class ShaderResourcePack implements IResourcePack {
protected boolean validPath(ResourceLocation location) {
return location.getResourceDomain().equals("minecraft") && location.getResourcePath().startsWith("shaders/");
}
@Override
public InputStream getInputStream(ResourceLocation location) throws IOException {
if (validPath(location)) {
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 new ByteArrayInputStream(data.toString().getBytes());
}
return null;
}
@Override
public boolean resourceExists(ResourceLocation location) {
return validPath(location) && Blur.class.getResource("/" + location.getResourcePath()) != null;
}
@Override
public Set<String> getResourceDomains() {
return ImmutableSet.of("minecraft");
}
@Override
public <T extends IMetadataSection> T getPackMetadata(
MetadataSerializer metadataSerializer, String metadataSectionName)
throws IOException {
return null;
}
@Override
public BufferedImage getPackImage() throws IOException {
return null;
}
@Override
public String getPackName() {
return "Blur dummy resource pack";
}
}

View File

@@ -14,7 +14,7 @@
},
{
"name": "Radius",
"values": [ 20.0 ]
"values": [ @radius@.0 ]
}
]
},
@@ -29,7 +29,7 @@
},
{
"name": "Radius",
"values": [ 20.0 ]
"values": [ @radius@.0 ]
}
]
},
@@ -44,7 +44,7 @@
},
{
"name": "Radius",
"values": [ 20.0 ]
"values": [ @radius@.0 ]
}
]
},
@@ -59,7 +59,7 @@
},
{
"name": "Radius",
"values": [ 20.0 ]
"values": [ @radius@.0 ]
}
]
}