From fbc2ac5160c1331ac3ec5810fb28c6706500bf9c Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Sun, 19 Mar 2023 13:53:45 +0100 Subject: [PATCH] Update 0.2.1 --- .../foxloader/client/KeyBindingAPI.java | 25 ++++++++++++++++ .../foxloader/client/gui/GuiModList.java | 23 ++++++++------ .../client/gui/GuiModListContainer.java | 2 +- .../client/mixins/MixinGameSettings.java | 28 +++++++++++++++++ .../resources/foxloader.client.mixins.json | 1 + .../foxloader/launcher/LoggerHelper.java | 30 ++++++++++++++++--- .../assets/foxloader/lang/en_US.lang | 1 + gradle.properties | 2 +- 8 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 client/src/main/java/com/fox2code/foxloader/client/KeyBindingAPI.java create mode 100644 client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java diff --git a/client/src/main/java/com/fox2code/foxloader/client/KeyBindingAPI.java b/client/src/main/java/com/fox2code/foxloader/client/KeyBindingAPI.java new file mode 100644 index 0000000..67113d2 --- /dev/null +++ b/client/src/main/java/com/fox2code/foxloader/client/KeyBindingAPI.java @@ -0,0 +1,25 @@ +package com.fox2code.foxloader.client; + +import net.minecraft.src.client.KeyBinding; +import org.apache.commons.lang3.ArrayUtils; + +import java.util.ArrayList; + +public class KeyBindingAPI { + private static final ArrayList registeredKeyBindings = new ArrayList<>(); + private static boolean loaded; + + public static void registerKeyBinding(KeyBinding keyBinding) { + if (loaded) throw new IllegalStateException("Options are already loaded"); + if (registeredKeyBindings.size() >= 9) // This limit will be fixed in future update! + throw new IllegalStateException("Cannot register more than 9 custom key-binds!"); + registeredKeyBindings.add(keyBinding); + } + + public static class Internal { + public static KeyBinding[] inject(KeyBinding[] keyBindings) { + loaded = true; + return ArrayUtils.addAll(keyBindings, registeredKeyBindings.toArray(new KeyBinding[0])); + } + } +} diff --git a/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModList.java b/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModList.java index cdc33a0..77cc4e4 100644 --- a/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModList.java +++ b/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModList.java @@ -1,9 +1,8 @@ package com.fox2code.foxloader.client.gui; -import net.minecraft.src.client.gui.FontRenderer; -import net.minecraft.src.client.gui.GuiButton; -import net.minecraft.src.client.gui.GuiScreen; -import net.minecraft.src.client.gui.StringTranslate; +import com.fox2code.foxloader.loader.ModLoader; +import net.minecraft.src.client.gui.*; +import org.lwjgl.Sys; public class GuiModList extends GuiScreen { private final GuiScreen parent; @@ -18,9 +17,13 @@ public void initGui() { super.initGui(); this.modListContainer = new GuiModListContainer(this); this.modListContainer.registerScrollButtons(this.controlList, 4, 5); - this.controlList.add(new GuiButton(0, - this.width / 2 + 4, this.height - 28, 150, 20, - StringTranslate.getInstance().translateKey("gui.cancel"))); + StringTranslate st = StringTranslate.getInstance(); + this.controlList.add(new GuiSmallButton(0, + this.width / 2 - 154, this.height - 48, + st.translateKey("mods.openFolder"))); + this.controlList.add(new GuiSmallButton(1, + this.width / 2 + 4, this.height - 48, + st.translateKey("gui.done"))); } @Override @@ -32,10 +35,12 @@ public void drawScreen(int var1, int var2, float deltaTicks) { @Override protected void actionPerformed(GuiButton var1) { if (var1.id == 0) { + Sys.openURL("file://" + ModLoader.mods); + } else if (var1.id == 1) { this.mc.displayGuiScreen(this.parent); - return; + } else { + this.modListContainer.actionPerformed(var1); } - this.modListContainer.actionPerformed(var1); } public FontRenderer getFontRenderer() { diff --git a/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModListContainer.java b/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModListContainer.java index 24bcde4..97b567c 100644 --- a/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModListContainer.java +++ b/client/src/main/java/com/fox2code/foxloader/client/gui/GuiModListContainer.java @@ -15,7 +15,7 @@ public GuiModListContainer(GuiModList guiModList) { super(Minecraft.theMinecraft, guiModList.width, guiModList.height, 32, - guiModList.height - 64, 36); + guiModList.height - 51, 36); this.guiModList = guiModList; this.mods = ModLoader.getModContainers().toArray(new ModContainer[0]); } diff --git a/client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java b/client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java new file mode 100644 index 0000000..e5e61fa --- /dev/null +++ b/client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java @@ -0,0 +1,28 @@ +package com.fox2code.foxloader.client.mixins; + +import com.fox2code.foxloader.client.KeyBindingAPI; +import net.minecraft.src.client.GameSettings; +import net.minecraft.src.client.KeyBinding; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GameSettings.class) +public class MixinGameSettings { + @Shadow public KeyBinding[] keyBindings; + + @Redirect(method = "(Lnet/minecraft/client/Minecraft;Ljava/io/File;)V", at = + @At(value = "INVOKE", target = "Lnet/minecraft/src/client/GameSettings;loadOptions()V")) + public void onLoadOptionInit(GameSettings instance) { + this.keyBindings = KeyBindingAPI.Internal.inject(this.keyBindings); + instance.loadOptions(); + } + + @Inject(method = "()V", at = @At("RETURN")) + public void onOptionInit(CallbackInfo ci) { + this.keyBindings = KeyBindingAPI.Internal.inject(this.keyBindings); + } +} diff --git a/client/src/main/resources/foxloader.client.mixins.json b/client/src/main/resources/foxloader.client.mixins.json index 9b82de7..e5975d0 100644 --- a/client/src/main/resources/foxloader.client.mixins.json +++ b/client/src/main/resources/foxloader.client.mixins.json @@ -12,6 +12,7 @@ "MixinEntityClientPlayerMP", "MixinEntityPlayerSP", "MixinEntityRenderer", + "MixinGameSettings", "MixinGuiChat", "MixinGuiContainer", "MixinGuiDebug", diff --git a/common/src/main/java/com/fox2code/foxloader/launcher/LoggerHelper.java b/common/src/main/java/com/fox2code/foxloader/launcher/LoggerHelper.java index 8a6041f..d054b88 100644 --- a/common/src/main/java/com/fox2code/foxloader/launcher/LoggerHelper.java +++ b/common/src/main/java/com/fox2code/foxloader/launcher/LoggerHelper.java @@ -43,20 +43,24 @@ static boolean install(File logFile) { if (installed) { final PrintStream out = System.out; out.flush(); // <- Make sure buffer is flushed - System.setOut(new FoxLoaderLogPrintStream(out, rootLogger, STDOUT)); - System.setErr(new FoxLoaderLogPrintStream(out, rootLogger, STDERR)); + System.setOut(new FoxLoaderLogPrintStream(out, rootLogger, STDOUT, false)); + System.setErr(new FoxLoaderLogPrintStream(out, rootLogger, STDERR, true)); } return installed; } + @SuppressWarnings({"UnnecessaryCallToStringValueOf", "StringOperationCanBeSimplified"}) private static final class FoxLoaderLogPrintStream extends PrintStream { private final Logger rootLogger; private final Level level; + private final boolean doSkips; + private boolean skip; - public FoxLoaderLogPrintStream(@NotNull OutputStream out, Logger rootLogger, Level level) { + public FoxLoaderLogPrintStream(@NotNull OutputStream out, Logger rootLogger, Level level, boolean doSkips) { super(out, true); this.rootLogger = rootLogger; this.level = level; + this.doSkips = doSkips; } @Override @@ -64,6 +68,11 @@ public void println() { this.println(""); } + @Override + public void print(int i) { + this.print(String.valueOf(i)); + } + @Override public void println(@Nullable Object x) { this.println(String.valueOf(x)); @@ -71,9 +80,22 @@ public void println(@Nullable Object x) { @Override public void println(@Nullable String line) { - rootLogger.log(level, line); + if (line == null) line = "null"; + if (doSkips && line.startsWith( // Normal on linux! + "java.io.IOException: Cannot run program \"sensible-browser\"")) { + skip = true; + } else if (skip) { + if (!line.startsWith("\t") && !line.startsWith(" ") + && !line.startsWith("Caused by:")) { + skip = false; + } + } + if (!skip) { + rootLogger.log(level, line); + } } } + private static class FoxLoaderLogFormatter extends SimpleFormatter { private final Date date = new Date(); diff --git a/common/src/main/resources/assets/foxloader/lang/en_US.lang b/common/src/main/resources/assets/foxloader/lang/en_US.lang index f05e6c4..0841b2c 100644 --- a/common/src/main/resources/assets/foxloader/lang/en_US.lang +++ b/common/src/main/resources/assets/foxloader/lang/en_US.lang @@ -2,3 +2,4 @@ chat.link.confirm=Are you sure you want to open the following website? chat.link.warning=Never open links from people that you don't trust! chat.link.open=Open in Browser chat.copy=Copy to Clipboard +mods.openFolder=Open mods folder diff --git a/gradle.properties b/gradle.properties index 6ca1729..9f08aa6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.parallel=true org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8 # FoxLoader properties -foxloader.version=0.2.0 +foxloader.version=0.2.1 foxloader.lastReIndevTransformerChanges=0.2.0 # ReIndev properties