Skip to content

Commit

Permalink
Update 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Mar 19, 2023
1 parent 801508d commit fbc2ac5
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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<KeyBinding> 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]));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "<init>(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 = "<init>()V", at = @At("RETURN"))
public void onOptionInit(CallbackInfo ci) {
this.keyBindings = KeyBindingAPI.Internal.inject(this.keyBindings);
}
}
1 change: 1 addition & 0 deletions client/src/main/resources/foxloader.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"MixinEntityClientPlayerMP",
"MixinEntityPlayerSP",
"MixinEntityRenderer",
"MixinGameSettings",
"MixinGuiChat",
"MixinGuiContainer",
"MixinGuiDebug",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,59 @@ 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
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));
}

@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();

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/foxloader/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fbc2ac5

Please sign in to comment.