mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-17 04:05:10 +01:00
Add config for radius, using a custom resourcepack
This commit is contained in:
70
src/main/java/com/tterrag/blur/util/ShaderResourcePack.java
Normal file
70
src/main/java/com/tterrag/blur/util/ShaderResourcePack.java
Normal 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";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user