-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
client/src/main/java/com/fox2code/foxloader/client/KeyBindingAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters