mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-08-17 16:31:49 +02:00
Compare commits
22 Commits
forge/1.15
...
fabric/1.1
Author | SHA1 | Date | |
---|---|---|---|
d416883dbb | |||
681fd75997 | |||
04408ddfb1 | |||
15e314eb73 | |||
b292a3b621 | |||
4248293230 | |||
9634c33ca2 | |||
54a6b4ea56 | |||
9437932b97 | |||
50c035bb91 | |||
81e135469e | |||
188f66b4d3 | |||
ab4fa452f7 | |||
116bbe241d | |||
9baa7c4460 | |||
7f258966de | |||
9af10ad04c | |||
6e316eff89 | |||
21ee424cef | |||
c7c5b67c3b | |||
06b2782372 | |||
83b2dfdfa5 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -24,10 +24,6 @@ bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# forge
|
||||
|
||||
logs/
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
||||
|
@@ -27,15 +27,12 @@ You can also bind a key that resets all **Toggle Keybinds** at once. That makes
|
||||
|
||||
#### Flying
|
||||
|
||||
* **Double Tap 'Jump' To Fly** can be turned off to prevent accidental flight toggling.
|
||||
* **Disable Flight Inertia** stops you instantly when you stop holding movement keys.
|
||||
* **Sprint Key Mode While Flying** changes how the Sprint key behaves during flight.
|
||||
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
||||
* **Fly On Ground** lets you fly while touching the ground in creative mode (and also lets you stop flying by tapping Sneak while touching the ground).
|
||||
* **Flight Speed Multiplier** (0.25x - 8x) changes how fast you fly in creative and spectator mode.
|
||||
* **Vertical Speed Boost** (up to +300%) adds additional vertical speed boost while flying in creative and spectator mode.
|
||||
|
||||
Both speed boosts can be configured separately for sprinting, which will be active when the Sprint key is held. Unlike in vanilla, the sprinting flight boost works in all directions.
|
||||
|
||||
## Installation
|
||||
|
||||
The following mod loaders are supported:
|
||||
|
117
build.gradle
117
build.gradle
@@ -1,100 +1,41 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url = 'https://files.minecraftforge.net/maven' }
|
||||
maven { url = "https://repo.spongepowered.org/maven" }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
|
||||
classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7-SNAPSHOT'
|
||||
}
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.5-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "https://maven.tterrag.com/"
|
||||
}
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
def mcversion = "1.15.2"
|
||||
def forgeversion = "31.2.45"
|
||||
|
||||
def prefixName = 'displayName = '
|
||||
def prefixVersion = 'version = '
|
||||
|
||||
def metaLines = file('src/main/resources/META-INF/mods.toml').readLines()
|
||||
def metaName = metaLines.find { line -> line.startsWith(prefixName) }.substring(prefixName.length())[1..-2]
|
||||
def metaVersion = metaLines.find { line -> line.startsWith(prefixVersion) }.substring(prefixVersion.length())[1..-2]
|
||||
|
||||
group = 'chylex.bettercontrols'
|
||||
version = metaVersion
|
||||
archivesBaseName = metaName.replaceAll('\\s', '')
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'snapshot', version: '20201030-1.15.1'
|
||||
|
||||
runs {
|
||||
client {
|
||||
workingDirectory file('run')
|
||||
|
||||
property 'mixin.env.disableRefMap', 'true'
|
||||
arg '-mixin.config=bettercontrols.mixins.json'
|
||||
|
||||
mods {
|
||||
bettercontrols {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory file('run')
|
||||
|
||||
property 'mixin.env.disableRefMap', 'true'
|
||||
arg '-mixin.config=bettercontrols.mixins.json'
|
||||
|
||||
mods {
|
||||
bettercontrols {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
dependencies {
|
||||
minecraft 'net.minecraftforge:forge:' + mcversion + '-' + forgeversion
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveName = archivesBaseName + '-' + mcversion + '-v' + version + '.jar'
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
from('./') {
|
||||
include 'LICENSE'
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
manifest {
|
||||
attributes([
|
||||
'Specification-Title' : 'bettercontrols',
|
||||
'Specification-Version' : '1',
|
||||
'Specification-Vendor' : 'chylex',
|
||||
|
||||
'Implementation-Title' : metaName,
|
||||
'Implementation-Version' : metaVersion,
|
||||
'Implementation-Vendor' : 'chylex',
|
||||
|
||||
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
|
||||
'MixinConfigs' : 'bettercontrols.mixins.json'
|
||||
])
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
|
||||
finalizedBy('reobfJar')
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
version = 'v' + version
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
exclude "io/github/prospector/"
|
||||
}
|
||||
|
@@ -1,4 +1,15 @@
|
||||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
minecraft_version=1.15.2
|
||||
yarn_mappings=1.15.2+build.17
|
||||
loader_version=0.10.2+build.210
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.2.0
|
||||
maven_group=chylex.bettercontrols
|
||||
archives_base_name=BetterControls-1.15.x
|
||||
|
||||
# https://fabricmc.net/use
|
||||
# https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
|
||||
|
53
gradlew
vendored
53
gradlew
vendored
@@ -1,5 +1,21 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
@@ -66,6 +82,7 @@ esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
@@ -109,10 +126,11 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
@@ -138,19 +156,19 @@ if $cygwin ; then
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -159,14 +177,9 @@ save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -1,3 +1,19 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
@@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%*
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
|
10
settings.gradle
Normal file
10
settings.gradle
Normal file
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
@@ -1,33 +1,11 @@
|
||||
package chylex.bettercontrols;
|
||||
import chylex.bettercontrols.config.BetterControlsConfig;
|
||||
import chylex.bettercontrols.gui.BetterControlsScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ExtensionPoint;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.minecraftforge.fml.network.FMLNetworkConstants;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
@Mod("bettercontrols")
|
||||
public final class BetterControlsMod{
|
||||
public static final BetterControlsConfig config = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> ClientLoader::loadConfig);
|
||||
public final class BetterControlsMod implements ClientModInitializer{
|
||||
public static final BetterControlsConfig config = BetterControlsConfig.load(FabricLoader.getInstance().getConfigDir().resolve("BetterControls.json"));
|
||||
|
||||
public BetterControlsMod(){
|
||||
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> ClientLoader::createScreen);
|
||||
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));
|
||||
}
|
||||
|
||||
private static final class ClientLoader {
|
||||
public static BetterControlsConfig loadConfig() {
|
||||
return BetterControlsConfig.load(FMLPaths.CONFIGDIR.get().resolve("BetterControls.json"));
|
||||
}
|
||||
|
||||
public static BetterControlsScreen createScreen(final Minecraft mc, final Screen parentScreen) {
|
||||
return new BetterControlsScreen(parentScreen);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onInitializeClient(){}
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package chylex.bettercontrols.compatibility;
|
||||
import chylex.bettercontrols.gui.BetterControlsScreen;
|
||||
import io.github.prospector.modmenu.api.ConfigScreenFactory;
|
||||
import io.github.prospector.modmenu.api.ModMenuApi;
|
||||
|
||||
public class ModMenuSupport implements ModMenuApi{
|
||||
@Override
|
||||
public String getModId(){
|
||||
return "bettercontrols";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory(){
|
||||
return BetterControlsScreen::new;
|
||||
}
|
||||
}
|
@@ -12,14 +12,14 @@ import chylex.bettercontrols.input.ModifierKey;
|
||||
import chylex.bettercontrols.input.SprintMode;
|
||||
import chylex.bettercontrols.util.Key;
|
||||
import chylex.bettercontrols.util.LiteralText;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.SettingsScreen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.gui.screen.options.GameOptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -32,7 +32,7 @@ import static chylex.bettercontrols.gui.elements.TextWidget.CENTER;
|
||||
import static chylex.bettercontrols.util.LiteralText.text;
|
||||
import static chylex.bettercontrols.util.Statics.OPTIONS;
|
||||
|
||||
public class BetterControlsScreen extends SettingsScreen{
|
||||
public class BetterControlsScreen extends GameOptionsScreen{
|
||||
public static final LiteralText TITLE = text("Better Controls");
|
||||
|
||||
private static final int BOTTOM_PADDING = 3;
|
||||
@@ -48,7 +48,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
|
||||
// Options
|
||||
|
||||
private int generateSprintingOptions(int y, final List<IGuiEventListener> elements){
|
||||
private int generateSprintingOptions(int y, final List<Element> elements){
|
||||
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||
|
||||
generateKeyBindingWithModifierOption(y, elements, text("Toggle Sprint"), cfg.keyToggleSprint);
|
||||
@@ -72,7 +72,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
return y;
|
||||
}
|
||||
|
||||
private int generateSneakingOptions(int y, final List<IGuiEventListener> elements){
|
||||
private int generateSneakingOptions(int y, final List<Element> elements){
|
||||
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||
|
||||
generateKeyBindingWithModifierOption(y, elements, text("Toggle Sneak"), cfg.keyToggleSneak);
|
||||
@@ -87,7 +87,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
||||
private int generateFlightOptions(int y, final List<IGuiEventListener> elements){
|
||||
private int generateFlightOptions(int y, final List<Element> elements){
|
||||
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||
|
||||
final List<Option<Float>> flightSpeedOptions = Arrays.asList(
|
||||
@@ -172,7 +172,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
return y;
|
||||
}
|
||||
|
||||
private int generateMiscellaneousOptions(int y, final List<IGuiEventListener> elements){
|
||||
private int generateMiscellaneousOptions(int y, final List<Element> elements){
|
||||
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||
|
||||
generateKeyBindingWithModifierOption(y, elements, text("Toggle Walk Forwards"), cfg.keyToggleWalkForward);
|
||||
@@ -202,7 +202,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
new Option<>(ModifierKey.ALT, text("Alt"))
|
||||
);
|
||||
|
||||
private void generateKeyBindingWithModifierOption(final int y, final List<IGuiEventListener> elements, final LiteralText text, final KeyBindingWithModifier binding){
|
||||
private void generateKeyBindingWithModifierOption(final int y, final List<Element> elements, final LiteralText text, final KeyBindingWithModifier binding){
|
||||
final CycleButtonWidget<ModifierKey> modifierButton = new CycleButtonWidget<>(col4(2), y, COL4_W, MODIFIER_OPTIONS, binding.getModifier(), binding::setModifier);
|
||||
final KeyBindingWidget bindingButton = new KeyBindingWidget(col4(3), y, COL4_W, binding, this::startEditingKeyBinding);
|
||||
bindingButton.linkButtonToBoundState(modifierButton);
|
||||
@@ -213,7 +213,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
allKeyBindings.add(bindingButton);
|
||||
}
|
||||
|
||||
private static void generateLeftSideText(final int y, final List<IGuiEventListener> elements, final LiteralText text){
|
||||
private static void generateLeftSideText(final int y, final List<Element> elements, final LiteralText text){
|
||||
elements.add(new TextWidget(col2(0), y, COL2_W - TEXT_PADDING_RIGHT, text));
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
private KeyBindingWidget editingKeyBinding;
|
||||
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
|
||||
|
||||
public BetterControlsScreen(@Nullable final Screen parentScreen){
|
||||
public BetterControlsScreen(final Screen parentScreen){
|
||||
super(parentScreen, OPTIONS, TITLE);
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
public void init(){
|
||||
allKeyBindings.clear();
|
||||
|
||||
final List<IGuiEventListener> elements = new ArrayList<>();
|
||||
final List<Element> elements = new ArrayList<>();
|
||||
int y = 0;
|
||||
|
||||
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Sprinting"), CENTER));
|
||||
@@ -246,7 +246,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER));
|
||||
y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
||||
|
||||
addButton(new Button(width / 2 - 99, height - 29, 200, 20, I18n.format("gui.done"), btn -> minecraft.displayGuiScreen(parentScreen)));
|
||||
addButton(new ButtonWidget(width / 2 - 99, height - 29, 200, 20, I18n.translate("gui.done"), btn -> minecraft.openScreen(parent)));
|
||||
children.add(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
public void render(final int mouseX, final int mouseY, final float delta){
|
||||
renderBackground();
|
||||
optionsWidget.render(mouseX, mouseY, delta);
|
||||
drawCenteredString(font, title.getString(), width / 2, 8, (255 << 16) | (255 << 8) | 255);
|
||||
drawCenteredString(font, title.asFormattedString(), width / 2, 8, (255 << 16) | (255 << 8) | 255);
|
||||
super.render(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
|
||||
private void onKeyBindingEditingFinished(){
|
||||
editingKeyBinding = null;
|
||||
KeyBinding.resetKeyBindingArrayAndHash();
|
||||
KeyBinding.updateKeysByCode();
|
||||
|
||||
for(final KeyBindingWidget widget : allKeyBindings){
|
||||
widget.updateKeyBindingText();
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package chylex.bettercontrols.gui;
|
||||
import chylex.bettercontrols.gui.OptionListWidget.Entry;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.gui.IRenderable;
|
||||
import net.minecraft.client.gui.widget.list.AbstractOptionList;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -11,7 +12,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
public final class OptionListWidget extends AbstractOptionList<Entry>{
|
||||
public final class OptionListWidget extends ElementListWidget<Entry>{
|
||||
public static final int ROW_WIDTH = 408;
|
||||
public static final int ROW_PADDING = 2;
|
||||
|
||||
@@ -26,19 +27,19 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
|
||||
return (column * ROW_WIDTH) / 4;
|
||||
}
|
||||
|
||||
private static Offset getElementOffset(final IGuiEventListener element){
|
||||
private static Offset getElementOffset(final Element element){
|
||||
if (element instanceof Widget){
|
||||
return new Offset(((Widget)element).getX(), ((Widget)element).getY());
|
||||
}
|
||||
else if (element instanceof net.minecraft.client.gui.widget.Widget){
|
||||
return new Offset(((net.minecraft.client.gui.widget.Widget)element).x, ((net.minecraft.client.gui.widget.Widget)element).y);
|
||||
else if (element instanceof AbstractButtonWidget){
|
||||
return new Offset(((AbstractButtonWidget)element).x, ((AbstractButtonWidget)element).y);
|
||||
}
|
||||
else{
|
||||
return new Offset(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Widget extends IGuiEventListener, IRenderable{
|
||||
public interface Widget extends Element, Drawable{
|
||||
int getX();
|
||||
int getY();
|
||||
void setX(int x);
|
||||
@@ -55,7 +56,7 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
|
||||
}
|
||||
}
|
||||
|
||||
public OptionListWidget(final int top, final int bottom, final int width, final int height, final List<IGuiEventListener> widgets, final int innerHeight){
|
||||
public OptionListWidget(final int top, final int bottom, final int width, final int height, final List<Element> widgets, final int innerHeight){
|
||||
super(MINECRAFT, width, height, top, bottom, innerHeight);
|
||||
addEntry(new Entry(widgets));
|
||||
}
|
||||
@@ -75,27 +76,27 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
|
||||
return (width + ROW_WIDTH) / 2 + 4;
|
||||
}
|
||||
|
||||
protected static final class Entry extends AbstractOptionList.Entry<Entry>{
|
||||
private final List<IGuiEventListener> elements;
|
||||
private final Map<IGuiEventListener, Offset> offsets;
|
||||
protected static final class Entry extends ElementListWidget.Entry<Entry>{
|
||||
private final List<Element> elements;
|
||||
private final Map<Element, Offset> offsets;
|
||||
|
||||
public Entry(final List<IGuiEventListener> elements){
|
||||
public Entry(final List<Element> elements){
|
||||
this.elements = new ArrayList<>(elements);
|
||||
this.offsets = elements.stream().collect(Collectors.toMap(Function.identity(), OptionListWidget::getElementOffset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends IGuiEventListener> children(){
|
||||
public List<? extends Element> children(){
|
||||
return Collections.unmodifiableList(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final int index, final int y, final int x, final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean hovered, final float tickDelta){
|
||||
for(final IGuiEventListener element : elements){
|
||||
for(final Element element : elements){
|
||||
final Offset offset = offsets.get(element);
|
||||
|
||||
if (element instanceof net.minecraft.client.gui.widget.Widget){
|
||||
final net.minecraft.client.gui.widget.Widget button = (net.minecraft.client.gui.widget.Widget)element;
|
||||
if (element instanceof AbstractButtonWidget){
|
||||
final AbstractButtonWidget button = (AbstractButtonWidget)element;
|
||||
button.x = x + offset.x;
|
||||
button.y = y + offset.y;
|
||||
}
|
||||
@@ -105,8 +106,8 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
|
||||
widget.setY(y + offset.y);
|
||||
}
|
||||
|
||||
if (element instanceof IRenderable){
|
||||
((IRenderable)element).render(mouseX, mouseY, tickDelta);
|
||||
if (element instanceof Drawable){
|
||||
((Drawable)element).render(mouseX, mouseY, tickDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
package chylex.bettercontrols.gui;
|
||||
import chylex.bettercontrols.mixin.AccessOptionButtonWidgetOption;
|
||||
import chylex.bettercontrols.mixin.AccessScreenButtons;
|
||||
import net.minecraft.client.gui.AccessibilityScreen;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.gui.INestedGuiEventHandler;
|
||||
import net.minecraft.client.gui.screen.ControlsScreen;
|
||||
import net.minecraft.client.gui.widget.button.AbstractButton;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.gui.widget.button.OptionButton;
|
||||
import net.minecraft.client.settings.AbstractOption;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.ParentElement;
|
||||
import net.minecraft.client.gui.screen.options.AccessibilityScreen;
|
||||
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.OptionButtonWidget;
|
||||
import net.minecraft.client.options.Option;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
@@ -16,15 +16,15 @@ import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
public final class ScreenPatcher{
|
||||
private ScreenPatcher(){}
|
||||
|
||||
public static void onControlsScreenOpened(final ControlsScreen screen){
|
||||
public static void onControlsScreenOpened(final ControlsOptionsScreen screen){
|
||||
final AccessScreenButtons accessor = (AccessScreenButtons)screen;
|
||||
|
||||
final List<? extends IGuiEventListener> children = screen.children();
|
||||
final List<AbstractButton> buttons = accessor.getButtons();
|
||||
final List<? extends Element> children = screen.children();
|
||||
final List<AbstractButtonWidget> buttons = accessor.getButtons();
|
||||
|
||||
final AbstractButton autoJump = buttons
|
||||
final AbstractButtonWidget autoJump = buttons
|
||||
.stream()
|
||||
.filter(it -> it instanceof OptionButton && ((AccessOptionButtonWidgetOption)it).getOption() == AbstractOption.AUTO_JUMP)
|
||||
.filter(it -> it instanceof OptionButtonWidget && ((AccessOptionButtonWidgetOption)it).getOption() == Option.AUTO_JUMP)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
@@ -32,31 +32,31 @@ public final class ScreenPatcher{
|
||||
children.remove(autoJump);
|
||||
buttons.remove(autoJump);
|
||||
|
||||
accessor.callAddButton(new Button(autoJump.x, autoJump.y, autoJump.getWidth(), 20, BetterControlsScreen.TITLE.copy().appendText("...").getString(), btn -> {
|
||||
MINECRAFT.displayGuiScreen(new BetterControlsScreen(screen));
|
||||
accessor.callAddButton(new ButtonWidget(autoJump.x, autoJump.y, autoJump.getWidth(), 20, BetterControlsScreen.TITLE.copy().append("...").asFormattedString(), btn -> {
|
||||
MINECRAFT.openScreen(new BetterControlsScreen(screen));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public static void onAccessibilityScreenOpened(final AccessibilityScreen screen){
|
||||
walkChildren(screen.children(), it -> {
|
||||
if (it instanceof OptionButton){
|
||||
final OptionButton button = (OptionButton)it;
|
||||
final AbstractOption option = ((AccessOptionButtonWidgetOption)button).getOption();
|
||||
if (it instanceof OptionButtonWidget){
|
||||
final OptionButtonWidget button = (OptionButtonWidget)it;
|
||||
final Option option = ((AccessOptionButtonWidgetOption)button).getOption();
|
||||
|
||||
if (option == AbstractOption.SPRINT || option == AbstractOption.SNEAK){
|
||||
if (option == Option.SPRINT_TOGGLED || option == Option.SNEAK_TOGGLED){
|
||||
button.active = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void walkChildren(final List<? extends IGuiEventListener> listeners, final Consumer<IGuiEventListener> callback){
|
||||
for(final IGuiEventListener listener : listeners){
|
||||
callback.accept(listener);
|
||||
private static void walkChildren(final List<? extends Element> elements, final Consumer<Element> callback){
|
||||
for(final Element element : elements){
|
||||
callback.accept(element);
|
||||
|
||||
if (listener instanceof INestedGuiEventHandler){
|
||||
walkChildren(((INestedGuiEventHandler)listener).children(), callback);
|
||||
if (element instanceof ParentElement){
|
||||
walkChildren(((ParentElement)element).children(), callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
|
||||
public final class BooleanValueWidget extends Button{
|
||||
public final class BooleanValueWidget extends ButtonWidget{
|
||||
private final BooleanConsumer onChanged;
|
||||
private boolean value;
|
||||
|
||||
public BooleanValueWidget(final int x, final int y, final int width, final int height, final boolean currentValue, final BooleanConsumer onChanged){
|
||||
super(x, y, width, height, I18n.format(currentValue ? "options.on" : "options.off"), ignore -> {});
|
||||
super(x, y, width, height, I18n.translate(currentValue ? "options.on" : "options.off"), ignore -> {});
|
||||
this.value = currentValue;
|
||||
this.onChanged = onChanged;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public final class BooleanValueWidget extends Button{
|
||||
public void onPress(){
|
||||
super.onPress();
|
||||
value = !value;
|
||||
setMessage(I18n.format(value ? "options.on" : "options.off"));
|
||||
setMessage(I18n.translate(value ? "options.on" : "options.off"));
|
||||
onChanged.accept(value);
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CycleButtonWidget<T> extends Button{
|
||||
public class CycleButtonWidget<T> extends ButtonWidget{
|
||||
private final List<Option<T>> options;
|
||||
private final Consumer<T> onChanged;
|
||||
private T selectedValue;
|
||||
|
||||
public CycleButtonWidget(final int x, final int y, final int width, final int height, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged){
|
||||
super(x, y, width, height, Option.find(options, selectedValue).getText().getString(), btn -> {});
|
||||
super(x, y, width, height, Option.find(options, selectedValue).getText().asFormattedString(), btn -> {});
|
||||
this.options = options;
|
||||
this.selectedValue = selectedValue;
|
||||
this.onChanged = onChanged;
|
||||
@@ -31,6 +31,6 @@ public class CycleButtonWidget<T> extends Button{
|
||||
|
||||
selectedValue = newSelectedOption.getValue();
|
||||
onChanged.accept(selectedValue);
|
||||
setMessage(newSelectedOption.getText().getString());
|
||||
setMessage(newSelectedOption.getText().asFormattedString());
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import net.minecraft.client.gui.widget.AbstractSlider;
|
||||
import net.minecraft.client.gui.widget.SliderWidget;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class DiscreteValueSliderWidget<T> extends AbstractSlider{
|
||||
public final class DiscreteValueSliderWidget<T> extends SliderWidget{
|
||||
private final List<Option<T>> options;
|
||||
private final Consumer<T> onChanged;
|
||||
private T selectedValue;
|
||||
@@ -27,7 +27,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSlider{
|
||||
|
||||
@Override
|
||||
protected void updateMessage(){
|
||||
setMessage(getSelectedOption().getText().getString());
|
||||
setMessage(getSelectedOption().getText().asFormattedString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,23 +1,21 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import chylex.bettercontrols.util.Key;
|
||||
import net.minecraft.client.gui.widget.button.AbstractButton;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.util.Formatting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import static chylex.bettercontrols.util.Statics.OPTIONS;
|
||||
|
||||
public final class KeyBindingWidget extends Button{
|
||||
public final class KeyBindingWidget extends ButtonWidget{
|
||||
private final KeyBinding binding;
|
||||
private final ITextComponent bindingName;
|
||||
private final String bindingName;
|
||||
|
||||
private final List<AbstractButton> linkedButtons = new ArrayList<>(1);
|
||||
private final List<AbstractButtonWidget> linkedButtons = new ArrayList<>(1);
|
||||
|
||||
private final Consumer<KeyBindingWidget> onEditingStarted;
|
||||
private boolean isEditing;
|
||||
@@ -25,7 +23,7 @@ public final class KeyBindingWidget extends Button{
|
||||
public KeyBindingWidget(final int x, final int y, final int width, final int height, final KeyBinding binding, final Consumer<KeyBindingWidget> onEditingStarted){
|
||||
super(x, y, width, height, "", btn -> {});
|
||||
this.binding = binding;
|
||||
this.bindingName = new TranslationTextComponent(binding.getTranslationKey());
|
||||
this.bindingName = I18n.translate(binding.getId());
|
||||
this.onEditingStarted = onEditingStarted;
|
||||
updateKeyBindingText();
|
||||
}
|
||||
@@ -34,14 +32,14 @@ public final class KeyBindingWidget extends Button{
|
||||
this(x, y, width, 20, binding, onEditingStarted);
|
||||
}
|
||||
|
||||
public void linkButtonToBoundState(final AbstractButton button){
|
||||
public void linkButtonToBoundState(final AbstractButtonWidget button){
|
||||
linkedButtons.add(button);
|
||||
button.active = !Key.isUnbound(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNarrationMessage(){
|
||||
return Key.isUnbound(binding) ? I18n.format("narrator.controls.unbound", bindingName) : I18n.format("narrator.controls.bound", bindingName, super.getNarrationMessage());
|
||||
return Key.isUnbound(binding) ? I18n.translate("narrator.controls.unbound", bindingName) : I18n.translate("narrator.controls.bound", bindingName, super.getNarrationMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,11 +49,11 @@ public final class KeyBindingWidget extends Button{
|
||||
updateKeyBindingText();
|
||||
}
|
||||
|
||||
public void bindAndStopEditing(final InputMappings.Input key){
|
||||
public void bindAndStopEditing(final InputUtil.KeyCode key){
|
||||
Key.bind(binding, key);
|
||||
stopEditing();
|
||||
|
||||
for(final AbstractButton button : linkedButtons){
|
||||
for(final AbstractButtonWidget button : linkedButtons){
|
||||
button.active = !Key.isUnbound(binding);
|
||||
}
|
||||
}
|
||||
@@ -69,7 +67,7 @@ public final class KeyBindingWidget extends Button{
|
||||
boolean hasConflict = false;
|
||||
|
||||
if (!Key.isUnbound(binding)){
|
||||
for(final KeyBinding other : OPTIONS.keyBindings){
|
||||
for(final KeyBinding other : OPTIONS.keysAll){
|
||||
if (binding != other && binding.equals(other)){
|
||||
hasConflict = true;
|
||||
break;
|
||||
@@ -78,10 +76,10 @@ public final class KeyBindingWidget extends Button{
|
||||
}
|
||||
|
||||
if (isEditing){
|
||||
setMessage(TextFormatting.WHITE + "> " + TextFormatting.YELLOW + Key.getBoundKeyText(binding) + TextFormatting.WHITE + " <");
|
||||
setMessage(Formatting.WHITE + "> " + Formatting.YELLOW + binding.getLocalizedName() + Formatting.WHITE + " <");
|
||||
}
|
||||
else if (hasConflict){
|
||||
setMessage(TextFormatting.RED + Key.getBoundKeyText(binding));
|
||||
setMessage(Formatting.RED + Key.getBoundKeyText(binding));
|
||||
}
|
||||
else{
|
||||
setMessage(Key.isUnbound(binding) ? "(No Binding)" : Key.getBoundKeyText(binding));
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import chylex.bettercontrols.gui.OptionListWidget.Widget;
|
||||
import chylex.bettercontrols.util.LiteralText;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import java.util.List;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
public final class TextWidget extends AbstractGui implements Widget{
|
||||
public final class TextWidget extends DrawableHelper implements Widget{
|
||||
public static final int LEFT = 0;
|
||||
public static final int CENTER = 1;
|
||||
|
||||
@@ -56,16 +56,16 @@ public final class TextWidget extends AbstractGui implements Widget{
|
||||
|
||||
@Override
|
||||
public void render(final int mouseX, final int mouseY, final float delta){
|
||||
final FontRenderer textRenderer = MINECRAFT.fontRenderer;
|
||||
final List<String> lines = textRenderer.listFormattedStringToWidth(text.getString(), width);
|
||||
final int lineHeight = textRenderer.FONT_HEIGHT + 1;
|
||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
final List<String> lines = textRenderer.wrapStringToWidthAsList(text.asFormattedString(), width);
|
||||
final int lineHeight = textRenderer.fontHeight + 1;
|
||||
|
||||
final int finalX = align == CENTER ? x + (width / 2) - (lines.stream().mapToInt(textRenderer::getStringWidth).max().orElse(0) / 2) : x;
|
||||
final int finalY = y + (height / 2) - (lineHeight * lines.size() / 2) + 1;
|
||||
|
||||
for(int i = 0; i < lines.size(); i++){
|
||||
final String line = lines.get(i);
|
||||
textRenderer.drawStringWithShadow(line, finalX, finalY + (i * lineHeight), (255 << 16) | (255 << 8) | 255);
|
||||
textRenderer.drawWithShadow(line, finalX, finalY + (i * lineHeight), (255 << 16) | (255 << 8) | 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
package chylex.bettercontrols.input;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings.Type;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.InputUtil.Type;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class KeyBindingWithModifier extends KeyBinding{
|
||||
public static final String CATEGORY = "key.categories.bettercontrols";
|
||||
|
||||
public static boolean checkCategoryMatches(final String text){
|
||||
return I18n.format(CATEGORY).equals(text);
|
||||
public static boolean checkCategoryMatches(final String name){
|
||||
return I18n.translate(CATEGORY).equals(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -27,13 +27,13 @@ public class KeyBindingWithModifier extends KeyBinding{
|
||||
return modifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeyDown(){
|
||||
return super.isKeyDown() && (modifier == null || modifier.isPressed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPressed(){
|
||||
return super.isPressed() && (modifier == null || modifier.isPressed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasPressed(){
|
||||
return super.wasPressed() && (modifier == null || modifier.isPressed());
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package chylex.bettercontrols.input;
|
||||
import chylex.bettercontrols.util.Key;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
|
||||
public class ToggleTracker{
|
||||
protected final KeyBinding bindingToggle;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package chylex.bettercontrols.input;
|
||||
import chylex.bettercontrols.mixin.AccessKeyBindingFields;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@@ -1,14 +1,14 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(ActiveRenderInfo.class)
|
||||
@Mixin(Camera.class)
|
||||
public interface AccessCameraFields{
|
||||
@Accessor("renderViewEntity")
|
||||
@Accessor
|
||||
Entity getFocusedEntity();
|
||||
|
||||
@Accessor("height")
|
||||
@Accessor
|
||||
void setCameraY(float y);
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
public interface AccessClientPlayerFields{
|
||||
@Accessor("sprintToggleTimer")
|
||||
@Accessor("field_3935")
|
||||
void setTicksLeftToDoubleTapSprint(int value);
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList.CategoryEntry;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget.CategoryEntry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(CategoryEntry.class)
|
||||
public interface AccessControlsListCategory{
|
||||
@Accessor("labelText")
|
||||
String getText();
|
||||
@Accessor
|
||||
String getName();
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList.KeyEntry;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget.KeyBindingEntry;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(KeyEntry.class)
|
||||
@Mixin(KeyBindingEntry.class)
|
||||
public interface AccessControlsListKeyBinding{
|
||||
@Accessor("keybinding")
|
||||
@Accessor
|
||||
KeyBinding getBinding();
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public interface AccessGameRendererFields{
|
||||
@Accessor("fovModifierHand")
|
||||
@Accessor
|
||||
void setMovementFovMultiplier(float value);
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(KeyBinding.class)
|
||||
public interface AccessKeyBindingFields{
|
||||
@Accessor("CATEGORY_ORDER")
|
||||
@Accessor
|
||||
static Map<String, Integer> getCategoryOrderMap(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.gui.widget.button.OptionButton;
|
||||
import net.minecraft.client.settings.AbstractOption;
|
||||
import net.minecraft.client.gui.widget.OptionButtonWidget;
|
||||
import net.minecraft.client.options.Option;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(OptionButton.class)
|
||||
@Mixin(OptionButtonWidget.class)
|
||||
public interface AccessOptionButtonWidgetOption{
|
||||
@Accessor("enumOptions")
|
||||
AbstractOption getOption();
|
||||
@Accessor
|
||||
Option getOption();
|
||||
}
|
||||
|
@@ -5,6 +5,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
public interface AccessPlayerFields{
|
||||
@Accessor("flyToggleTimer")
|
||||
@Accessor("field_7489")
|
||||
void setTicksLeftToDoubleTapFlight(int value);
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.AbstractButton;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
@@ -10,8 +9,8 @@ import java.util.List;
|
||||
@Mixin(Screen.class)
|
||||
public interface AccessScreenButtons{
|
||||
@Accessor
|
||||
List<AbstractButton> getButtons();
|
||||
List<AbstractButtonWidget> getButtons();
|
||||
|
||||
@Invoker
|
||||
<T extends Widget> T callAddButton(T button);
|
||||
<T extends AbstractButtonWidget> T callAddButton(T button);
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.client.settings.ToggleableKeyBinding;
|
||||
import net.minecraft.client.options.StickyKeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(ToggleableKeyBinding.class)
|
||||
@Mixin(StickyKeyBinding.class)
|
||||
public interface AccessStickyKeyBindingStateGetter{
|
||||
@Accessor("getterToggle")
|
||||
@Accessor
|
||||
BooleanSupplier getToggleGetter();
|
||||
|
||||
@Accessor("getterToggle")
|
||||
@Accessor
|
||||
@Mutable
|
||||
void setToggleGetter(final BooleanSupplier toggleGetter);
|
||||
}
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.player.PlayerTicker;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.util.MovementInput;
|
||||
import net.minecraft.util.MovementInputFromOptions;
|
||||
import net.minecraft.client.input.KeyboardInput;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -10,11 +9,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
|
||||
|
||||
@Mixin(MovementInputFromOptions.class)
|
||||
@Mixin(KeyboardInput.class)
|
||||
public abstract class HookClientPlayerInputTick{
|
||||
@Inject(method = "func_225607_a_(Z)V", at = @At(value = "FIELD", target = "Lnet/minecraft/util/MovementInputFromOptions;forwardKeyDown:Z", ordinal = 0, shift = AFTER))
|
||||
@Inject(method = "tick(Z)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/input/KeyboardInput;pressingForward:Z", ordinal = 0, shift = AFTER))
|
||||
private void afterInputTick(final CallbackInfo info){
|
||||
final MovementInput input = (MovementInput)(Object)this;
|
||||
final KeyboardInput input = (KeyboardInput)(Object)this;
|
||||
final ClientPlayerEntity player = MINECRAFT.player;
|
||||
|
||||
if (player != null){
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.player.PlayerTicker;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -16,19 +16,19 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayerEntity{
|
||||
super(world, profile);
|
||||
}
|
||||
|
||||
@Inject(method = "livingTick", at = @At("HEAD"))
|
||||
@Inject(method = "tickMovement()V", at = @At("HEAD"))
|
||||
private void atHead(final CallbackInfo info){
|
||||
final ClientPlayerEntity player = (ClientPlayerEntity)(Object)this;
|
||||
PlayerTicker.get(player).atHead(player);
|
||||
}
|
||||
|
||||
@Inject(method = "livingTick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MovementInput;func_225607_a_(Z)V", ordinal = 0, shift = AFTER))
|
||||
@Inject(method = "tickMovement()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(Z)V", ordinal = 0, shift = AFTER))
|
||||
private void afterInputTick(final CallbackInfo info){
|
||||
final ClientPlayerEntity player = (ClientPlayerEntity)(Object)this;
|
||||
PlayerTicker.get(player).afterInputTick(player);
|
||||
}
|
||||
|
||||
@Inject(method = "livingTick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/player/AbstractClientPlayerEntity;livingTick()V", ordinal = 0, shift = AFTER))
|
||||
@Inject(method = "tickMovement()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;tickMovement()V", ordinal = 0, shift = AFTER))
|
||||
private void afterSuperCall(final CallbackInfo info){
|
||||
final ClientPlayerEntity player = (ClientPlayerEntity)(Object)this;
|
||||
PlayerTicker.get(player).afterSuperCall(player);
|
||||
|
@@ -1,33 +1,33 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.BetterControlsMod;
|
||||
import chylex.bettercontrols.input.KeyBindingWithModifier;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.ControlsScreen;
|
||||
import net.minecraft.client.gui.widget.list.AbstractOptionList;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList.CategoryEntry;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList.Entry;
|
||||
import net.minecraft.client.gui.widget.list.KeyBindingList.KeyEntry;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget.CategoryEntry;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget.Entry;
|
||||
import net.minecraft.client.gui.screen.options.ControlsListWidget.KeyBindingEntry;
|
||||
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(KeyBindingList.class)
|
||||
public abstract class HookControlsListWidget extends AbstractOptionList<Entry>{
|
||||
public HookControlsListWidget(final Minecraft client, final int width, final int height, final int top, final int bottom, final int itemHeight){
|
||||
@Mixin(ControlsListWidget.class)
|
||||
public abstract class HookControlsListWidget extends ElementListWidget<Entry>{
|
||||
public HookControlsListWidget(final MinecraftClient client, final int width, final int height, final int top, final int bottom, final int itemHeight){
|
||||
super(client, width, height, top, bottom, itemHeight);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
public void init(final ControlsScreen parent, final Minecraft client, final CallbackInfo ci){
|
||||
public void init(final ControlsOptionsScreen parent, final MinecraftClient client, final CallbackInfo ci){
|
||||
children().removeIf(it -> {
|
||||
if (it instanceof CategoryEntry && KeyBindingWithModifier.checkCategoryMatches(((AccessControlsListCategory)it).getText())){
|
||||
if (it instanceof CategoryEntry && KeyBindingWithModifier.checkCategoryMatches(((AccessControlsListCategory)it).getName())){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (it instanceof KeyEntry && ArrayUtils.contains(BetterControlsMod.config.getAllKeyBindings(), ((AccessControlsListKeyBinding)it).getBinding())){
|
||||
if (it instanceof KeyBindingEntry && ArrayUtils.contains(BetterControlsMod.config.getAllKeyBindings(), ((AccessControlsListKeyBinding)it).getBinding())){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -1,30 +1,34 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.BetterControlsMod;
|
||||
import chylex.bettercontrols.input.KeyBindingWithModifier;
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.options.GameOptions;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
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;
|
||||
|
||||
@Mixin(GameSettings.class)
|
||||
@Mixin(GameOptions.class)
|
||||
public abstract class HookLoadGameOptions{
|
||||
private boolean hasLoaded = false;
|
||||
|
||||
@Mutable
|
||||
@Final
|
||||
@Shadow
|
||||
public KeyBinding[] keyBindings;
|
||||
public KeyBinding[] keysAll;
|
||||
|
||||
@Inject(method = "loadOptions()V", at = @At("HEAD"))
|
||||
@Inject(method = "load()V", at = @At("HEAD"))
|
||||
private void load(final CallbackInfo info){
|
||||
if (hasLoaded){
|
||||
return;
|
||||
}
|
||||
|
||||
hasLoaded = true;
|
||||
keyBindings = ArrayUtils.addAll(keyBindings, BetterControlsMod.config.getAllKeyBindings());
|
||||
keysAll = ArrayUtils.addAll(keysAll, BetterControlsMod.config.getAllKeyBindings());
|
||||
AccessKeyBindingFields.getCategoryOrderMap().put(KeyBindingWithModifier.CATEGORY, Integer.valueOf(Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
@@ -1,24 +1,24 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.gui.ScreenPatcher;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AccessibilityScreen;
|
||||
import net.minecraft.client.gui.screen.ControlsScreen;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.options.AccessibilityScreen;
|
||||
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
@Mixin(value = Minecraft.class, priority = 100)
|
||||
@Mixin(value = MinecraftClient.class, priority = 100)
|
||||
public abstract class HookOpenScreen{
|
||||
@Inject(method = "displayGuiScreen(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At("TAIL"))
|
||||
@Inject(method = "openScreen(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At("TAIL"))
|
||||
private void openScreen(final Screen ignore, final CallbackInfo ci){
|
||||
final Screen screen = MINECRAFT.currentScreen;
|
||||
|
||||
if (screen != null && !Screen.hasAltDown()){
|
||||
if (screen.getClass() == ControlsScreen.class){
|
||||
ScreenPatcher.onControlsScreenOpened((ControlsScreen)screen);
|
||||
if (screen.getClass() == ControlsOptionsScreen.class){
|
||||
ScreenPatcher.onControlsScreenOpened((ControlsOptionsScreen)screen);
|
||||
}
|
||||
else if (screen.getClass() == AccessibilityScreen.class){
|
||||
ScreenPatcher.onAccessibilityScreenOpened((AccessibilityScreen)screen);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.input.ToggleTrackerForStickyKey;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.settings.ToggleableKeyBinding;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.options.StickyKeyBinding;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -10,11 +10,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(ToggleableKeyBinding.class)
|
||||
@Mixin(StickyKeyBinding.class)
|
||||
public abstract class HookStickyKeyBindingState extends KeyBinding{
|
||||
@Shadow
|
||||
@Final
|
||||
private BooleanSupplier getterToggle;
|
||||
private BooleanSupplier toggleGetter;
|
||||
|
||||
public HookStickyKeyBindingState(final String translationKey, final int code, final String category){
|
||||
super(translationKey, code, category);
|
||||
@@ -29,7 +29,7 @@ public abstract class HookStickyKeyBindingState extends KeyBinding{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeyDown(){
|
||||
return super.isKeyDown() || (ToggleTrackerForStickyKey.isOverrideEnabled(this) && getterToggle.getAsBoolean());
|
||||
public boolean isPressed(){
|
||||
return super.isPressed() || (ToggleTrackerForStickyKey.isOverrideEnabled(this) && toggleGetter.getAsBoolean());
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package chylex.bettercontrols.player;
|
||||
import chylex.bettercontrols.BetterControlsMod;
|
||||
import chylex.bettercontrols.config.BetterControlsConfig;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
|
||||
final class FlightHelper{
|
||||
private FlightHelper(){}
|
||||
@@ -14,11 +14,11 @@ final class FlightHelper{
|
||||
}
|
||||
|
||||
static boolean isFlyingCreativeOrSpectator(final ClientPlayerEntity player){
|
||||
return player.abilities.isFlying && (player.isCreative() || player.isSpectator());
|
||||
return player.abilities.flying && (player.isCreative() || player.isSpectator());
|
||||
}
|
||||
|
||||
static boolean shouldFlyOnGround(final ClientPlayerEntity player){
|
||||
return cfg().flyOnGroundInCreative && player.isCreative() && player.abilities.isFlying;
|
||||
return cfg().flyOnGroundInCreative && player.isCreative() && player.abilities.flying;
|
||||
}
|
||||
|
||||
static float getFlightSpeed(final ClientPlayerEntity player, final boolean boost){
|
||||
|
@@ -11,8 +11,9 @@ import chylex.bettercontrols.mixin.AccessGameRendererFields;
|
||||
import chylex.bettercontrols.mixin.AccessPlayerFields;
|
||||
import chylex.bettercontrols.mixin.AccessStickyKeyBindingStateGetter;
|
||||
import chylex.bettercontrols.util.Key;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.util.MovementInput;
|
||||
import net.minecraft.client.input.Input;
|
||||
import net.minecraft.client.input.KeyboardInput;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import static chylex.bettercontrols.util.Statics.KEY_FORWARD;
|
||||
@@ -46,8 +47,8 @@ public final class PlayerTicker{
|
||||
|
||||
// Logic
|
||||
|
||||
private final ToggleTracker toggleSprint = new ToggleTrackerForStickyKey(cfg().keyToggleSprint, KEY_SPRINT, toggled -> OPTIONS.toggleSprint = toggled);
|
||||
private final ToggleTracker toggleSneak = new ToggleTrackerForStickyKey(cfg().keyToggleSneak, KEY_SNEAK, toggled -> OPTIONS.toggleCrouch = toggled);
|
||||
private final ToggleTracker toggleSprint = new ToggleTrackerForStickyKey(cfg().keyToggleSprint, KEY_SPRINT, toggled -> OPTIONS.sprintToggled = toggled);
|
||||
private final ToggleTracker toggleSneak = new ToggleTrackerForStickyKey(cfg().keyToggleSneak, KEY_SNEAK, toggled -> OPTIONS.sneakToggled = toggled);
|
||||
private final ToggleTracker toggleWalkForward = new ToggleTracker(cfg().keyToggleWalkForward, KEY_FORWARD);
|
||||
private final ToggleTracker toggleJump = new ToggleTracker(cfg().keyToggleJump, KEY_JUMP);
|
||||
|
||||
@@ -87,7 +88,7 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
final SprintMode sprintMode = cfg().sprintMode;
|
||||
final boolean wasSprintToggled = OPTIONS.toggleSprint;
|
||||
final boolean wasSprintToggled = OPTIONS.sprintToggled;
|
||||
final boolean isSprintToggled = toggleSprint.tick();
|
||||
|
||||
if (temporarySprintTimer > 0){
|
||||
@@ -143,17 +144,17 @@ public final class PlayerTicker{
|
||||
toggleSneak.tick();
|
||||
}
|
||||
|
||||
public void afterInputAssignsPressingForward(final MovementInput input){
|
||||
public void afterInputAssignsPressingForward(final KeyboardInput input){
|
||||
if (MINECRAFT.currentScreen == null){
|
||||
input.forwardKeyDown |= toggleWalkForward.tick();
|
||||
input.pressingForward |= toggleWalkForward.tick();
|
||||
}
|
||||
}
|
||||
|
||||
public void afterInputTick(final ClientPlayerEntity player){
|
||||
final MovementInput input = player.movementInput;
|
||||
final Input input = player.input;
|
||||
|
||||
if (MINECRAFT.currentScreen == null && !player.abilities.isFlying){
|
||||
input.jump |= toggleJump.tick();
|
||||
if (MINECRAFT.currentScreen == null && !player.abilities.flying){
|
||||
input.jumping |= toggleJump.tick();
|
||||
}
|
||||
|
||||
if (FlightHelper.isFlyingCreativeOrSpectator(player)){
|
||||
@@ -165,25 +166,25 @@ public final class PlayerTicker{
|
||||
player.abilities.setFlySpeed(flightSpeed);
|
||||
}
|
||||
|
||||
if (Math.abs(verticalVelocity) > 1E-5F && player == MINECRAFT.getRenderViewEntity()){
|
||||
if (Math.abs(verticalVelocity) > 1E-5F && player == MINECRAFT.getCameraEntity()){
|
||||
int direction = 0;
|
||||
|
||||
if (input.sneaking){
|
||||
--direction;
|
||||
}
|
||||
|
||||
if (input.jump){
|
||||
if (input.jumping){
|
||||
++direction;
|
||||
}
|
||||
|
||||
if (direction != 0){
|
||||
player.setMotion(player.getMotion().add(0D, flightSpeed * verticalVelocity * direction, 0D));
|
||||
player.setVelocity(player.getVelocity().add(0D, flightSpeed * verticalVelocity * direction, 0D));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg().resumeSprintingAfterHittingObstacle){
|
||||
if (wasHittingObstacle != player.collidedHorizontally){
|
||||
if (wasHittingObstacle != player.horizontalCollision){
|
||||
if (!wasHittingObstacle){
|
||||
wasSprintingBeforeHittingObstacle = player.isSprinting() || Key.isPressed(KEY_SPRINT);
|
||||
}
|
||||
@@ -193,11 +194,11 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
// collision also stops when the player lets go of movement keys
|
||||
wasHittingObstacle = player.collidedHorizontally;
|
||||
wasHittingObstacle = player.horizontalCollision;
|
||||
}
|
||||
}
|
||||
else{
|
||||
wasHittingObstacle = player.collidedHorizontally;
|
||||
wasHittingObstacle = player.horizontalCollision;
|
||||
wasSprintingBeforeHittingObstacle = false;
|
||||
}
|
||||
|
||||
@@ -229,8 +230,8 @@ public final class PlayerTicker{
|
||||
holdingSneakWhileTouchingGround = true;
|
||||
}
|
||||
else if (holdingSneakWhileTouchingGround){
|
||||
player.abilities.isFlying = false;
|
||||
player.sendPlayerAbilities();
|
||||
player.abilities.flying = false;
|
||||
player.sendAbilitiesUpdate();
|
||||
cancelLanding = false;
|
||||
}
|
||||
}
|
||||
@@ -246,23 +247,23 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
if (FlightHelper.isFlyingCreativeOrSpectator(player) && cfg().disableFlightInertia){
|
||||
final MovementInput input = player.movementInput;
|
||||
final Input input = player.input;
|
||||
|
||||
if (input.moveForward == 0F && input.moveStrafe == 0F){
|
||||
player.setMotion(player.getMotion().mul(0.0, 1.0, 0.0));
|
||||
if (input.movementForward == 0F && input.movementSideways == 0F){
|
||||
player.setVelocity(player.getVelocity().multiply(0.0, 1.0, 0.0));
|
||||
}
|
||||
|
||||
if (!input.jump && !input.sneaking){
|
||||
player.setMotion(player.getMotion().mul(1.0, 0.0, 1.0));
|
||||
if (!input.jumping && !input.sneaking){
|
||||
player.setVelocity(player.getVelocity().multiply(1.0, 0.0, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
if (player.isCreative()){
|
||||
if (Key.wasPressed(cfg().keyToggleFlight)){
|
||||
final boolean isFlying = !player.abilities.isFlying;
|
||||
final boolean isFlying = !player.abilities.flying;
|
||||
|
||||
player.abilities.isFlying = isFlying;
|
||||
player.sendPlayerAbilities();
|
||||
player.abilities.flying = isFlying;
|
||||
player.sendAbilitiesUpdate();
|
||||
|
||||
if (isFlying){
|
||||
temporaryFlyOnGroundTimer = 10;
|
||||
@@ -284,10 +285,10 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
if (!cfg().sneakingMovesCameraSmoothly){
|
||||
final AccessCameraFields camera = (AccessCameraFields)MINECRAFT.gameRenderer.getActiveRenderInfo();
|
||||
final AccessCameraFields camera = (AccessCameraFields)MINECRAFT.gameRenderer.getCamera();
|
||||
|
||||
if (camera.getFocusedEntity() == player){
|
||||
camera.setCameraY(player.getEyeHeight());
|
||||
camera.setCameraY(player.getStandingEyeHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +300,7 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
if (Key.isPressed(cfg().keyOpenMenu)){
|
||||
MINECRAFT.displayGuiScreen(new BetterControlsScreen(null));
|
||||
MINECRAFT.openScreen(new BetterControlsScreen(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,46 +1,45 @@
|
||||
package chylex.bettercontrols.util;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.client.util.InputMappings.Input;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
|
||||
public final class Key{
|
||||
private Key(){}
|
||||
|
||||
public static final Input INVALID = InputMappings.INPUT_INVALID;
|
||||
public static final InputUtil.KeyCode INVALID = InputUtil.UNKNOWN_KEYCODE;
|
||||
|
||||
public static boolean isUnbound(final KeyBinding binding){
|
||||
return binding.isInvalid();
|
||||
return binding.isNotBound();
|
||||
}
|
||||
|
||||
public static boolean isPressed(final KeyBinding binding){
|
||||
return binding.isKeyDown();
|
||||
return binding.isPressed();
|
||||
}
|
||||
|
||||
public static boolean wasPressed(final KeyBinding binding){
|
||||
return binding.isPressed();
|
||||
return binding.wasPressed();
|
||||
}
|
||||
|
||||
public static String getBoundKeyText(final KeyBinding binding){
|
||||
return binding.getLocalizedName();
|
||||
}
|
||||
|
||||
public static void bind(final KeyBinding binding, final Input input){
|
||||
binding.bind(input);
|
||||
public static void bind(final KeyBinding binding, final InputUtil.KeyCode input){
|
||||
binding.setKeyCode(input);
|
||||
}
|
||||
|
||||
public static String writeBinding(final KeyBinding binding){
|
||||
return binding.getTranslationKey();
|
||||
return binding.getName();
|
||||
}
|
||||
|
||||
public static void readBinding(final KeyBinding binding, final String serialized){
|
||||
bind(binding, InputMappings.getInputByName(serialized));
|
||||
bind(binding, InputUtil.fromName(serialized));
|
||||
}
|
||||
|
||||
public static Input inputFromMouse(final int button){
|
||||
return InputMappings.Type.MOUSE.getOrMakeInput(button);
|
||||
public static InputUtil.KeyCode inputFromMouse(final int button){
|
||||
return InputUtil.Type.MOUSE.createFromCode(button);
|
||||
}
|
||||
|
||||
public static Input inputFromKeyboard(final int keyCode, final int scanCode){
|
||||
return InputMappings.getInputByCode(keyCode, scanCode);
|
||||
public static InputUtil.KeyCode inputFromKeyboard(final int keyCode, final int scanCode){
|
||||
return InputUtil.getKeyCode(keyCode, scanCode);
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,11 @@
|
||||
package chylex.bettercontrols.util;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
public final class LiteralText extends StringTextComponent{
|
||||
public final class LiteralText extends net.minecraft.text.LiteralText{
|
||||
public static LiteralText text(final String text){
|
||||
return new LiteralText(text);
|
||||
}
|
||||
|
||||
private final String msg;
|
||||
|
||||
public LiteralText(final String msg){
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public LiteralText copy(){
|
||||
return new LiteralText(msg);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
package chylex.bettercontrols.util;
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.options.GameOptions;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
|
||||
public final class Statics{
|
||||
private Statics(){}
|
||||
|
||||
public static final Minecraft MINECRAFT = Minecraft.getInstance();
|
||||
public static final GameSettings OPTIONS = MINECRAFT.gameSettings;
|
||||
public static final MinecraftClient MINECRAFT = MinecraftClient.getInstance();
|
||||
public static final GameOptions OPTIONS = MINECRAFT.options;
|
||||
|
||||
public static final KeyBinding KEY_SPRINT = OPTIONS.keyBindSprint;
|
||||
public static final KeyBinding KEY_SNEAK = OPTIONS.keyBindSneak;
|
||||
public static final KeyBinding KEY_FORWARD = OPTIONS.keyBindForward;
|
||||
public static final KeyBinding KEY_JUMP = OPTIONS.keyBindJump;
|
||||
public static final KeyBinding KEY_SPRINT = OPTIONS.keySprint;
|
||||
public static final KeyBinding KEY_SNEAK = OPTIONS.keySneak;
|
||||
public static final KeyBinding KEY_FORWARD = OPTIONS.keyForward;
|
||||
public static final KeyBinding KEY_JUMP = OPTIONS.keyJump;
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package io.github.prospector.modmenu.api;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@FunctionalInterface
|
||||
public interface ConfigScreenFactory<S extends Screen>{
|
||||
S create(Screen var1);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package io.github.prospector.modmenu.api;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface ModMenuApi{
|
||||
String getModId();
|
||||
|
||||
default ConfigScreenFactory<?> getModConfigScreenFactory(){
|
||||
return ignore -> null;
|
||||
}
|
||||
|
||||
default Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories(){
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[31,)"
|
||||
|
||||
authors = "chylex"
|
||||
license = "MPL-2.0"
|
||||
issueTrackerURL = "https://github.com/chylex/Better-Controls/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "bettercontrols"
|
||||
version = "1.2.0a"
|
||||
displayName = "Better Controls"
|
||||
logoFile = "icon.png"
|
||||
description = '''
|
||||
Adds many powerful key bindings and options to control your movement.
|
||||
The features complement vanilla mechanics without giving unfair advantages, so server use should be fine.
|
||||
'''
|
||||
|
||||
[[dependencies.bettercontrols]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.15.2,1.16)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.bettercontrols]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[31.2.44,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@@ -3,7 +3,7 @@
|
||||
"minVersion": "0.8",
|
||||
"package": "chylex.bettercontrols.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"mixins": [
|
||||
"AccessCameraFields",
|
||||
"AccessClientPlayerFields",
|
||||
"AccessControlsListCategory",
|
||||
|
33
src/main/resources/fabric.mod.json
Normal file
33
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "bettercontrols",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Better Controls",
|
||||
"description": "Adds many powerful key bindings and options to control your movement.\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine.",
|
||||
"icon": "assets/bettercontrols/icon.png",
|
||||
"license": "MPL-2.0",
|
||||
|
||||
"authors": [ "chylex" ],
|
||||
"contact": {
|
||||
"homepage": "",
|
||||
"sources": "https://github.com/chylex/Better-Controls",
|
||||
"issues": "https://github.com/chylex/Better-Controls/issues"
|
||||
},
|
||||
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [ "chylex.bettercontrols.BetterControlsMod" ],
|
||||
"modmenu": [ "chylex.bettercontrols.compatibility.ModMenuSupport" ]
|
||||
},
|
||||
|
||||
"mixins": [{
|
||||
"config": "bettercontrols.mixins.json",
|
||||
"environment": "client"
|
||||
}],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"minecraft": "1.15.x"
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "Better Controls",
|
||||
"pack_format": 5,
|
||||
"_comment": ""
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user