mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-16 19:55:10 +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@";
|
||||
|
||||
private String[] blurExclusions = new String[] {
|
||||
"net.minecraft.client.gui.ingame.ChatGui"
|
||||
"net.minecraft.client.gui.ingame.ChatGui"
|
||||
};
|
||||
|
||||
private Field _listShaders;
|
||||
@@ -56,34 +56,33 @@ public class Blur implements ModInitializer {
|
||||
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() {
|
||||
ResourcePackContainerManager<ClientResourcePackContainer> rps = ReflectionHelper.getValue(MinecraftClient.class, MinecraftClient.getInstance(), "field_1715", "resourcePackContainerManager");
|
||||
rps.addCreator(new ResourcePackCreator() {
|
||||
|
||||
@Override
|
||||
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
||||
NativeImage img = null;
|
||||
try {
|
||||
img = NativeImage.fromInputStream(dummyPack.openRoot("pack.png"));
|
||||
} catch (IOException e) {
|
||||
LogManager.getLogger().error("Could not load blur's pack.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);
|
||||
if (var3 != null) {
|
||||
var1.put("blur", var3);
|
||||
}
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public <T extends ResourcePackContainer> void registerContainer(Map<String, T> var1, Factory<T> factory) {
|
||||
NativeImage img = null;
|
||||
try {
|
||||
img = NativeImage.fromInputStream(dummyPack.openRoot("pack.png"));
|
||||
} catch (IOException e) {
|
||||
LogManager.getLogger().error("Could not load blur's pack.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);
|
||||
if (var3 != null) {
|
||||
var1.put("blur", var3);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
instance = this;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize() {}
|
||||
|
||||
public void registerReloadListeners(ReloadableResourceManager manager) {
|
||||
public void registerReloadListeners(ReloadableResourceManager manager) {
|
||||
manager.addListener(dummyPack);
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ public class Blur implements ModInitializer {
|
||||
*/
|
||||
public void onGuiChange(Gui newGui) {
|
||||
if (_listShaders == null) {
|
||||
_listShaders = ReflectionHelper.getField(class_279.class, "field_1497");
|
||||
_listShaders = ReflectionHelper.getField(class_279.class, "field_1497");
|
||||
}
|
||||
if (MinecraftClient.getInstance().world != null) {
|
||||
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)
|
||||
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 = -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;
|
||||
}
|
||||
@ModifyConstant(
|
||||
method = "drawBackground(I)V",
|
||||
constant = @Constant(intValue = -804253680))
|
||||
public int getSecondBackgroundColor(int color) {
|
||||
return Blur.instance.colorSecond;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,28 +16,28 @@ import net.minecraft.resource.ReloadableResourceManager;
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MixinMinecraftClient {
|
||||
|
||||
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
||||
at = @At(value = "FIELD",
|
||||
target = "net/minecraft/client/MinecraftClient.currentGui : Lnet/minecraft/client/gui/Gui;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
public void onGuiOpen(Gui newGui, CallbackInfo info) {
|
||||
Blur.instance.onGuiChange(newGui);
|
||||
}
|
||||
@Inject(method = "openGui(Lnet/minecraft/client/gui/Gui;)V",
|
||||
at = @At(value = "FIELD",
|
||||
target = "net/minecraft/client/MinecraftClient.currentGui : Lnet/minecraft/client/gui/Gui;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
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();
|
||||
}
|
||||
@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();
|
||||
}
|
||||
|
||||
@Inject(method = "init()V",
|
||||
at = @At(value = "FIELD",
|
||||
target = "net/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());
|
||||
}
|
||||
@Inject(method = "init()V",
|
||||
at = @At(value = "FIELD",
|
||||
target = "net/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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.util.Identifier;
|
||||
@Mixin(WorldRenderer.class)
|
||||
public interface MixinWorldRenderer {
|
||||
|
||||
@Invoker
|
||||
void invokeLoadShader(Identifier loc);
|
||||
@Invoker
|
||||
void invokeLoadShader(Identifier loc);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,32 +5,32 @@ import java.util.Arrays;
|
||||
|
||||
public class ReflectionHelper {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getValue(Class<?> cls, Object instance, String...names) {
|
||||
try {
|
||||
return (T) getField(cls, names).get(instance);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getValue(Class<?> cls, Object instance, String...names) {
|
||||
try {
|
||||
return (T) getField(cls, names).get(instance);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> cls, String... names) {
|
||||
for (String name : names) {
|
||||
Field f = getFieldInternal(cls, name);
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find any of fields " + Arrays.toString(names) + " on class " + cls);
|
||||
}
|
||||
public static Field getField(Class<?> cls, String... names) {
|
||||
for (String name : names) {
|
||||
Field f = getFieldInternal(cls, name);
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find any of fields " + Arrays.toString(names) + " on class " + cls);
|
||||
}
|
||||
|
||||
private static Field getFieldInternal(Class<?> cls, String name) {
|
||||
try {
|
||||
Field f = cls.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private static Field getFieldInternal(Class<?> cls, String name) {
|
||||
try {
|
||||
Field f = cls.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ import net.minecraft.util.Identifier;
|
||||
|
||||
public class ShaderResourcePack implements ResourcePack, ResourceReloadListener {
|
||||
|
||||
protected boolean validPath(Identifier location) {
|
||||
return location.getNamespace().equals("minecraft") && location.getPath().startsWith("shaders/");
|
||||
}
|
||||
protected boolean validPath(Identifier location) {
|
||||
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
|
||||
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
||||
@Override
|
||||
public InputStream open(ResourceType type, Identifier location) throws IOException {
|
||||
if (type == ResourceType.ASSETS && validPath(location)) {
|
||||
String s = loadedData.computeIfAbsent(location, loc -> {
|
||||
InputStream in = Blur.class.getResourceAsStream("/" + location.getPath());
|
||||
@@ -52,47 +52,47 @@ public class ShaderResourcePack implements ResourcePack, ResourceReloadListener
|
||||
return new ByteArrayInputStream(s.getBytes());
|
||||
}
|
||||
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
|
||||
public String getName() {
|
||||
return "Blur Shaders";
|
||||
}
|
||||
@Override
|
||||
public boolean contains(ResourceType type, Identifier location) {
|
||||
return type == ResourceType.ASSETS && validPath(location) && Blur.class.getResource("/" + location.getPath()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReload(ResourceManager resourceManager) {
|
||||
loadedData.clear();
|
||||
}
|
||||
@Override
|
||||
public Set<String> getNamespaces(ResourceType type) {
|
||||
return ImmutableSet.of("minecraft");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {}
|
||||
@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
|
||||
public InputStream openRoot(String var1) throws IOException {
|
||||
return Blur.class.getResourceAsStream("/assets/blur/" + var1);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Blur Shaders";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Identifier> findResources(ResourceType var1, String var2, int var3, Predicate<String> var4) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@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