mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-16 11:45:09 +01:00
Remove old transformer and tabs->spaces
This commit is contained in:
@@ -40,7 +40,7 @@ public class Blur implements ModInitializer {
|
|||||||
public static final String VERSION = "@VERSION@";
|
public static final String VERSION = "@VERSION@";
|
||||||
|
|
||||||
private String[] blurExclusions = new String[] {
|
private String[] blurExclusions = new String[] {
|
||||||
"net.minecraft.client.gui.ingame.ChatGui"
|
"net.minecraft.client.gui.ingame.ChatGui"
|
||||||
};
|
};
|
||||||
|
|
||||||
private Field _listShaders;
|
private Field _listShaders;
|
||||||
@@ -54,36 +54,35 @@ public class Blur implements ModInitializer {
|
|||||||
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
private ShaderResourcePack dummyPack = new ShaderResourcePack();
|
||||||
|
|
||||||
public static Blur instance;
|
public static Blur instance;
|
||||||
|
|
||||||
public Blur() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
|
||||||
ResourcePackContainerManager<ClientResourcePackContainer> rps = ReflectionHelper.getValue(MinecraftClient.class, MinecraftClient.getInstance(), "field_1715", "resourcePackContainerManager");
|
|
||||||
rps.addCreator(new ResourcePackCreator() {
|
|
||||||
|
|
||||||
@Override
|
public Blur() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||||
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
ResourcePackContainerManager<ClientResourcePackContainer> rps = ReflectionHelper.getValue(MinecraftClient.class, MinecraftClient.getInstance(), "field_1715", "resourcePackContainerManager");
|
||||||
NativeImage img = null;
|
rps.addCreator(new ResourcePackCreator() {
|
||||||
try {
|
|
||||||
img = NativeImage.fromInputStream(dummyPack.openRoot("pack.png"));
|
@Override
|
||||||
} catch (IOException e) {
|
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
||||||
LogManager.getLogger().error("Could not load blur's pack.png", e);
|
NativeImage img = null;
|
||||||
}
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
img = NativeImage.fromInputStream(dummyPack.openRoot("pack.png"));
|
||||||
T var3 = (T) new ClientResourcePackContainer("blur", true, () -> dummyPack,
|
} catch (IOException e) {
|
||||||
new StringTextComponent(dummyPack.getName()), new StringTextComponent("Default shaders for Blur"),
|
LogManager.getLogger().error("Could not load blur's pack.png", e);
|
||||||
ResourcePackCompatibility.COMPATIBLE, SortingDirection.BOTTOM, true, img);
|
}
|
||||||
if (var3 != null) {
|
@SuppressWarnings("unchecked")
|
||||||
var1.put("blur", var3);
|
T var3 = (T) new ClientResourcePackContainer("blur", true, () -> dummyPack, new StringTextComponent(dummyPack.getName()), new StringTextComponent("Default shaders for Blur"),
|
||||||
}
|
ResourcePackCompatibility.COMPATIBLE, SortingDirection.BOTTOM, true, img);
|
||||||
}
|
if (var3 != null) {
|
||||||
});
|
var1.put("blur", var3);
|
||||||
|
}
|
||||||
instance = this;
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {}
|
public void onInitialize() {}
|
||||||
|
|
||||||
public void registerReloadListeners(ReloadableResourceManager manager) {
|
public void registerReloadListeners(ReloadableResourceManager manager) {
|
||||||
manager.addListener(dummyPack);
|
manager.addListener(dummyPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ public class Blur implements ModInitializer {
|
|||||||
*/
|
*/
|
||||||
public void onGuiChange(Gui newGui) {
|
public void onGuiChange(Gui newGui) {
|
||||||
if (_listShaders == null) {
|
if (_listShaders == null) {
|
||||||
_listShaders = ReflectionHelper.getField(class_279.class, "field_1497");
|
_listShaders = ReflectionHelper.getField(class_279.class, "field_1497");
|
||||||
}
|
}
|
||||||
if (MinecraftClient.getInstance().world != null) {
|
if (MinecraftClient.getInstance().world != null) {
|
||||||
WorldRenderer er = MinecraftClient.getInstance().worldRenderer;
|
WorldRenderer er = MinecraftClient.getInstance().worldRenderer;
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -11,17 +11,17 @@ import net.minecraft.client.gui.Gui;
|
|||||||
@Mixin(Gui.class)
|
@Mixin(Gui.class)
|
||||||
public class MixinGui {
|
public class MixinGui {
|
||||||
|
|
||||||
@ModifyConstant(
|
@ModifyConstant(
|
||||||
method = "drawBackground(I)V",
|
method = "drawBackground(I)V",
|
||||||
constant = @Constant(intValue = -1072689136))
|
constant = @Constant(intValue = -1072689136))
|
||||||
public int getFirstBackgroundColor(int color) {
|
public int getFirstBackgroundColor(int color) {
|
||||||
return Blur.instance.colorFirst;
|
return Blur.instance.colorFirst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModifyConstant(
|
@ModifyConstant(
|
||||||
method = "drawBackground(I)V",
|
method = "drawBackground(I)V",
|
||||||
constant = @Constant(intValue = -804253680))
|
constant = @Constant(intValue = -804253680))
|
||||||
public int getSecondBackgroundColor(int color) {
|
public int getSecondBackgroundColor(int color) {
|
||||||
return Blur.instance.colorSecond;
|
return Blur.instance.colorSecond;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,29 +15,29 @@ import net.minecraft.resource.ReloadableResourceManager;
|
|||||||
|
|
||||||
@Mixin(MinecraftClient.class)
|
@Mixin(MinecraftClient.class)
|
||||||
public class MixinMinecraftClient {
|
public class MixinMinecraftClient {
|
||||||
|
|
||||||
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
||||||
at = @At(value = "FIELD",
|
at = @At(value = "FIELD",
|
||||||
target = "net/minecraft/client/MinecraftClient.currentGui : Lnet/minecraft/client/gui/Gui;",
|
target = "net/minecraft/client/MinecraftClient.currentGui : Lnet/minecraft/client/gui/Gui;",
|
||||||
opcode = Opcodes.PUTFIELD))
|
opcode = Opcodes.PUTFIELD))
|
||||||
public void onGuiOpen(Gui newGui, CallbackInfo info) {
|
public void onGuiOpen(Gui newGui, CallbackInfo info) {
|
||||||
Blur.instance.onGuiChange(newGui);
|
Blur.instance.onGuiChange(newGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "method_1523(Z)V",
|
@Inject(method = "method_1523(Z)V",
|
||||||
at = @At(value = "INVOKE",
|
at = @At(value = "INVOKE",
|
||||||
target = "net/minecraft/client/toast/ToastManager.draw()V"),
|
target = "net/minecraft/client/toast/ToastManager.draw()V"),
|
||||||
require = 1)
|
require = 1)
|
||||||
public void onPostRenderTick(CallbackInfo info) {
|
public void onPostRenderTick(CallbackInfo info) {
|
||||||
Blur.instance.onPostRenderTick();
|
Blur.instance.onPostRenderTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "init()V",
|
@Inject(method = "init()V",
|
||||||
at = @At(value = "FIELD",
|
at = @At(value = "FIELD",
|
||||||
target = "net/minecraft/client/MinecraftClient.resourceManager : Lnet/minecraft/resource/ReloadableResourceManager;",
|
target = "net/minecraft/client/MinecraftClient.resourceManager : Lnet/minecraft/resource/ReloadableResourceManager;",
|
||||||
opcode = Opcodes.PUTFIELD,
|
opcode = Opcodes.PUTFIELD,
|
||||||
shift = Shift.AFTER))
|
shift = Shift.AFTER))
|
||||||
public void onResourceManagerAssign(CallbackInfo info) {
|
public void onResourceManagerAssign(CallbackInfo info) {
|
||||||
Blur.instance.registerReloadListeners((ReloadableResourceManager) MinecraftClient.getInstance().getResourceManager());
|
Blur.instance.registerReloadListeners((ReloadableResourceManager) MinecraftClient.getInstance().getResourceManager());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import net.minecraft.util.Identifier;
|
|||||||
|
|
||||||
@Mixin(WorldRenderer.class)
|
@Mixin(WorldRenderer.class)
|
||||||
public interface MixinWorldRenderer {
|
public interface MixinWorldRenderer {
|
||||||
|
|
||||||
@Invoker
|
@Invoker
|
||||||
void invokeLoadShader(Identifier loc);
|
void invokeLoadShader(Identifier loc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,33 +4,33 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ReflectionHelper {
|
public class ReflectionHelper {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T getValue(Class<?> cls, Object instance, String...names) {
|
public static <T> T getValue(Class<?> cls, Object instance, String...names) {
|
||||||
try {
|
try {
|
||||||
return (T) getField(cls, names).get(instance);
|
return (T) getField(cls, names).get(instance);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field getField(Class<?> cls, String... names) {
|
public static Field getField(Class<?> cls, String... names) {
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
Field f = getFieldInternal(cls, name);
|
Field f = getFieldInternal(cls, name);
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not find any of fields " + Arrays.toString(names) + " on class " + cls);
|
throw new IllegalArgumentException("Could not find any of fields " + Arrays.toString(names) + " on class " + cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Field getFieldInternal(Class<?> cls, String name) {
|
private static Field getFieldInternal(Class<?> cls, String name) {
|
||||||
try {
|
try {
|
||||||
Field f = cls.getDeclaredField(name);
|
Field f = cls.getDeclaredField(name);
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
return f;
|
return f;
|
||||||
} catch (NoSuchFieldException | SecurityException e) {
|
} catch (NoSuchFieldException | SecurityException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ import net.minecraft.text.StringTextComponent;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ShaderResourcePack implements ResourcePack, ResourceReloadListener {
|
public class ShaderResourcePack implements ResourcePack, ResourceReloadListener {
|
||||||
|
|
||||||
protected boolean validPath(Identifier location) {
|
protected boolean validPath(Identifier location) {
|
||||||
return location.getNamespace().equals("minecraft") && location.getPath().startsWith("shaders/");
|
return location.getNamespace().equals("minecraft") && location.getPath().startsWith("shaders/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<Identifier, String> loadedData = new HashMap<>();
|
private final Map<Identifier, String> loadedData = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
||||||
if (type == ResourceType.ASSETS && 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.getPath());
|
InputStream in = Blur.class.getResourceAsStream("/" + location.getPath());
|
||||||
@@ -52,47 +52,47 @@ public class ShaderResourcePack implements ResourcePack, ResourceReloadListener
|
|||||||
return new ByteArrayInputStream(s.getBytes());
|
return new ByteArrayInputStream(s.getBytes());
|
||||||
}
|
}
|
||||||
throw new FileNotFoundException(location.toString());
|
throw new FileNotFoundException(location.toString());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(ResourceType type, Identifier location) {
|
|
||||||
return type == ResourceType.ASSETS && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getNamespaces(ResourceType type) {
|
|
||||||
return ImmutableSet.of("minecraft");
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public boolean contains(ResourceType type, Identifier location) {
|
||||||
return "Blur Shaders";
|
return type == ResourceType.ASSETS && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResourceReload(ResourceManager resourceManager) {
|
|
||||||
loadedData.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {}
|
public Set<String> getNamespaces(ResourceType type) {
|
||||||
|
return ImmutableSet.of("minecraft");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings({ "unchecked", "null" })
|
||||||
public InputStream openRoot(String var1) throws IOException {
|
@Override
|
||||||
return Blur.class.getResourceAsStream("/assets/blur/" + var1);
|
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 null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Identifier> findResources(ResourceType var1, String var2, int var3, Predicate<String> var4) {
|
public String getName() {
|
||||||
return Collections.emptyList();
|
return "Blur Shaders";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResourceReload(ResourceManager resourceManager) {
|
||||||
|
loadedData.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream openRoot(String var1) throws IOException {
|
||||||
|
return Blur.class.getResourceAsStream("/assets/blur/" + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Identifier> findResources(ResourceType var1, String var2, int var3, Predicate<String> var4) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user