-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
7c99dc8
commit 9f929d9
Showing
26 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import com.nomiceu.nomilabs.util.LabsSide | ||
import net.minecraftforge.client.settings.KeyModifier | ||
import org.lwjgl.input.Keyboard | ||
|
||
import static com.nomiceu.nomilabs.groovy.GroovyHelpers.KeyBindingHelpers.* | ||
|
||
// Override Default Keybinds! (Goes in Post Init) | ||
|
||
// Doesn't matter on Server | ||
// IMPORTANT! This stops the script from crashing on servers! | ||
if (LabsSide.isDedicatedServer()) return | ||
|
||
// Change Default Sprint Keybind to 'W' (Same as forwards, essentially toggle-sprint) | ||
addOverride('key.sprint', Keyboard.KEY_W) | ||
|
||
// Change Default Advancements Keybind to None | ||
addOverride('key.advancements', Keyboard.KEY_NONE) | ||
|
||
// Change Drop key to 'CTRL + Q' | ||
addOverride('key.drop', KeyModifier.CONTROL, Keyboard.KEY_Q) |
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/nomiceu/nomilabs/groovy/KeyBindingHelper.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,36 @@ | ||
package com.nomiceu.nomilabs.groovy; | ||
|
||
import com.cleanroommc.groovyscript.api.GroovyBlacklist; | ||
import com.nomiceu.nomilabs.config.LabsConfig; | ||
import com.nomiceu.nomilabs.groovy.mixinhelper.AccessibleKeyBinding; | ||
import com.nomiceu.nomilabs.mixin.KeyBindingAccessor; | ||
import com.nomiceu.nomilabs.tooltip.LabsTooltipHelper; | ||
import com.nomiceu.nomilabs.util.LabsGroovyHelper; | ||
import com.nomiceu.nomilabs.util.LabsTranslate; | ||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import net.minecraftforge.client.settings.KeyModifier; | ||
|
||
@GroovyBlacklist | ||
public class KeyBindingHelper { | ||
public static void drawKeybindingTooltip(int mouseX, int mouseY, FontRenderer fontRenderer, KeyBinding keybinding) { | ||
fontRenderer.drawString(LabsTranslate.translate(keybinding.getKeyCategory()), mouseX + 10, mouseY, 0xFFFFFF); | ||
var spacing = fontRenderer.FONT_HEIGHT; | ||
var currentSpacing = spacing; | ||
if (LabsTooltipHelper.isShiftDown() && LabsConfig.advanced.controlMenuTooltipSettings.showID) { | ||
fontRenderer.drawString(keybinding.getKeyDescription(), mouseX + 10, mouseY + spacing, 0x808080); | ||
currentSpacing += spacing; | ||
} | ||
if (LabsTooltipHelper.isCtrlDown() && LabsConfig.advanced.controlMenuTooltipSettings.showClass) | ||
fontRenderer.drawString(keybinding.getClass().getName(), mouseX + 10, mouseY + currentSpacing, 0x505050); | ||
} | ||
|
||
public static void addKeybindOverride(String id, KeyModifier modifier, int keyCode) { | ||
if (!KeyBindingAccessor.getKeybindRegistry().containsKey(id)) { | ||
LabsGroovyHelper.throwOrGroovyLog(new IllegalArgumentException("Keybind with ID " + id + " was not found!")); | ||
return; | ||
} | ||
((AccessibleKeyBinding) KeyBindingAccessor.getKeybindRegistry().get(id)) | ||
.setDefaultKeyModifierAndCode(modifier, keyCode); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/AccessibleKeyBinding.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,7 @@ | ||
package com.nomiceu.nomilabs.groovy.mixinhelper; | ||
|
||
import net.minecraftforge.client.settings.KeyModifier; | ||
|
||
public interface AccessibleKeyBinding { | ||
void setDefaultKeyModifierAndCode(KeyModifier modifier, int keyCode); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/nomiceu/nomilabs/mixin/GuiKeyBindingListAccessor.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,12 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiKeyBindingList; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(GuiKeyBindingList.class) | ||
public interface GuiKeyBindingListAccessor { | ||
@Accessor(value = "mc") | ||
Minecraft getMc(); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/nomiceu/nomilabs/mixin/GuiKeyBindingListKeyEntryMixin.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,34 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import com.nomiceu.nomilabs.groovy.KeyBindingHelper; | ||
import net.minecraft.client.gui.GuiKeyBindingList; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.callback.CallbackInfo; | ||
|
||
/** | ||
* Allows a tooltip over each keybind, stating the category and id. | ||
*/ | ||
@Mixin(GuiKeyBindingList.KeyEntry.class) | ||
public abstract class GuiKeyBindingListKeyEntryMixin { | ||
@Shadow(aliases = "this$0") | ||
@Final | ||
GuiKeyBindingList this$0; | ||
|
||
@Shadow | ||
@Final | ||
private KeyBinding keybinding; | ||
|
||
@Inject(method = "drawEntry", at = @At("TAIL")) | ||
public void drawTooltips(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks, CallbackInfo ci) { | ||
if (mouseY >= y && mouseY <= y + slotHeight) { | ||
var fontRenderer = ((GuiKeyBindingListAccessor) this$0).getMc().fontRenderer; | ||
|
||
KeyBindingHelper.drawKeybindingTooltip(mouseX, mouseY, fontRenderer, keybinding); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/nomiceu/nomilabs/mixin/KeyBindingAccessor.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,16 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import net.minecraft.client.settings.KeyBinding; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(KeyBinding.class) | ||
public interface KeyBindingAccessor { | ||
@Accessor(value = "KEYBIND_ARRAY") | ||
static Map<String, KeyBinding> getKeybindRegistry() { | ||
throw new NotImplementedException("KeyBindingAccessor Failed to Apply!"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/nomiceu/nomilabs/mixin/KeyBindingMixin.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,33 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import com.nomiceu.nomilabs.groovy.mixinhelper.AccessibleKeyBinding; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import net.minecraftforge.client.settings.KeyModifier; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
/** | ||
* Allows Setting of Default Key Codes and Modifies. | ||
*/ | ||
@Mixin(KeyBinding.class) | ||
public abstract class KeyBindingMixin implements AccessibleKeyBinding { | ||
@Shadow | ||
@Final | ||
@Mutable | ||
private int keyCodeDefault; | ||
|
||
@Shadow | ||
private KeyModifier keyModifierDefault; | ||
|
||
@Shadow | ||
public abstract void setKeyModifierAndCode(KeyModifier keyModifier, int keyCode); | ||
|
||
@Override | ||
public void setDefaultKeyModifierAndCode(KeyModifier modifier, int keyCode) { | ||
keyCodeDefault = keyCode; | ||
keyModifierDefault = modifier; | ||
setKeyModifierAndCode(modifier, keyCode); | ||
} | ||
} |
Oops, something went wrong.