Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat with ModernKeybinding #7

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dependencies {}
dependencies {
compileOnly(rfg.deobf("curse.maven:modern-keybinding-686846:4034361")) { transitive = false }
}
17 changes: 14 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true

# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
Expand Down Expand Up @@ -85,6 +85,11 @@ accessTransformersFile = controlling_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false

# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false

Expand Down Expand Up @@ -117,9 +122,15 @@ minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true

# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true

# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
# list of strings, with the acceptable keys being(case does not matter):
# cursemaven
# modrinth
excludeWellKnownRepositories =

# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26'
}


5 changes: 5 additions & 0 deletions src/main/java/com/blamejared/controlling/Controlling.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

import com.blamejared.controlling.events.ClientEventHandler;

import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = "controlling", name = "Controlling", version = "GRADLETOKEN_VERSION", acceptableRemoteVersions = "*")
public class Controlling {

public static boolean isModernKeybindingInstalled = false;

@Mod.EventHandler
private void init(final FMLInitializationEvent event) {
if (event.getSide().isClient()) {
isModernKeybindingInstalled = Loader.isModLoaded("mkb");

MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import org.lwjgl.input.Keyboard;

import com.blamejared.controlling.Controlling;
import committee.nova.mkb.api.IKeyBinding;
import committee.nova.mkb.keybinding.KeyModifier;

import cpw.mods.fml.client.config.GuiCheckBox;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -216,9 +220,16 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
boolean flag = false;

for (KeyBinding keybinding : this.options.keyBindings) {
if (keybinding.getKeyCode() != keybinding.getKeyCodeDefault()) {
flag = true;
break;
if (Controlling.isModernKeybindingInstalled && keybinding instanceof IKeyBinding modernKB) {
if (!modernKB.isSetToDefaultValue()) {
flag = true;
break;
}
} else {
if (keybinding.getKeyCode() != keybinding.getKeyCodeDefault()) {
flag = true;
break;
}
}
}

Expand Down Expand Up @@ -266,7 +277,11 @@ protected void actionPerformed(GuiButton button) {
button.displayString = StatCollector.translateToLocal("controls.resetAll");

for (KeyBinding keyBinding : mc.gameSettings.keyBindings) {
keyBinding.setKeyCode(keyBinding.getKeyCodeDefault());
if (Controlling.isModernKeybindingInstalled && keyBinding instanceof IKeyBinding modernKB) {
modernKB.setToDefault();
} else {
keyBinding.setKeyCode(keyBinding.getKeyCodeDefault());
}
}
KeyBinding.resetKeyBindingArrayAndHash();
} else if (button.id == SHOW_UNBOUD_BUTTON_ID) {
Expand Down Expand Up @@ -307,6 +322,9 @@ protected void actionPerformed(GuiButton button) {
@Override
public void mouseClicked(int mx, int my, int mb) {
if (this.buttonId != null) {
if (Controlling.isModernKeybindingInstalled && this.buttonId instanceof IKeyBinding modernKB) {
modernKB.setKeyModifierAndCode(KeyModifier.getActiveModifier(), -100 + mb);
}
this.options.setOptionKeyBinding(this.buttonId, -100 + mb);
this.buttonId = null;
KeyBinding.resetKeyBindingArrayAndHash();
Expand Down Expand Up @@ -374,14 +392,29 @@ protected void superSuperMouseReleased(int mouseX, int mouseY, int state) {
@Override
public void keyTyped(char typedChar, int keyCode) {
if (this.buttonId != null) {
if (Controlling.isModernKeybindingInstalled && this.buttonId instanceof IKeyBinding modernKB) {
if (keyCode == Keyboard.KEY_ESCAPE) {
modernKB.setKeyModifierAndCode(KeyModifier.NONE, Keyboard.KEY_NONE);
} else if (keyCode != Keyboard.KEY_NONE) {
modernKB.setKeyModifierAndCode(KeyModifier.getActiveModifier(), keyCode);
} else if (typedChar > 0) {
modernKB.setKeyModifierAndCode(KeyModifier.getActiveModifier(), typedChar + 256);
}
}

if (keyCode == Keyboard.KEY_ESCAPE) {
this.options.setOptionKeyBinding(this.buttonId, Keyboard.KEY_NONE);
} else if (keyCode != Keyboard.KEY_NONE) {
this.options.setOptionKeyBinding(this.buttonId, keyCode);
} else if (typedChar > 0) {
this.options.setOptionKeyBinding(this.buttonId, typedChar + 256);
}
this.buttonId = null;

// logic - if modern keybinding is not installed, or the key pressed was not a modifier
if (!Controlling.isModernKeybindingInstalled || !KeyModifier.isKeyCodeModifier(keyCode)) {
this.buttonId = null;
}

this.field_152177_g = Minecraft.getSystemTime();
KeyBinding.resetKeyBindingArrayAndHash();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import org.apache.commons.lang3.ArrayUtils;

import com.blamejared.controlling.Controlling;
import committee.nova.mkb.api.IKeyBinding;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -197,20 +200,30 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight

this.btnChangeKeyBinding.xPosition = x + 105;
this.btnChangeKeyBinding.yPosition = y;
this.btnChangeKeyBinding.displayString = GameSettings.getKeyDisplayString(this.keybinding.getKeyCode());
this.btnChangeKeyBinding.displayString = Controlling.isModernKeybindingInstalled
&& keybinding instanceof IKeyBinding modernKB ? modernKB.getDisplayName()
: GameSettings.getKeyDisplayString(this.keybinding.getKeyCode());

boolean hasConflict = false;
boolean modConflict = true; // less severe form of conflict, like SHIFT conflicting with SHIFT+G

if (this.keybinding.getKeyCode() != 0) {
for (KeyBinding key : mc.gameSettings.keyBindings) {
if (key != this.keybinding && this.keybinding.getKeyCode() == key.getKeyCode()) {
hasConflict = true;
break;
if (key != this.keybinding) {
if (Controlling.isModernKeybindingInstalled && key instanceof IKeyBinding modernKB
&& keybinding instanceof IKeyBinding modernKB2
&& modernKB.conflicts(keybinding)) {
hasConflict = true;
modConflict &= modernKB2.hasKeyCodeModifierConflict(key);
} else if (this.keybinding.getKeyCode() == key.getKeyCode()) {
hasConflict = true;
break;
}
}
}
}

final String displayText = GameSettings.getKeyDisplayString(this.keybinding.getKeyCode());
final String displayText = this.btnChangeKeyBinding.displayString;
final String searchString = controlsScreen.getSearchString();
final int index = this.btnChangeKeyBinding.displayString.toLowerCase().indexOf(searchString.toLowerCase());
final int indexEndHighlight = index + controlsScreen.getSearchString().length();
Expand All @@ -230,8 +243,9 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
prefix = EnumChatFormatting.YELLOW + "> " + EnumChatFormatting.RESET + EnumChatFormatting.UNDERLINE;
suffix = EnumChatFormatting.RESET.toString() + EnumChatFormatting.YELLOW + " <";
} else if (hasConflict) {
prefix = EnumChatFormatting.RED + "[ " + EnumChatFormatting.RESET;
suffix = EnumChatFormatting.RED + " ]";
EnumChatFormatting clr = modConflict ? EnumChatFormatting.GOLD : EnumChatFormatting.RED;
prefix = clr + "[ " + EnumChatFormatting.RESET;
suffix = clr + " ]";
}
Caedis marked this conversation as resolved.
Show resolved Hide resolved
this.btnChangeKeyBinding.displayString = prefix + this.btnChangeKeyBinding.displayString + suffix;

Expand Down Expand Up @@ -273,7 +287,11 @@ public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEven
controlsScreen.buttonId = this.keybinding;
return true;
} else if (this.btnResetKeyBinding.mousePressed(mc, mouseX, mouseY)) {
this.keybinding.setKeyCode(this.keybinding.getKeyCodeDefault());
if (Controlling.isModernKeybindingInstalled && keybinding instanceof IKeyBinding modernKB) {
modernKB.setToDefault();
} else {
this.keybinding.setKeyCode(this.keybinding.getKeyCodeDefault());
}
mc.gameSettings.setOptionKeyBinding(this.keybinding, this.keybinding.getKeyCodeDefault());
KeyBinding.resetKeyBindingArrayAndHash();
return true;
Expand Down