Compare commits

..

32 Commits

Author SHA1 Message Date
LambdAurora
f62819d9a4 LambdaControls v1.6.0: Fix several bugs and upgrade settings screen. 2021-03-18 13:28:38 +01:00
Yao Chung Hu
978b94176c Update Mexican Spanish Translation (#49)
* Update Mexican Spanish Translation

* Remove old translation key, add missing translation key

I swear I'm not blind
2021-03-18 13:12:03 +01:00
LambdAurora
c8989cb9ee Add max values to axes, fixes #41. 2021-03-17 23:50:16 +01:00
LambdAurora
97521e832d Add stick-independent dead zones (#32) and update license headers. 2021-03-17 18:49:10 +01:00
LambdAurora
400b625716 Reformat code and update networking. 2021-03-17 00:51:34 +01:00
LambdAurora
f89eebf0e7 More WIP GUI rework! 2021-03-16 22:37:50 +01:00
LambdAurora
cc0a9aebe2 Fix #37, fix some movement bugs, more WIP GUI rework. 2021-03-16 14:51:50 +01:00
LambdAurora
b8ec934c10 Change package. 2021-03-16 00:40:56 +01:00
LambdAurora
ac8fab83a2 More GUI rework! Controller controls tab works now. 2021-03-16 00:31:24 +01:00
LambdAurora
1489b796a8 Fix gradle stupidity. 2021-03-15 21:24:16 +01:00
LambdAurora
ab8b78f75a Modules be gone! 2021-03-15 20:39:40 +01:00
LambdAurora
c7026ba1fd Old stuff be gone. 2021-03-15 17:21:43 +01:00
LambdAurora
0532913d69 WIP broken stuff. 2021-03-15 17:20:16 +01:00
LambdAurora
597700b2bc Merge pull request #34 from egeesin/1.16
Add Turkish localization
2020-11-07 20:08:38 +01:00
Ege
4edb0952d8 Add Turkish translation strings 2020-10-20 03:17:37 +03:00
LambdAurora
178f19dc2c Merge pull request #29 from Hambaka/1.16
Update Simplified Chinese localization.
2020-09-01 19:43:39 +02:00
Hambaka
129c3d0f3b Update Simplified Chinese localization.
Update zh_cn.json

Translate new 5 lines strings.
Adjust some translations. ( followed suggestions in a Chinese Minecraft community project's translation style guide, although most changes in this commit are "add space" )

Note: The translation of "Show controls ring" is not final, since ring menu feature is not completed, I am not sure its feature, so current translation is "Show extra keys (select) menu".
2020-09-02 00:00:27 +08:00
LambdAurora
deccb758ea Fix compilation crash. 2020-09-01 14:30:40 +02:00
LambdAurora
b7c60f8651 🔖 LambdaControls v1.5.0: Update to Minecraft 1.16.2. 2020-09-01 14:29:06 +02:00
LambdAurora
1ee75bc4e5 Fix issues, improve REI compat and horizontal reach-around, WIP on ring. 2020-08-25 16:06:38 +02:00
LambdAurora
1f0ddab36b Fix lot of bugs and update to 1.16.2. 2020-08-19 17:58:50 +02:00
LambdAurora
8a919934e2 Merge pull request #24 from joaoh1/1.16
👽 Fix compatibility with Ok Zoomer 4.0.0 betas
2020-08-14 17:47:08 +02:00
joaoh1
0178f5e684 👽 Fix compatibility with Ok Zoomer 4.0.0 betas 2020-08-14 12:40:45 -03:00
LambdAurora
c495e2ae0c Merge pull request #22 from FlashyReese/1.16
Add es_mx localization
2020-08-03 11:23:02 +02:00
Yao Chung Hu
3ecce09775 fix: use of words 2020-08-02 18:59:59 -05:00
Yao Chung Hu
e94d2eb240 new: added es_mx localization 2020-08-02 18:54:35 -05:00
LambdAurora
7571a2aa1b Merge pull request #21 from joaoh1/1.16
🚸 Hide Ok Zoomer's extra keybinds when disabled
2020-07-31 21:40:44 +02:00
joaoh1
d09a225518 🚸 Hide Ok Zoomer's extra keybinds when disabled 2020-07-31 15:55:43 -03:00
LambdAurora
4290d79bd0 Merge pull request #18 from Hambaka/1.16
🌐 Add Simplified Chinese localization.
2020-07-20 21:09:30 +02:00
Hambaka
f9f0a7a18d 🌐 Add Simplified Chinese localization. 2020-07-21 02:49:01 +08:00
LambdAurora
f889fc6367 Fix chording problem. 2020-07-20 19:22:18 +02:00
LambdAurora
7dcbda7e57 Update CHANGELOG. 2020-07-19 00:11:43 +02:00
124 changed files with 3982 additions and 4498 deletions

View File

@@ -89,3 +89,24 @@ This update also has a backport 1.14.4 version ([#9](https://github.com/LambdAur
- Started to work on action ring. - Started to work on action ring.
- Will allow for better compability with other mods. - Will allow for better compability with other mods.
- Might be interesting for keyboard users too. - Might be interesting for keyboard users too.
### v1.4.1
- Fixed crash with [REI](https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items).
## v1.5.0
- Added mappings string editor screen.
- Added Simplified Chinese translations ([#18](https://github.com/LambdAurora/LambdaControls/pull/18)).
- Added Mexican Spanish translations ([#22](https://github.com/LambdAurora/LambdaControls/pull/22)).
- Added Xbox 360 button skin and overhauled Xbox button skin.
- Added debug option.
- Respect toggle setting in Accessibility screen.
- Tweaked rotation speeds.
- Updated to Minecraft 1.16.2.
- Updated [SpruceUI](https://github.com/LambdAurora/SpruceUI) to 1.6.4.
- Overhauled REI compatibility.
- Improved horizontal reach-around.
- Fixed crashes with Ok Zoomer.
- Fixed crashes with key unbinding.
- More WIP on keybind ring.

6
HEADER Normal file
View File

@@ -0,0 +1,6 @@
Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
This file is part of LambdaControls.
Licensed under the MIT license. For more information,
see the LICENSE file.

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -3,7 +3,7 @@
![Java 8](https://img.shields.io/badge/language-Java%208-9B599A.svg?style=flat-square) ![Java 8](https://img.shields.io/badge/language-Java%208-9B599A.svg?style=flat-square)
[![GitHub license](https://img.shields.io/github/license/LambdAurora/LambdaControls?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambdaControls/master/LICENSE) [![GitHub license](https://img.shields.io/github/license/LambdAurora/LambdaControls?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambdaControls/master/LICENSE)
![Environment: Client](https://img.shields.io/badge/environment-client-1976d2?style=flat-square) ![Environment: Client](https://img.shields.io/badge/environment-client-1976d2?style=flat-square)
![Mod loader: Fabric](https://img.shields.io/badge/modloader-Fabric-1976d2?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDIgNzkuMTYwOTI0LCAyMDE3LzA3LzEzLTAxOjA2OjM5ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgMjAxOCAoV2luZG93cykiIHhtcDpDcmVhdGVEYXRlPSIyMDE4LTEyLTE2VDE2OjU0OjE3LTA4OjAwIiB4bXA6TW9kaWZ5RGF0ZT0iMjAxOS0wNy0yOFQyMToxNzo0OC0wNzowMCIgeG1wOk1ldGFkYXRhRGF0ZT0iMjAxOS0wNy0yOFQyMToxNzo0OC0wNzowMCIgZGM6Zm9ybWF0PSJpbWFnZS9wbmciIHBob3Rvc2hvcDpDb2xvck1vZGU9IjMiIHBob3Rvc2hvcDpJQ0NQcm9maWxlPSJzUkdCIElFQzYxOTY2LTIuMSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowZWRiMWMyYy1mZjhjLWU0NDEtOTMxZi00OTVkNGYxNGM3NjAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MGVkYjFjMmMtZmY4Yy1lNDQxLTkzMWYtNDk1ZDRmMTRjNzYwIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6MGVkYjFjMmMtZmY4Yy1lNDQxLTkzMWYtNDk1ZDRmMTRjNzYwIj4gPHhtcE1NOkhpc3Rvcnk+IDxyZGY6U2VxPiA8cmRmOmxpIHN0RXZ0OmFjdGlvbj0iY3JlYXRlZCIgc3RFdnQ6aW5zdGFuY2VJRD0ieG1wLmlpZDowZWRiMWMyYy1mZjhjLWU0NDEtOTMxZi00OTVkNGYxNGM3NjAiIHN0RXZ0OndoZW49IjIwMTgtMTItMTZUMTY6NTQ6MTctMDg6MDAiIHN0RXZ0OnNvZnR3YXJlQWdlbnQ9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE4IChXaW5kb3dzKSIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4/HiGMAAAAtUlEQVRYw+XXrQqAMBQF4D2P2eBL+QIG8RnEJFaNBjEum+0+zMQLtwwv+wV3ZzhhMDgfJ0wUSinxZUQWgKos1JP/AbD4OneIDyQPwCFniA+EJ4CaXm4TxAXCC0BNHgLhAdAnx9hC8PwGSRtAFVMQjF7cNTWED8B1cgwW20yfJgAvrssAsZ1cB3g/xckAxr6FmCDU5N6f488BrpCQ4rQBJkiMYh4ACmLzwOQF0CExinkCsvw7vgGikl+OotaKRwAAAABJRU5ErkJggg==) [![Mod loader: Fabric]][fabric]
![Version](https://img.shields.io/github/v/tag/LambdAurora/LambdaControls?label=version&style=flat-square) ![Version](https://img.shields.io/github/v/tag/LambdAurora/LambdaControls?label=version&style=flat-square)
[![CurseForge](http://cf.way2muchnoise.eu/title/354231.svg)](https://www.curseforge.com/minecraft/mc-mods/lambdacontrols) [![CurseForge](http://cf.way2muchnoise.eu/title/354231.svg)](https://www.curseforge.com/minecraft/mc-mods/lambdacontrols)
@@ -40,6 +40,16 @@ This mod also adds controller support.
- Joycons - Joycons
- And many more! - And many more!
## Screenshots
![controller_controls]
![controller_options]
## Build ## Build
Just do `./gradlew :fabric:shadowRemapJar` and everything should build just fine! Just do `./gradlew shadowRemapJar` and everything should build just fine!
[controller_controls]: images/controller_controls.png
[controller_options]: images/controller_options.png
[fabric]: https://fabricmc.net
[Mod loader: Fabric]: https://img.shields.io/badge/modloader-Fabric-1976d2?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDIgNzkuMTYwOTI0LCAyMDE3LzA3LzEzLTAxOjA2OjM5ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgMjAxOCAoV2luZG93cykiIHhtcDpDcmVhdGVEYXRlPSIyMDE4LTEyLTE2VDE2OjU0OjE3LTA4OjAwIiB4bXA6TW9kaWZ5RGF0ZT0iMjAxOS0wNy0yOFQyMToxNzo0OC0wNzowMCIgeG1wOk1ldGFkYXRhRGF0ZT0iMjAxOS0wNy0yOFQyMToxNzo0OC0wNzowMCIgZGM6Zm9ybWF0PSJpbWFnZS9wbmciIHBob3Rvc2hvcDpDb2xvck1vZGU9IjMiIHBob3Rvc2hvcDpJQ0NQcm9maWxlPSJzUkdCIElFQzYxOTY2LTIuMSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowZWRiMWMyYy1mZjhjLWU0NDEtOTMxZi00OTVkNGYxNGM3NjAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MGVkYjFjMmMtZmY4Yy1lNDQxLTkzMWYtNDk1ZDRmMTRjNzYwIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6MGVkYjFjMmMtZmY4Yy1lNDQxLTkzMWYtNDk1ZDRmMTRjNzYwIj4gPHhtcE1NOkhpc3Rvcnk+IDxyZGY6U2VxPiA8cmRmOmxpIHN0RXZ0OmFjdGlvbj0iY3JlYXRlZCIgc3RFdnQ6aW5zdGFuY2VJRD0ieG1wLmlpZDowZWRiMWMyYy1mZjhjLWU0NDEtOTMxZi00OTVkNGYxNGM3NjAiIHN0RXZ0OndoZW49IjIwMTgtMTItMTZUMTY6NTQ6MTctMDg6MDAiIHN0RXZ0OnNvZnR3YXJlQWdlbnQ9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE4IChXaW5kb3dzKSIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4/HiGMAAAAtUlEQVRYw+XXrQqAMBQF4D2P2eBL+QIG8RnEJFaNBjEum+0+zMQLtwwv+wV3ZzhhMDgfJ0wUSinxZUQWgKos1JP/AbD4OneIDyQPwCFniA+EJ4CaXm4TxAXCC0BNHgLhAdAnx9hC8PwGSRtAFVMQjF7cNTWED8B1cgwW20yfJgAvrssAsZ1cB3g/xckAxr6FmCDU5N6f488BrpCQ4rQBJkiMYh4ACmLzwOQF0CExinkCsvw7vgGikl+OotaKRwAAAABJRU5ErkJggg==

View File

@@ -1,25 +1,148 @@
plugins { buildscript {
id 'java-library' dependencies {
id 'maven-publish' constraints {
["asm", "asm-util", "asm-tree", "asm-analysis"].each {
classpath("org.ow2.asm:$it") {
version { require("9.1") }
because("Fabric's TinyRemapper requires ASM 9")
}
}
}
}
} }
allprojects { plugins {
id 'fabric-loom' version '0.6-SNAPSHOT'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'org.cadixdev.licenser' version '0.5.0'
}
import net.fabricmc.loom.task.RemapJarTask
group = project.maven_group group = project.maven_group
version = project.mod_version version = "${project.mod_version}+${getMCVersionString()}"
archivesBaseName = project.archives_base_name + "-fabric"
// This field defines the Java version your mod target.
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too.
def targetJavaVersion = 8
def getMCVersionString() {
if (project.minecraft_version.matches("\\d\\dw\\d\\d[a-z]")) {
return project.minecraft_version
}
int lastDot = project.minecraft_version.lastIndexOf('.')
return project.minecraft_version.substring(0, lastDot)
}
minecraft {
}
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
maven { url = 'https://aperlambda.github.io/maven' } maven { url = 'https://aperlambda.github.io/maven' }
maven {
name = 'CottonMC'
url = 'http://server.bbkr.space:8081/artifactory/libs-snapshot'
}
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases'
}
maven { url "https://maven.shedaniel.me/" }
maven { url = "https://jitpack.io" }
}
configurations {
shadow
api.extendsFrom shadow
} }
dependencies { dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation "com.github.lambdaurora:spruceui:${project.spruceui_version}"
include "com.github.lambdaurora:spruceui:${project.spruceui_version}"
// Compatibility mods
modImplementation("com.github.joaoh1:okzoomer:e13183c59b") {
exclude group: 'me.shedaniel.cloth'
exclude group: 'io.github.prospector'
} }
tasks.withType(JavaCompile) { modImplementation("me.shedaniel:RoughlyEnoughItems:5.10.184")
options.encoding = "UTF-8"
shadow "com.electronwill.night-config:core:3.6.3"
shadow "com.electronwill.night-config:toml:3.6.3"
} }
java {
sourceCompatibility = JavaVersion.toVersion(targetJavaVersion)
targetCompatibility = JavaVersion.toVersion(targetJavaVersion)
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (JavaVersion.current().isJava9Compatible()) {
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetJavaVersion
}
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}
license {
header file('HEADER')
include '**/*.java'
}
shadowJar {
dependsOn jar
configurations = [project.configurations.shadow]
archiveClassifier.set('dev')
exclude 'META-INF/maven/**'
exclude 'com/google/**'
exclude 'javax/**'
exclude 'org/**'
relocate 'com.electronwill.nightconfig', 'dev.lambdaurora.lambdacontrols.shadow.nightconfig'
}
task shadowRemapJar(type: RemapJarTask) {
dependsOn shadowJar
input = file("${project.buildDir}/libs/$archivesBaseName-$version-dev.jar")
archiveName = "${archivesBaseName}-${version}.jar"
addNestedDependencies = true
}
// configure the maven publication
publishing { publishing {
repositories { repositories {
mavenLocal() mavenLocal()
@@ -32,12 +155,7 @@ allprojects {
} }
} }
} }
}
}
/*
// configure the maven publication
publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven // add all the jars that should be included when publishing to maven
@@ -49,9 +167,4 @@ publishing {
} }
} }
} }
// select the repositories you want to publish to
repositories {
mavenLocal()
} }
}*/

View File

@@ -1,32 +0,0 @@
plugins {
id 'java-library'
id 'maven-publish'
}
archivesBaseName = project.archives_base_name + "-core"
dependencies {
api "org.jetbrains:annotations:17.0.0"
api "org.aperlambda:lambdajcommon:1.8.0"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(jar) {
builtBy jar
}
artifact(sourcesJar) {
builtBy sourcesJar
}
}
}
}

View File

@@ -1,21 +0,0 @@
plugins {
id 'java-library'
}
archivesBaseName = project.archives_base_name + "-elytra"
repositories {
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url = 'https://mcelytra.github.io/maven/' }
maven { url = 'https://libraries.minecraft.net/' }
}
dependencies {
api project(":core")
implementation "org.mcelytra:elytra-core:1.0.0-SNAPSHOT"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.event;
import me.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControlsConstants;
import org.aperlambda.lambdacommon.Identifier;
import org.jetbrains.annotations.NotNull;
import org.mcelytra.core.entity.EntityPlayer;
import org.mcelytra.core.event.HandlerList;
import org.mcelytra.core.event.player.PlayerEvent;
/**
* Represents an event which is fired when a player change their controls mode.
*
* @author LambdAurora
* @version 1.1.0
* @since 1.1.0
*/
public class PlayerControlsModeEvent extends PlayerEvent
{
private static final HandlerList HANDLERS = new HandlerList();
private final ControlsMode controlsMode;
public PlayerControlsModeEvent(@NotNull EntityPlayer player, @NotNull ControlsMode controlsMode)
{
super(new Identifier(LambdaControlsConstants.NAMESPACE, "player_controls_mode"), player, true);
this.controlsMode = controlsMode;
}
/**
* Returns the controls mode of the player.
*
* @return The player's controls mode.
*/
public ControlsMode getControlsMode()
{
return this.controlsMode;
}
@Override
public @NotNull HandlerList getHandlers()
{
return HANDLERS;
}
}

View File

@@ -1,137 +0,0 @@
import net.fabricmc.loom.task.RemapJarTask
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'java-library'
id 'maven-publish'
}
version = "${project.mod_version}+${project.minecraft_version}"
archivesBaseName = project.archives_base_name + "-fabric"
minecraft {
}
repositories {
maven {
name = 'CottonMC'
url = 'http://server.bbkr.space:8081/artifactory/libs-snapshot'
}
repositories {
maven { url = "https://jitpack.io" }
}
// OkZoomer
ivy {
url 'https://github.com/joaoh1/OkZoomer/releases/download/'
patternLayout {
artifact '[revision]/[module]-[revision].[ext]'
}
metadataSources() {
artifact()
}
}
}
configurations {
shadowInternal
shadow
api.extendsFrom shadow
}
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
modImplementation "com.github.lambdaurora:spruceui:${project.spruceui_version}"
include "com.github.lambdaurora:spruceui:${project.spruceui_version}"
// Compatibility mods
modImplementation "io.github.joaoh1:okzoomer:4.0.0-alpha.4.1.16.1"
modImplementation "me.shedaniel:RoughlyEnoughItems:4.5.5"
api project(":core")
shadowInternal project(":core")
shadow("org.aperlambda:lambdajcommon:1.8.0") {
// Minecraft already has all that google crap.
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'
}
shadow "com.electronwill.night-config:core:3.5.3"
shadow "com.electronwill.night-config:toml:3.5.3"
}
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}
jar {
from "../LICENSE"
}
task shadowJar(type: Jar) {
archiveClassifier.set("dev")
from sourceSets.main.output
from {
configurations.shadowInternal.filter {
it.getName().contains("lambdacontrols")
}.collect {
it.isDirectory() ? it : zipTree(it)
}
}
from {
configurations.shadow.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
task shadowRemapJar(type: RemapJarTask) {
dependsOn shadowJar
input = file("${project.buildDir}/libs/$archivesBaseName-$version-dev.jar")
archiveName = "${archivesBaseName}-${version}.jar"
addNestedDependencies = true
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
}
shadowJar.dependsOn(":core:jar")
build.dependsOn(":core:build")
publish.dependsOn(":core:publish")

View File

@@ -1,63 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.compat;
import io.github.joaoh1.okzoomer.client.OkZoomerClientMod;
import io.github.joaoh1.okzoomer.main.OkZoomerMod;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import org.aperlambda.lambdacommon.Identifier;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
/**
* Represents a compatibility handler for OkZoomer.
*
* @author LambdAurora
* @version 1.3.0
* @since 1.1.0
*/
public class OkZoomerCompat implements CompatHandler
{
public static final String OKZOOMER_CLASS_PATH = "io.github.joaoh1.okzoomer.client.OkZoomerClientMod";
@Override
public void handle(@NotNull LambdaControlsClient mod)
{
new ButtonBinding.Builder("zoom")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X)
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(OkZoomerClientMod.zoomKeyBinding)
.register();
new ButtonBinding.Builder("zoom.in")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(OkZoomerClientMod.increaseZoomKeyBinding)
.register();
new ButtonBinding.Builder("zoom.out")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(OkZoomerClientMod.decreaseZoomKeyBinding)
.register();
new ButtonBinding.Builder("zoom.reset")
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(OkZoomerClientMod.resetZoomKeyBinding)
.register();
}
}

View File

@@ -1,190 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.compat;
import me.lambdaurora.lambdacontrols.client.ButtonState;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.compat.mixin.RecipeViewingScreenAccessor;
import me.lambdaurora.lambdacontrols.client.compat.mixin.VillagerRecipeViewingScreenAccessor;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.InputHandlers;
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.lambdacontrols.client.controller.PressAction;
import me.shedaniel.rei.api.REIHelper;
import me.shedaniel.rei.api.RecipeCategory;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.RecipeViewingScreen;
import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
import me.shedaniel.rei.gui.widget.EntryListWidget;
import me.shedaniel.rei.impl.ScreenHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Identifier;
import org.aperlambda.lambdacommon.utils.LambdaReflection;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
import static org.lwjgl.glfw.GLFW.*;
/**
* Represents a compatibility handler for REI.
*
* @author LambdAurora
* @version 1.4.0
* @since 1.2.0
*/
public class ReiCompat implements CompatHandler
{
private static EntryListWidget ENTRY_LIST_WIDGET;
@Override
public void handle(@NotNull LambdaControlsClient mod)
{
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "category_back"))
.buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleTab(false))
.cooldown(true)
.build());
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "category_next"))
.buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleTab(true))
.cooldown(true)
.build());
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "page_back"))
.buttons(ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_X, false))
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handlePage(false))
.cooldown(true)
.build());
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "page_next"))
.buttons(ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_X, true))
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handlePage(true))
.cooldown(true)
.build());
// For some reasons this is broken.
InputManager.registerBinding(new ButtonBinding.Builder(new Identifier("rei", "show_usage"))
.buttons(GLFW_GAMEPAD_BUTTON_RIGHT_THUMB)
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action((client, button, value, action) -> {
if (action != ButtonState.RELEASE)
return false;
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (!overlay.isPresent())
return false;
double mouseX = client.mouse.getX();
double mouseY = client.mouse.getY();
EntryListWidget widget = getEntryListWidget();
if (widget == null)
return false;
return widget.mouseClicked(mouseX, mouseY, GLFW_MOUSE_BUTTON_2);
})
.cooldown(true)
.build());
}
@Override
public boolean requireMouseOnScreen(Screen screen)
{
return isViewingScreen(screen);
}
private static boolean isViewingScreen(Screen screen)
{
return screen instanceof RecipeViewingScreen || screen instanceof VillagerRecipeViewingScreen;
}
@Override
public boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen)
{
if (!isViewingScreen(screen))
return false;
MinecraftClient.getInstance().openScreen(REIHelper.getInstance().getPreviousContainerScreen());
ScreenHelper.getLastOverlay().init();
return true;
}
private static EntryListWidget getEntryListWidget()
{
if (ENTRY_LIST_WIDGET == null) {
ENTRY_LIST_WIDGET = LambdaReflection.getFirstFieldOfType(ContainerScreenOverlay.class, EntryListWidget.class)
.map(field -> (EntryListWidget) LambdaReflection.getFieldValue(null, field))
.orElse(null);
}
return ENTRY_LIST_WIDGET;
}
private static PressAction handlePage(boolean next)
{
return (client, button, value, action) -> {
if (action == ButtonState.RELEASE)
return false;
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (!overlay.isPresent())
return false;
EntryListWidget widget = getEntryListWidget();
if (widget == null)
return false;
if (next)
widget.nextPage();
else
widget.previousPage();
widget.updateEntriesPosition();
return true;
};
}
/**
* Returns the handler for category tabs buttons.
*
* @param next True if the action is to switch to the next tab.
* @return The handler.
*/
private static PressAction handleTab(boolean next)
{
return (client, button, value, action) -> {
if (action != ButtonState.RELEASE)
return false;
if (client.currentScreen instanceof RecipeViewingScreen) {
RecipeViewingScreenAccessor screen = (RecipeViewingScreenAccessor) client.currentScreen;
if (next)
screen.getCategoryNext().onClick();
else
screen.getCategoryBack().onClick();
return true;
} else if (client.currentScreen instanceof VillagerRecipeViewingScreen) {
VillagerRecipeViewingScreenAccessor screen = (VillagerRecipeViewingScreenAccessor) client.currentScreen;
List<RecipeCategory<?>> categories = screen.getCategories();
int currentTab = screen.getSelectedCategoryIndex();
int nextTab = currentTab + (next ? 1 : -1);
if (nextTab < 0)
nextTab = categories.size() - 1;
else if (nextTab >= categories.size())
nextTab = 0;
screen.setSelectedCategoryIndex(nextTab);
screen.lambdacontrols_init();
return true;
}
return false;
};
}
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.spruceui.SpruceButtonWidget;
import me.lambdaurora.spruceui.SpruceTexts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.function.Predicates;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* Represents the controls screen.
*/
public class ControllerControlsScreen extends Screen
{
private final Screen parent;
final LambdaControlsClient mod;
private final boolean hideSettings;
private ControlsListWidget bindingsListWidget;
private ButtonWidget resetButton;
public ButtonBinding focusedBinding;
public boolean waiting = false;
public List<Integer> currentButtons = new ArrayList<>();
public ControllerControlsScreen(@NotNull Screen parent, boolean hideSettings)
{
super(new TranslatableText("lambdacontrols.menu.title.controller_controls"));
this.parent = parent;
this.mod = LambdaControlsClient.get();
this.hideSettings = hideSettings;
}
@Override
public void removed()
{
this.mod.config.save();
super.removed();
}
@Override
protected void init()
{
this.addButton(new SpruceButtonWidget(this.width / 2 - 155, 18, this.hideSettings ? 310 : 150, 20,
new TranslatableText("lambdacontrols.menu.keyboard_controls"),
btn -> this.client.openScreen(new ControlsOptionsScreen(this, this.client.options))));
if (!this.hideSettings)
this.addButton(new SpruceButtonWidget(this.width / 2 - 155 + 160, 18, 150, 20,
SpruceTexts.MENU_OPTIONS,
btn -> this.client.openScreen(new LambdaControlsSettingsScreen(this, true))));
this.bindingsListWidget = new ControlsListWidget(this, this.client);
this.children.add(this.bindingsListWidget);
this.resetButton = this.addButton(new ButtonWidget(this.width / 2 - 155, this.height - 29, 150, 20,
new TranslatableText("controls.resetAll"),
btn -> InputManager.streamBindings().forEach(binding -> this.mod.config.setButtonBinding(binding, binding.getDefaultButton()))));
this.addButton(new ButtonWidget(this.width / 2 - 155 + 160, this.height - 29, 150, 20,
SpruceTexts.GUI_DONE,
btn -> this.client.openScreen(this.parent)));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
{
this.renderBackground(matrices);
this.bindingsListWidget.render(matrices, mouseX, mouseY, delta);
this.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
this.resetButton.active = InputManager.streamBindings().anyMatch(Predicates.not(ButtonBinding::isDefault));
super.render(matrices, mouseX, mouseY, delta);
}
}

View File

@@ -1,214 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.ButtonCategory;
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.spruceui.SpruceTexts;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Represents a control list widget.
*/
public class ControlsListWidget extends ElementListWidget<ControlsListWidget.Entry>
{
private static final int[] UNBOUND = new int[0];
private final ControllerControlsScreen gui;
private int field_2733;
public ControlsListWidget(@NotNull ControllerControlsScreen gui, @NotNull MinecraftClient client)
{
super(client, gui.width + 45, gui.height, 43, gui.height - 32, 24);
this.gui = gui;
InputManager.streamCategories()
.sorted(Comparator.comparingInt(ButtonCategory::getPriority))
.forEach(category -> {
this.addEntry(new CategoryEntry(category));
category.getBindings().forEach(binding -> {
int i = client.textRenderer.getWidth(I18n.translate(binding.getTranslationKey()));
if (i > this.field_2733) {
this.field_2733 = i;
}
this.addEntry(new ControlsListWidget.ButtonBindingEntry(binding));
});
});
}
@Override
protected int getScrollbarPositionX()
{
return super.getScrollbarPositionX() + 15;
}
@Override
public int getRowWidth()
{
return super.getRowWidth() + 32;
}
public class ButtonBindingEntry extends Entry
{
private final ButtonBinding binding;
private final String bindingName;
private final ControllerButtonWidget editButton;
private final ButtonWidget resetButton;
private final ButtonWidget unboundButton;
ButtonBindingEntry(@NotNull ButtonBinding binding)
{
this.binding = binding;
this.bindingName = I18n.translate(this.binding.getTranslationKey());
this.editButton = new ControllerButtonWidget(0, 0, 110, this.binding, btn -> {
gui.focusedBinding = binding;
gui.currentButtons.clear();
gui.waiting = true;
})
{
protected MutableText getNarrationMessage()
{
return binding.isNotBound() ? new TranslatableText("narrator.controls.unbound", bindingName) : new TranslatableText("narrator.controls.bound", bindingName, super.getNarrationMessage());
}
};
this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"),
btn -> gui.mod.config.setButtonBinding(binding, binding.getDefaultButton()))
{
protected MutableText getNarrationMessage()
{
return new TranslatableText("narrator.controls.reset", bindingName);
}
};
this.unboundButton = new ButtonWidget(0, 0, 50, 20, SpruceTexts.OPTIONS_GENERIC_UNBOUND,
btn -> {
gui.mod.config.setButtonBinding(binding, UNBOUND);
gui.focusedBinding = null;
})
{
protected MutableText getNarrationMessage()
{
return new TranslatableText("lambdacontrols.narrator.unbound", bindingName);
}
};
}
@Override
public List<? extends Element> children()
{
return Collections.unmodifiableList(Arrays.asList(this.editButton, this.resetButton));
}
@Override
public void render(MatrixStack matrices, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float delta)
{
boolean focused = gui.focusedBinding == this.binding;
TextRenderer textRenderer = ControlsListWidget.this.client.textRenderer;
String bindingName = this.bindingName;
float var10002 = (float) (x + 70 - ControlsListWidget.this.field_2733);
int var10003 = y + height / 2;
textRenderer.draw(matrices, bindingName, var10002, (float) (var10003 - 9 / 2), 16777215);
this.resetButton.x = this.unboundButton.x = x + 190;
this.resetButton.y = this.unboundButton.y = y;
this.resetButton.active = !this.binding.isDefault();
if (focused)
this.unboundButton.render(matrices, mouseX, mouseY, delta);
else
this.resetButton.render(matrices, mouseX, mouseY, delta);
this.editButton.x = x + 75;
this.editButton.y = y;
this.editButton.update();
if (focused) {
MutableText text = new LiteralText("> ").formatted(Formatting.WHITE);
text.append(this.editButton.getMessage().copy().formatted(Formatting.YELLOW));
this.editButton.setMessage(text.append(new LiteralText(" <").formatted(Formatting.WHITE)));
} else if (!this.binding.isNotBound() && InputManager.hasDuplicatedBindings(this.binding)) {
MutableText text = this.editButton.getMessage().copy();
this.editButton.setMessage(text.formatted(Formatting.RED));
} else if (this.binding.isNotBound()) {
MutableText text = this.editButton.getMessage().copy();
this.editButton.setMessage(text.formatted(Formatting.GOLD));
}
this.editButton.render(matrices, mouseX, mouseY, delta);
}
public boolean mouseClicked(double mouseX, double mouseY, int button)
{
boolean focused = gui.focusedBinding == this.binding;
if (this.editButton.mouseClicked(mouseX, mouseY, button))
return true;
else
return focused ? this.unboundButton.mouseClicked(mouseX, mouseY, button) : this.resetButton.mouseClicked(mouseX, mouseY, button);
}
public boolean mouseReleased(double mouseX, double mouseY, int button)
{
return this.editButton.mouseReleased(mouseX, mouseY, button) || this.resetButton.mouseReleased(mouseX, mouseY, button)
|| this.unboundButton.mouseReleased(mouseX, mouseY, button);
}
}
public class CategoryEntry extends Entry
{
private final String name;
private final int nameWidth;
public CategoryEntry(@NotNull ButtonCategory category)
{
this.name = category.getTranslatedName();
this.nameWidth = ControlsListWidget.this.client.textRenderer.getWidth(this.name);
}
@Override
public void render(MatrixStack matrices, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float delta)
{
ControlsListWidget.this.client.textRenderer.draw(matrices, this.name, (float) (ControlsListWidget.this.client.currentScreen.width / 2 - this.nameWidth / 2),
(float) ((y + height) - 9 - 1), 16777215);
}
@Override
public boolean changeFocus(boolean bl)
{
return false;
}
@Override
public List<? extends Element> children()
{
return Collections.emptyList();
}
}
@Environment(EnvType.CLIENT)
public abstract static class Entry extends ElementListWidget.Entry<Entry>
{
}
}

View File

@@ -1,287 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControls;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.spruceui.SpruceButtonWidget;
import me.lambdaurora.spruceui.SpruceLabelWidget;
import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.Tooltip;
import me.lambdaurora.spruceui.option.*;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
import net.minecraft.client.gui.widget.ButtonListWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.options.Option;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
import org.lwjgl.glfw.GLFW;
/**
* Represents the LambdaControls settings screen.
*/
public class LambdaControlsSettingsScreen extends Screen
{
public static final String GAMEPAD_TOOL_URL = "https://generalarcade.com/gamepadtool/";
final LambdaControlsClient mod;
private final Screen parent;
private final boolean hideControls;
// General options
private final Option autoSwitchModeOption;
private final Option rotationSpeedOption;
private final Option mouseSpeedOption;
private final Option resetOption;
// Gameplay options
private final Option autoJumpOption;
private final Option fastBlockPlacingOption;
private final Option frontBlockPlacingOption;
private final Option verticalReacharoundOption;
private final Option flyDriftingOption;
private final Option flyVerticalDriftingOption;
// Controller options
private final Option controllerOption;
private final Option secondControllerOption;
private final Option controllerTypeOption;
private final Option deadZoneOption;
private final Option invertsRightXAxis;
private final Option invertsRightYAxis;
private final Option unfocusedInputOption;
private final Option virtualMouseOption;
private final Option virtualMouseSkinOption;
// Hud options
private final Option hudEnableOption;
private final Option hudSideOption;
private final MutableText controllerMappingsUrlText = new LiteralText("(")
.append(new LiteralText(GAMEPAD_TOOL_URL).formatted(Formatting.GOLD))
.append("),");
private ButtonListWidget list;
private SpruceLabelWidget gamepadToolUrlLabel;
public LambdaControlsSettingsScreen(Screen parent, boolean hideControls)
{
super(new TranslatableText("lambdacontrols.title.settings"));
this.mod = LambdaControlsClient.get();
this.parent = parent;
this.hideControls = hideControls;
// General options
this.autoSwitchModeOption = new SpruceBooleanOption("lambdacontrols.menu.auto_switch_mode", this.mod.config::hasAutoSwitchMode,
this.mod.config::setAutoSwitchMode, new TranslatableText("lambdacontrols.tooltip.auto_switch_mode"), true);
this.rotationSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.rotation_speed", 0.0, 100.0, 0.5F, this.mod.config::getRotationSpeed,
newValue -> {
synchronized (this.mod.config) {
this.mod.config.setRotationSpeed(newValue);
}
}, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))),
new TranslatableText("lambdacontrols.tooltip.rotation_speed"));
this.mouseSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.mouse_speed", 0.0, 150.0, 0.5F, this.mod.config::getMouseSpeed,
newValue -> {
synchronized (this.mod.config) {
this.mod.config.setMouseSpeed(newValue);
}
}, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))),
new TranslatableText("lambdacontrols.tooltip.mouse_speed"));
this.resetOption = new SpruceResetOption(btn -> {
this.mod.config.reset();
MinecraftClient client = MinecraftClient.getInstance();
this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
});
// Gameplay options
this.autoJumpOption = SpruceBooleanOption.fromVanilla("options.autoJump", Option.AUTO_JUMP, null, true);
this.fastBlockPlacingOption = new SpruceBooleanOption("lambdacontrols.menu.fast_block_placing", this.mod.config::hasFastBlockPlacing,
this.mod.config::setFastBlockPlacing, new TranslatableText("lambdacontrols.tooltip.fast_block_placing"), true);
this.frontBlockPlacingOption = new SpruceBooleanOption("lambdacontrols.menu.reacharound.horizontal", this.mod.config::hasFrontBlockPlacing,
this.mod.config::setFrontBlockPlacing, new TranslatableText("lambdacontrols.tooltip.reacharound.horizontal"), true);
this.verticalReacharoundOption = new SpruceBooleanOption("lambdacontrols.menu.reacharound.vertical", this.mod.config::hasVerticalReacharound,
this.mod.config::setVerticalReacharound, new TranslatableText("lambdacontrols.tooltip.reacharound.vertical"), true);
this.flyDriftingOption = new SpruceBooleanOption("lambdacontrols.menu.fly_drifting", this.mod.config::hasFlyDrifting,
this.mod.config::setFlyDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting"), true);
this.flyVerticalDriftingOption = new SpruceBooleanOption("lambdacontrols.menu.fly_drifting_vertical", this.mod.config::hasFlyVerticalDrifting,
this.mod.config::setFlyVerticalDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting_vertical"), true);
// Controller options
this.controllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller", amount -> {
int id = this.mod.config.getController().getId();
id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST)
id = GLFW.GLFW_JOYSTICK_1;
this.mod.config.setController(Controller.byId(id));
}, option -> {
String controllerName = this.mod.config.getController().getName();
if (!this.mod.config.getController().isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
else if (!this.mod.config.getController().isGamepad())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD));
else
return option.getDisplayText(new LiteralText(controllerName));
}, null);
this.secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2",
amount -> {
int id = this.mod.config.getSecondController().map(Controller::getId).orElse(-1);
id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST)
id = -1;
this.mod.config.setSecondController(id == -1 ? null : Controller.byId(id));
}, option -> this.mod.config.getSecondController().map(controller -> {
String controllerName = controller.getName();
if (!controller.isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
else if (!controller.isGamepad())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD));
else
return option.getDisplayText(new LiteralText(controllerName));
}).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))),
new TranslatableText("lambdacontrols.tooltip.controller2"));
this.controllerTypeOption = new SpruceCyclingOption("lambdacontrols.menu.controller_type",
amount -> this.mod.config.setControllerType(this.mod.config.getControllerType().next()),
option -> option.getDisplayText(this.mod.config.getControllerType().getTranslatedText()),
new TranslatableText("lambdacontrols.tooltip.controller_type"));
this.deadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.dead_zone", 0.05, 1.0, 0.05F, this.mod.config::getDeadZone,
newValue -> {
synchronized (this.mod.config) {
this.mod.config.setDeadZone(newValue);
}
}, option -> {
String value = String.valueOf(option.get());
return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5))));
}, new TranslatableText("lambdacontrols.tooltip.dead_zone"));
this.invertsRightXAxis = new SpruceBooleanOption("lambdacontrols.menu.invert_right_x_axis", this.mod.config::doesInvertRightXAxis,
newValue -> {
synchronized (this.mod.config) {
this.mod.config.setInvertRightXAxis(newValue);
}
}, null, true);
this.invertsRightYAxis = new SpruceBooleanOption("lambdacontrols.menu.invert_right_y_axis", this.mod.config::doesInvertRightYAxis,
newValue -> {
synchronized (this.mod.config) {
this.mod.config.setInvertRightYAxis(newValue);
}
}, null, true);
this.unfocusedInputOption = new SpruceBooleanOption("lambdacontrols.menu.unfocused_input", this.mod.config::hasUnfocusedInput,
this.mod.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input"), true);
this.virtualMouseOption = new SpruceBooleanOption("lambdacontrols.menu.virtual_mouse", this.mod.config::hasVirtualMouse,
this.mod.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse"), true);
this.virtualMouseSkinOption = new SpruceCyclingOption("lambdacontrols.menu.virtual_mouse.skin",
amount -> this.mod.config.setVirtualMouseSkin(this.mod.config.getVirtualMouseSkin().next()),
option -> option.getDisplayText(this.mod.config.getVirtualMouseSkin().getTranslatedText()),
null);
// HUD options
this.hudEnableOption = new SpruceBooleanOption("lambdacontrols.menu.hud_enable", this.mod.config::isHudEnabled,
this.mod::setHudEnabled, new TranslatableText("lambdacontrols.tooltip.hud_enable"), true);
this.hudSideOption = new SpruceCyclingOption("lambdacontrols.menu.hud_side",
amount -> this.mod.config.setHudSide(this.mod.config.getHudSide().next()),
option -> option.getDisplayText(this.mod.config.getHudSide().getTranslatedText()),
new TranslatableText("lambdacontrols.tooltip.hud_side"));
}
@Override
public void removed()
{
this.mod.config.save();
super.removed();
}
@Override
public void onClose()
{
this.mod.config.save();
super.onClose();
}
private int getTextHeight()
{
return (5 + this.textRenderer.fontHeight) * 3 + 5;
}
@Override
protected void init()
{
super.init();
int buttonHeight = 20;
SpruceButtonWidget controlsModeBtn = new SpruceButtonWidget(this.width / 2 - 155, 18, this.hideControls ? 310 : 150, buttonHeight,
new TranslatableText("lambdacontrols.menu.controls_mode").append(": ").append(new TranslatableText(this.mod.config.getControlsMode().getTranslationKey())),
btn -> {
ControlsMode next = this.mod.config.getControlsMode().next();
btn.setMessage(new TranslatableText("lambdacontrols.menu.controls_mode").append(": ").append(new TranslatableText(next.getTranslationKey())));
this.mod.config.setControlsMode(next);
this.mod.config.save();
if (this.client.player != null) {
ClientSidePacketRegistry.INSTANCE.sendToServer(LambdaControls.CONTROLS_MODE_CHANNEL, this.mod.makeControlsModeBuffer(next));
}
});
controlsModeBtn.setTooltip(new TranslatableText("lambdacontrols.tooltip.controls_mode"));
this.addButton(controlsModeBtn);
if (!this.hideControls)
this.addButton(new ButtonWidget(this.width / 2 - 155 + 160, 18, 150, buttonHeight, new TranslatableText("options.controls"),
btn -> {
if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER)
this.client.openScreen(new ControllerControlsScreen(this, true));
else
this.client.openScreen(new ControlsOptionsScreen(this, this.client.options));
}));
this.list = new ButtonListWidget(this.client, this.width, this.height, 43, this.height - 29 - this.getTextHeight(), 25);
// General options
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.general", true, null));
this.list.addOptionEntry(this.rotationSpeedOption, this.mouseSpeedOption);
this.list.addSingleOptionEntry(this.autoSwitchModeOption);
// Gameplay options
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.gameplay", true, null));
this.list.addOptionEntry(this.autoJumpOption, this.fastBlockPlacingOption);
this.list.addOptionEntry(this.frontBlockPlacingOption, this.verticalReacharoundOption);
this.list.addSingleOptionEntry(this.flyDriftingOption);
this.list.addSingleOptionEntry(this.flyVerticalDriftingOption);
// Controller options
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.controller", true, null));
this.list.addSingleOptionEntry(this.controllerOption);
this.list.addSingleOptionEntry(this.secondControllerOption);
this.list.addOptionEntry(this.controllerTypeOption, this.deadZoneOption);
this.list.addOptionEntry(this.invertsRightXAxis, this.invertsRightYAxis);
this.list.addOptionEntry(this.unfocusedInputOption, this.virtualMouseOption);
this.list.addSingleOptionEntry(this.virtualMouseSkinOption);
this.list.addSingleOptionEntry(new ReloadControllerMappingsOption());
// HUD options
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.hud", true, null));
this.list.addOptionEntry(this.hudEnableOption, this.hudSideOption);
this.children.add(this.list);
this.gamepadToolUrlLabel = new SpruceLabelWidget(this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight) * 2, this.controllerMappingsUrlText, this.width,
label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true);
this.gamepadToolUrlLabel.setTooltip(new TranslatableText("chat.link.open"));
this.children.add(this.gamepadToolUrlLabel);
this.addButton(this.resetOption.createButton(this.client.options, this.width / 2 - 155, this.height - 29, 150));
this.addButton(new ButtonWidget(this.width / 2 - 155 + 160, this.height - 29, 150, buttonHeight, SpruceTexts.GUI_DONE,
(buttonWidget) -> this.client.openScreen(this.parent)));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
{
this.renderBackground(matrices);
this.list.render(matrices, mouseX, mouseY, delta);
super.render(matrices, mouseX, mouseY, delta);
this.drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.menu.title"), this.width / 2, 8, 16777215);
this.drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.1", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight) * 3, 10526880);
this.gamepadToolUrlLabel.render(matrices, mouseX, mouseY, delta);
this.drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.3", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight), 10526880);
Tooltip.renderAll(matrices);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.spruceui.SpruceButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.options.GameOptions;
import net.minecraft.client.options.Option;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;
/**
* Represents the option to reload the controller mappings.
*/
public class ReloadControllerMappingsOption extends Option implements Nameable
{
private static final String KEY = "lambdacontrols.menu.reload_controller_mappings";
public ReloadControllerMappingsOption()
{
super(KEY);
}
@Override
public AbstractButtonWidget createButton(GameOptions options, int x, int y, int width)
{
SpruceButtonWidget button = new SpruceButtonWidget(x, y, width, 20, new TranslatableText(KEY), btn -> {
MinecraftClient client = MinecraftClient.getInstance();
Controller.updateMappings();
if (client.currentScreen != null)
client.currentScreen.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
client.getToastManager().add(new SystemToast(SystemToast.Type.TUTORIAL_HINT, new TranslatableText("lambdacontrols.controller.mappings.updated"), null));
});
button.setTooltip(new TranslatableText("lambdacontrols.tooltip.reload_controller_mappings"));
return button;
}
@Override
public @NotNull String getName()
{
return I18n.translate(KEY);
}
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.LambdaControls;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
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(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin
{
@Inject(method = "onGameJoin", at = @At(value = "TAIL"))
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci)
{
ClientSidePacketRegistry.INSTANCE.sendToServer(LambdaControls.HELLO_CHANNEL, LambdaControls.get().makeHello(LambdaControlsClient.get().config.getControlsMode()));
ClientSidePacketRegistry.INSTANCE.sendToServer(LambdaControls.CONTROLS_MODE_CHANNEL,
LambdaControls.get().makeControlsModeBuffer(LambdaControlsClient.get().config.getControlsMode()));
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.ring;
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import net.minecraft.client.options.KeyBinding;
import org.jetbrains.annotations.NotNull;
public class KeyBindingRingAction extends RingAction
{
public final KeyBinding binding;
public KeyBindingRingAction(@NotNull KeyBinding binding)
{
this.binding = binding;
}
@Override
public @NotNull String getName()
{
return this.binding.getTranslationKey();
}
@Override
public void onAction(@NotNull RingButtonMode mode)
{
KeyBindingAccessor accessor = (KeyBindingAccessor) this.binding;
switch (mode) {
case PRESS:
case HOLD:
accessor.lambdacontrols_handlePressState(this.activated);
break;
case TOGGLE:
accessor.lambdacontrols_handlePressState(!this.binding.isPressed());
this.activated = !this.binding.isPressed();
break;
}
}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.ring;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Represents a key binding ring.
*
* @author LambdAurora
* @version 1.4.0
* @since 1.4.0
*/
public class LambdaRing
{
private final List<RingPage> pages = new ArrayList<>(Collections.singletonList(new RingPage()));
private int currentPage = 0;
public LambdaRing()
{
}
public @NotNull RingPage getCurrentPage()
{
if (this.currentPage >= this.pages.size())
this.currentPage = this.pages.size() - 1;
else if (this.currentPage < 0)
this.currentPage = 0;
return this.pages.get(this.currentPage);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.ring;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull;
/**
* Represents a ring action.
*
* @author LambdAurora
* @version 1.4.0
* @since 1.4.0
*/
public abstract class RingAction implements Nameable
{
protected boolean activated = false;
/**
* Gets the translated name of the ring action.
*
* @return The translated name.
*/
public TranslatableText getTranslatedName()
{
return new TranslatableText(this.getName());
}
/**
* Returns whether the action is activated or not.
*
* @return True if the action is activated, else false.
*/
public boolean isActivated()
{
return this.activated;
}
public void activate(@NotNull RingButtonMode mode)
{
this.activated = !this.activated;
this.onAction(mode);
}
public abstract void onAction(@NotNull RingButtonMode mode);
}

View File

@@ -1,24 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.ring;
/**
* Represents a ring page.
*
* @author LambdAurora
* @version 1.4.0
* @since 1.4.0
*/
public class RingPage
{
private RingAction[] actions = new RingAction[8];
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.util;
/**
* Represents a Minecraft keybinding with extra access.
*/
public interface KeyBindingAccessor
{
boolean lambdacontrols_press();
boolean lambdacontrols_unpress();
default boolean lambdacontrols_handlePressState(boolean pressed)
{
if (pressed)
return this.lambdacontrols_press();
else
return this.lambdacontrols_unpress();
}
}

View File

@@ -1,18 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.client.util;
/**
* Represents mouse's extra access.
*/
public interface MouseAccessor
{
void lambdacontrols_onCursorPos(long window, double x, double y);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -1,13 +0,0 @@
{
"required": true,
"package": "me.lambdaurora.lambdacontrols.client.compat.mixin",
"plugin": "me.lambdaurora.lambdacontrols.client.compat.LambdaControlsMixinPlugin",
"compatibilityLevel": "JAVA_8",
"client": [
"RecipeViewingScreenAccessor",
"VillagerRecipeViewingScreenAccessor"
],
"injectors": {
"defaultRequire": 1
}
}

View File

@@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version=1.16.1 minecraft_version=1.16.5
yarn_mappings=1.16.1+build.21:v2 yarn_mappings=1.16.5+build.5
loader_version=0.9.0+build.204 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 1.4.1 mod_version = 1.6.0
maven_group = me.lambdaurora.lambdacontrols maven_group = dev.lambdaurora.lambdacontrols
archives_base_name = lambdacontrols archives_base_name = lambdacontrols
# Dependencies # Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.15.0+build.379-1.16.1 fabric_version=0.32.0+1.16
spruceui_version=1.5.9 spruceui_version=2.1.4-1.16
modmenu_version=1.12.2+build.17 modmenu_version=1.16.8

Binary file not shown.

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

21
gradlew.bat vendored
View File

@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -64,21 +64,6 @@ echo location of your Java installation.
goto fail goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
@@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @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% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@@ -1,6 +1,5 @@
pluginManagement { pluginManagement {
repositories { repositories {
jcenter()
maven { maven {
name = 'Fabric' name = 'Fabric'
url = 'https://maven.fabricmc.net/' url = 'https://maven.fabricmc.net/'
@@ -10,4 +9,3 @@ pluginManagement {
} }
rootProject.name = 'lambdacontrols' rootProject.name = 'lambdacontrols'
include 'core', 'fabric', 'spigot'

View File

@@ -1,50 +0,0 @@
plugins {
id 'java-library'
}
archivesBaseName = project.archives_base_name + "-spigot"
repositories {
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url = 'https://libraries.minecraft.net/' }
}
configurations {
include
}
dependencies {
api project(":core")
include(project(":core")) {
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'
}
api 'org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT'
api 'io.netty:netty-all:4.1.28.Final'
}
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "plugin.yml"
expand 'version': project.version.toString().replace("#", "")
}
}
jar {
from '../LICENSE'
dependsOn configurations.include
from {
(configurations.include).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols;
import com.electronwill.nightconfig.core.file.FileConfig;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* Represents the LambdaControls Spigot configuration.
*/
public class LambdaControlsConfig
{
private static final boolean DEFAULT_FRONT_BLOCK_PLACING = true;
protected final FileConfig config = FileConfig.builder("config/lambdacontrols.toml").concurrent().defaultResource("/server_config.toml").build();
private final LambdaControlsSpigot plugin;
public LambdaControlsConfig(@NotNull LambdaControlsSpigot plugin)
{
this.plugin = plugin;
}
public void load()
{
File configDir = new File("config/");
if (!configDir.exists())
configDir.mkdirs();
this.config.load();
this.plugin.log("Configuration loaded.");
LambdaControlsFeature.FRONT_BLOCK_PLACING.setAllowed(this.config.getOrElse("gameplay.front_block_placing", DEFAULT_FRONT_BLOCK_PLACING));
}
}

View File

@@ -1,148 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols;
import io.netty.buffer.Unpooled;
import me.lambdaurora.lambdacontrols.event.PlayerChangeControlsModeEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static me.lambdaurora.lambdacontrols.LambdaControlsConstants.*;
/**
* Represents the LambdaControls spigot plugin which provides extra features for servers.
*
* @author LambdAurora
* @version 1.1.0
* @since 1.1.0
*/
public class LambdaControlsSpigot extends JavaPlugin implements PluginMessageListener, Listener
{
private static final Map<Player, ControlsMode> PLAYERS_CONTROLS_MODE = new HashMap<>();
public final LambdaControlsConfig config = new LambdaControlsConfig(this);
@Override
public void onEnable()
{
super.onEnable();
this.config.load();
// Note that Spigot has a bullshit channel size restriction as Minecraft SUPPORTS UP TO 32767 AS CHANNEL SIZE.
// Please stop using that bad server software, move over Sponge or idk other things. REALLY.
this.getServer().getMessenger().registerIncomingPluginChannel(this, CONTROLS_MODE_CHANNEL.toString(), this);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CONTROLS_MODE_CHANNEL.toString());
this.getServer().getMessenger().registerOutgoingPluginChannel(this, FEATURE_CHANNEL.toString());
this.getServer().getMessenger().registerIncomingPluginChannel(this, HELLO_CHANNEL.toString(), this);
this.getServer().getPluginManager().registerEvents(this, this);
this.getServer().getOnlinePlayers().forEach(player -> {
PLAYERS_CONTROLS_MODE.put(player, ControlsMode.DEFAULT);
this.requestPlayerControlsMode(player);
this.updatePlayerFeature(player, LambdaControlsFeature.FRONT_BLOCK_PLACING);
});
}
@Override
public void onDisable()
{
super.onDisable();
this.getServer().getMessenger().unregisterIncomingPluginChannel(this, CONTROLS_MODE_CHANNEL.toString());
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this, CONTROLS_MODE_CHANNEL.toString());
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this, FEATURE_CHANNEL.toString());
this.getServer().getMessenger().unregisterIncomingPluginChannel(this, HELLO_CHANNEL.toString());
PLAYERS_CONTROLS_MODE.clear();
}
public void requestPlayerControlsMode(@NotNull Player player)
{
player.sendPluginMessage(this, CONTROLS_MODE_CHANNEL.toString(), new byte[0]);
}
public void updatePlayerFeature(@NotNull Player player, @NotNull LambdaControlsFeature feature)
{
Objects.requireNonNull(player);
Objects.requireNonNull(feature);
player.sendPluginMessage(this, FEATURE_CHANNEL.toString(), this.makeFeatureMessage(feature));
}
/**
* Prints a message to the terminal.
*
* @param info The message to print.
*/
public void log(String info)
{
this.getLogger().info(info);
}
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message)
{
if (channel.equals(HELLO_CHANNEL.toString())) {
NettyPacketBuffer buffer = new NettyPacketBuffer(Unpooled.copiedBuffer(message));
String version = buffer.readString(16);
ControlsMode.byId(buffer.readString(32)).ifPresent(controlsMode -> {
PLAYERS_CONTROLS_MODE.put(player, controlsMode);
PlayerChangeControlsModeEvent event = new PlayerChangeControlsModeEvent(player, controlsMode);
this.getServer().getPluginManager().callEvent(event);
});
this.updatePlayerFeature(player, LambdaControlsFeature.FRONT_BLOCK_PLACING);
} else if (channel.equals(CONTROLS_MODE_CHANNEL.toString())) {
NettyPacketBuffer buffer = new NettyPacketBuffer(Unpooled.copiedBuffer(message));
ControlsMode.byId(buffer.readString(32)).ifPresent(controlsMode -> {
PLAYERS_CONTROLS_MODE.put(player, controlsMode);
PlayerChangeControlsModeEvent event = new PlayerChangeControlsModeEvent(player, controlsMode);
this.getServer().getPluginManager().callEvent(event);
});
}
}
/**
* Returns a packet byte buffer made for the lambdacontrols:feature plugin message.
*
* @param feature The feature data to send.
* @return The packet byte buffer.
*/
public byte[] makeFeatureMessage(@NotNull LambdaControlsFeature feature)
{
Objects.requireNonNull(feature, "Feature cannot be null.");
NettyPacketBuffer buffer = new NettyPacketBuffer(Unpooled.buffer());
buffer.writeString(feature.getName());
buffer.writeBoolean(feature.isAllowed());
return buffer.array();
}
@EventHandler
public void onPlayerJoin(@NotNull PlayerJoinEvent event)
{
PLAYERS_CONTROLS_MODE.put(event.getPlayer(), ControlsMode.DEFAULT);
}
@EventHandler
public void onPlayerLeave(@NotNull PlayerQuitEvent event)
{
PLAYERS_CONTROLS_MODE.remove(event.getPlayer());
}
}

View File

@@ -1,102 +0,0 @@
package me.lambdaurora.lambdacontrols;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.EncoderException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class NettyPacketBuffer extends PacketBuffer
{
public NettyPacketBuffer(ByteBuf byteBuf)
{
super(byteBuf);
}
@Override
public int readVarint()
{
int var1 = 0;
int var2 = 0;
byte var3;
do {
var3 = this.readByte();
var1 |= (var3 & 127) << var2++ * 7;
if (var2 > 5)
throw new RuntimeException("VarInt too big");
} while ((var3 & 128) == 128);
return var1;
}
@Override
public void writeVarint(int input)
{
while ((input & -128) != 0) {
this.writeByte(input & 127 | 128);
input >>>= 7;
}
this.writeByte(input);
}
@Override
public String readString(int maxLength)
{
int var2 = this.readVarint();
if (var2 > maxLength * 4)
throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + var2 + " > " + maxLength * 4 + ")");
else if (var2 < 0)
throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!");
else {
String var3 = this.readCharSequence(var2, StandardCharsets.UTF_8).toString();
if (var3.length() > maxLength)
throw new DecoderException("The received string length is longer than maximum allowed (" + var2 + " > " + maxLength + ")");
else
return var3;
}
}
@Override
public void writeString(String string)
{
byte[] var2 = string.getBytes(Charset.forName("UTF-8"));
if (var2.length > 32767) {
throw new EncoderException("String too big (was " + string.length() + " data encoded, max " + 32767 + ")");
} else {
this.writeVarint(var2.length);
this.writeCharSequence(string, StandardCharsets.UTF_8);
}
}
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NettyPacketBuffer buffer = (NettyPacketBuffer) o;
return byteBuf.equals(buffer.byteBuf);
}
@Override
public int compareTo(ByteBuf buffer)
{
return this.byteBuf.compareTo(buffer);
}
@Override
public String toString()
{
return this.byteBuf.toString();
}
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package me.lambdaurora.lambdacontrols.event;
import me.lambdaurora.lambdacontrols.ControlsMode;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
/**
* Represents an event which is fired when a player change their controls mode.
*
* @author LambdAurora
* @version 1.1.0
* @since 1.1.0
*/
public class PlayerChangeControlsModeEvent extends PlayerEvent
{
private static final HandlerList HANDLERS = new HandlerList();
private final ControlsMode controlsMode;
public PlayerChangeControlsModeEvent(@NotNull Player who, @NotNull ControlsMode controlsMode)
{
super(who);
this.controlsMode = controlsMode;
}
/**
* Returns the controls mode of the player.
*
* @return The player's controls mode.
*/
public ControlsMode getControlsMode()
{
return this.controlsMode;
}
@Override
public String toString()
{
return "PlayerChangeControlsModeEvent{" +
"player=" + this.player +
", controls_mode=" + this.controlsMode +
'}';
}
@Override
public @NotNull HandlerList getHandlers()
{
return HANDLERS;
}
public static @NotNull HandlerList getHandlerList()
{
return HANDLERS;
}
}

View File

@@ -1,6 +0,0 @@
name: LambdaControls
version: ${version}
description: A quick Spigot plugin for LambdaControls which allow server admins to disable some features.
main: me.lambdaurora.lambdacontrols.LambdaControlsSpigot
api-version: 1.13

View File

@@ -1,6 +0,0 @@
# LambdaControls server configuration.
# Gameplay settings
[gameplay]
# Allows front block placing like in Bedrock Edition.
front_block_placing = true

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols; package dev.lambdaurora.lambdacontrols;
import org.aperlambda.lambdacommon.utils.Nameable; import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -22,8 +22,7 @@ import java.util.Optional;
* @version 1.1.0 * @version 1.1.0
* @since 1.0.0 * @since 1.0.0
*/ */
public enum ControlsMode implements Nameable public enum ControlsMode implements Nameable {
{
DEFAULT, DEFAULT,
CONTROLLER, CONTROLLER,
TOUCHSCREEN; TOUCHSCREEN;
@@ -33,8 +32,7 @@ public enum ControlsMode implements Nameable
* *
* @return The next available controls mode. * @return The next available controls mode.
*/ */
public ControlsMode next() public ControlsMode next() {
{
ControlsMode[] v = values(); ControlsMode[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -47,14 +45,12 @@ public enum ControlsMode implements Nameable
* @return The translated key of this controls mode. * @return The translated key of this controls mode.
* @since 1.1.0 * @since 1.1.0
*/ */
public String getTranslationKey() public String getTranslationKey() {
{
return "lambdacontrols.controls_mode." + this.getName(); return "lambdacontrols.controls_mode." + this.getName();
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -64,8 +60,7 @@ public enum ControlsMode implements Nameable
* @param id The identifier of the controls mode. * @param id The identifier of the controls mode.
* @return The controls mode if found, else empty. * @return The controls mode if found, else empty.
*/ */
public static Optional<ControlsMode> byId(@NotNull String id) public static Optional<ControlsMode> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,10 +7,10 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols; package dev.lambdaurora.lambdacontrols;
import dev.lambdaurora.lambdacontrols.event.PlayerChangeControlsModeCallback;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import me.lambdaurora.lambdacontrols.event.PlayerChangeControlsModeCallback;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@@ -29,11 +29,10 @@ import java.util.Optional;
* Represents the LambdaControls mod. * Represents the LambdaControls mod.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.0 * @version 1.6.0
* @since 1.0.0 * @since 1.0.0
*/ */
public class LambdaControls implements ModInitializer public class LambdaControls implements ModInitializer {
{
private static LambdaControls INSTANCE; private static LambdaControls INSTANCE;
public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(LambdaControlsConstants.CONTROLS_MODE_CHANNEL.toString()); public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(LambdaControlsConstants.CONTROLS_MODE_CHANNEL.toString());
public static final Identifier FEATURE_CHANNEL = new Identifier(LambdaControlsConstants.FEATURE_CHANNEL.toString()); public static final Identifier FEATURE_CHANNEL = new Identifier(LambdaControlsConstants.FEATURE_CHANNEL.toString());
@@ -44,19 +43,18 @@ public class LambdaControls implements ModInitializer
public final Logger logger = LogManager.getLogger("LambdaControls"); public final Logger logger = LogManager.getLogger("LambdaControls");
@Override @Override
public void onInitialize() public void onInitialize() {
{
INSTANCE = this; INSTANCE = this;
this.log("Initializing LambdaControls..."); this.log("Initializing LambdaControls...");
ServerSidePacketRegistry.INSTANCE.register(HELLO_CHANNEL, ServerSidePacketRegistry.INSTANCE.register(HELLO_CHANNEL,
(context, attachedData) -> { (context, attachedData) -> {
String version = attachedData.readString(16); String version = attachedData.readString(32);
ControlsMode.byId(attachedData.readString(32)) ControlsMode.byId(attachedData.readString(32))
.ifPresent(controlsMode -> context.getTaskQueue() .ifPresent(controlsMode -> context.getTaskQueue()
.execute(() -> PlayerChangeControlsModeCallback.EVENT.invoker().apply(context.getPlayer(), controlsMode))); .execute(() -> PlayerChangeControlsModeCallback.EVENT.invoker().apply(context.getPlayer(), controlsMode)));
context.getTaskQueue().execute(() -> context.getTaskQueue().execute(() ->
ServerSidePacketRegistry.INSTANCE.sendToPlayer(context.getPlayer(), FEATURE_CHANNEL, this.makeFeatureBuffer(LambdaControlsFeature.FRONT_BLOCK_PLACING))); ServerSidePacketRegistry.INSTANCE.sendToPlayer(context.getPlayer(), FEATURE_CHANNEL, this.makeFeatureBuffer(LambdaControlsFeature.HORIZONTAL_REACHAROUND)));
}); });
ServerSidePacketRegistry.INSTANCE.register(CONTROLS_MODE_CHANNEL, ServerSidePacketRegistry.INSTANCE.register(CONTROLS_MODE_CHANNEL,
(context, attachedData) -> ControlsMode.byId(attachedData.readString(32)) (context, attachedData) -> ControlsMode.byId(attachedData.readString(32))
@@ -69,8 +67,7 @@ public class LambdaControls implements ModInitializer
* *
* @param info The message to print. * @param info The message to print.
*/ */
public void log(String info) public void log(String info) {
{
this.logger.info("[LambdaControls] " + info); this.logger.info("[LambdaControls] " + info);
} }
@@ -79,8 +76,7 @@ public class LambdaControls implements ModInitializer
* *
* @param warning The warning to print. * @param warning The warning to print.
*/ */
public void warn(String warning) public void warn(String warning) {
{
this.logger.info("[LambdaControls] " + warning); this.logger.info("[LambdaControls] " + warning);
} }
@@ -90,8 +86,7 @@ public class LambdaControls implements ModInitializer
* @param controlsMode The controls mode to send. * @param controlsMode The controls mode to send.
* @return The packet byte buffer. * @return The packet byte buffer.
*/ */
public PacketByteBuf makeControlsModeBuffer(@NotNull ControlsMode controlsMode) public PacketByteBuf makeControlsModeBuffer(@NotNull ControlsMode controlsMode) {
{
Objects.requireNonNull(controlsMode, "Controls mode cannot be null."); Objects.requireNonNull(controlsMode, "Controls mode cannot be null.");
return new PacketByteBuf(Unpooled.buffer()).writeString(controlsMode.getName(), 32); return new PacketByteBuf(Unpooled.buffer()).writeString(controlsMode.getName(), 32);
} }
@@ -102,22 +97,20 @@ public class LambdaControls implements ModInitializer
* @param feature The feature data to send. * @param feature The feature data to send.
* @return The packet byte buffer. * @return The packet byte buffer.
*/ */
public PacketByteBuf makeFeatureBuffer(@NotNull LambdaControlsFeature feature) public PacketByteBuf makeFeatureBuffer(@NotNull LambdaControlsFeature feature) {
{
Objects.requireNonNull(feature, "Feature cannot be null."); Objects.requireNonNull(feature, "Feature cannot be null.");
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()).writeString(feature.getName(), 64); PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()).writeString(feature.getName(), 64);
buffer.writeBoolean(feature.isAllowed()); buffer.writeBoolean(feature.isAllowed());
return buffer; return buffer;
} }
public PacketByteBuf makeHello(@NotNull ControlsMode controlsMode) public PacketByteBuf makeHello(@NotNull ControlsMode controlsMode) {
{
String version = ""; String version = "";
Optional<ModContainer> container; Optional<ModContainer> container;
if ((container = FabricLoader.getInstance().getModContainer(LambdaControlsConstants.NAMESPACE)).isPresent()) { if ((container = FabricLoader.getInstance().getModContainer(LambdaControlsConstants.NAMESPACE)).isPresent()) {
version = container.get().getMetadata().getVersion().getFriendlyString(); version = container.get().getMetadata().getVersion().getFriendlyString();
} }
return new PacketByteBuf(Unpooled.buffer()).writeString(version, 16).writeString(controlsMode.getName(), 32); return new PacketByteBuf(Unpooled.buffer()).writeString(version, 32).writeString(controlsMode.getName(), 32);
} }
/** /**
@@ -125,8 +118,7 @@ public class LambdaControls implements ModInitializer
* *
* @return The LambdaControls instance. * @return The LambdaControls instance.
*/ */
public static LambdaControls get() public static LambdaControls get() {
{
return INSTANCE; return INSTANCE;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols; package dev.lambdaurora.lambdacontrols;
import org.aperlambda.lambdacommon.Identifier; import org.aperlambda.lambdacommon.Identifier;
@@ -18,8 +18,7 @@ import org.aperlambda.lambdacommon.Identifier;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsConstants public class LambdaControlsConstants {
{
public static final String NAMESPACE = "lambdacontrols"; public static final String NAMESPACE = "lambdacontrols";
public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(NAMESPACE, "controls_mode"); public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(NAMESPACE, "controls_mode");
public static final Identifier FEATURE_CHANNEL = new Identifier(NAMESPACE, "feature"); public static final Identifier FEATURE_CHANNEL = new Identifier(NAMESPACE, "feature");

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols; package dev.lambdaurora.lambdacontrols;
import org.aperlambda.lambdacommon.utils.Nameable; import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -21,14 +21,13 @@ import java.util.Optional;
* Represents a feature. * Represents a feature.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.2 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsFeature implements Nameable public class LambdaControlsFeature implements Nameable {
{
private static final List<LambdaControlsFeature> FEATURES = new ArrayList<>(); private static final List<LambdaControlsFeature> FEATURES = new ArrayList<>();
public static final LambdaControlsFeature FAST_BLOCK_PLACING = new LambdaControlsFeature("fast_block_placing", true, true); public static final LambdaControlsFeature FAST_BLOCK_PLACING = new LambdaControlsFeature("fast_block_placing", true, true);
public static final LambdaControlsFeature FRONT_BLOCK_PLACING = new LambdaControlsFeature("front_block_placing", true, false); public static final LambdaControlsFeature HORIZONTAL_REACHAROUND = new LambdaControlsFeature("horizontal_reacharound", true, false);
public static final LambdaControlsFeature VERTICAL_REACHAROUND = new LambdaControlsFeature("vertical_reacharound", true, false); public static final LambdaControlsFeature VERTICAL_REACHAROUND = new LambdaControlsFeature("vertical_reacharound", true, false);
private final String key; private final String key;
@@ -37,24 +36,21 @@ public class LambdaControlsFeature implements Nameable
private final boolean defaultEnabled; private final boolean defaultEnabled;
private boolean enabled; private boolean enabled;
public LambdaControlsFeature(@NotNull String key, boolean allowed, boolean enabled) public LambdaControlsFeature(@NotNull String key, boolean allowed, boolean enabled) {
{
Objects.requireNonNull(key, "Feature key cannot be null."); Objects.requireNonNull(key, "Feature key cannot be null.");
this.key = key; this.key = key;
this.setAllowed(this.defaultAllowed = allowed); this.setAllowed(this.defaultAllowed = allowed);
this.setEnabled(this.defaultEnabled = enabled); this.setEnabled(this.defaultEnabled = enabled);
} }
public LambdaControlsFeature(@NotNull String key) public LambdaControlsFeature(@NotNull String key) {
{
this(key, false, false); this(key, false, false);
} }
/** /**
* Allows the feature. * Allows the feature.
*/ */
public void allow() public void allow() {
{
this.setAllowed(true); this.setAllowed(true);
} }
@@ -63,8 +59,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @return True if this feature is allowed, else false. * @return True if this feature is allowed, else false.
*/ */
public boolean isAllowed() public boolean isAllowed() {
{
return this.allowed; return this.allowed;
} }
@@ -73,16 +68,14 @@ public class LambdaControlsFeature implements Nameable
* *
* @param allowed True if this feature is allowed, else false. * @param allowed True if this feature is allowed, else false.
*/ */
public void setAllowed(boolean allowed) public void setAllowed(boolean allowed) {
{
this.allowed = allowed; this.allowed = allowed;
} }
/** /**
* Resets allowed state to default. * Resets allowed state to default.
*/ */
public void resetAllowed() public void resetAllowed() {
{
this.setAllowed(this.defaultAllowed); this.setAllowed(this.defaultAllowed);
} }
@@ -91,8 +84,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @return True if this feature is enabled, else false. * @return True if this feature is enabled, else false.
*/ */
public boolean isEnabled() public boolean isEnabled() {
{
return this.enabled; return this.enabled;
} }
@@ -101,8 +93,7 @@ public class LambdaControlsFeature implements Nameable
* *
* @param enabled True if this feature is enabled, else false. * @param enabled True if this feature is enabled, else false.
*/ */
public void setEnabled(boolean enabled) public void setEnabled(boolean enabled) {
{
this.enabled = enabled; this.enabled = enabled;
} }
@@ -113,28 +104,24 @@ public class LambdaControlsFeature implements Nameable
* @see #isAllowed() * @see #isAllowed()
* @see #isEnabled() * @see #isEnabled()
*/ */
public boolean isAvailable() public boolean isAvailable() {
{
return this.isAllowed() && this.isEnabled(); return this.isAllowed() && this.isEnabled();
} }
/** /**
* Resets the feature to its default values. * Resets the feature to its default values.
*/ */
public void reset() public void reset() {
{
this.resetAllowed(); this.resetAllowed();
this.setEnabled(this.defaultEnabled); this.setEnabled(this.defaultEnabled);
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.key; return this.key;
} }
public static @NotNull Optional<LambdaControlsFeature> fromName(@NotNull String key) public static @NotNull Optional<LambdaControlsFeature> fromName(@NotNull String key) {
{
Objects.requireNonNull(key, "Cannot find features with a null name."); Objects.requireNonNull(key, "Cannot find features with a null name.");
return FEATURES.parallelStream().filter(feature -> feature.getName().equals(key)).findFirst(); return FEATURES.parallelStream().filter(feature -> feature.getName().equals(key)).findFirst();
} }
@@ -142,22 +129,20 @@ public class LambdaControlsFeature implements Nameable
/** /**
* Resets all features to their default values. * Resets all features to their default values.
*/ */
public static void resetAll() public static void resetAll() {
{
FEATURES.parallelStream().forEach(LambdaControlsFeature::reset); FEATURES.parallelStream().forEach(LambdaControlsFeature::reset);
} }
/** /**
* Resets all features to allow state. * Resets all features to allow state.
*/ */
public static void resetAllAllowed() public static void resetAllAllowed() {
{
FEATURES.parallelStream().forEach(LambdaControlsFeature::resetAllowed); FEATURES.parallelStream().forEach(LambdaControlsFeature::resetAllowed);
} }
static { static {
FEATURES.add(FAST_BLOCK_PLACING); FEATURES.add(FAST_BLOCK_PLACING);
FEATURES.add(FRONT_BLOCK_PLACING); FEATURES.add(HORIZONTAL_REACHAROUND);
FEATURES.add(VERTICAL_REACHAROUND); FEATURES.add(VERTICAL_REACHAROUND);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
/** /**
* Represents a button state. * Represents a button state.
@@ -16,8 +16,7 @@ package me.lambdaurora.lambdacontrols.client;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public enum ButtonState public enum ButtonState {
{
NONE(0), NONE(0),
PRESS(1), PRESS(1),
RELEASE(2), RELEASE(2),
@@ -25,8 +24,7 @@ public enum ButtonState
public final int id; public final int id;
ButtonState(int id) ButtonState(int id) {
{
this.id = id; this.id = id;
} }
@@ -35,8 +33,7 @@ public enum ButtonState
* *
* @return True if this state is a pressed state, else false. * @return True if this state is a pressed state, else false.
*/ */
public boolean isPressed() public boolean isPressed() {
{
return this == PRESS || this == REPEAT; return this == PRESS || this == REPEAT;
} }
@@ -45,8 +42,7 @@ public enum ButtonState
* *
* @return True if this state is an unpressed state, else false. * @return True if this state is an unpressed state, else false.
*/ */
public boolean isUnpressed() public boolean isUnpressed() {
{
return this == RELEASE || this == NONE; return this == RELEASE || this == NONE;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,8 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable; import org.aperlambda.lambdacommon.utils.Nameable;
@@ -21,25 +22,29 @@ import java.util.Optional;
* Represents a controller type. * Represents a controller type.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.4.3
* @since 1.0.0 * @since 1.0.0
*/ */
public enum ControllerType implements Nameable public enum ControllerType implements Nameable {
{
DEFAULT(0), DEFAULT(0),
DUALSHOCK(1), DUALSHOCK(1),
SWITCH(2), SWITCH(2),
XBOX(3), XBOX_360(3, new LiteralText("Xbox 360")),
STEAM(4), XBOX(4),
OUYA(5); STEAM(5),
OUYA(6);
private final int id; private final int id;
private final Text text; private final Text text;
ControllerType(int id) ControllerType(int id) {
{
this.id = id; this.id = id;
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText("lambdacontrols.controller_type." + this.getName());
}
ControllerType(int id, @NotNull Text text) {
this.id = id;
this.text = text;
} }
/** /**
@@ -47,8 +52,7 @@ public enum ControllerType implements Nameable
* *
* @return The controller type's identifier. * @return The controller type's identifier.
*/ */
public int getId() public int getId() {
{
return this.id; return this.id;
} }
@@ -57,37 +61,24 @@ public enum ControllerType implements Nameable
* *
* @return The next available controller type. * @return The next available controller type.
*/ */
public @NotNull ControllerType next() public @NotNull ControllerType next() {
{
ControllerType[] v = values(); ControllerType[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
return v[this.ordinal() + 1]; return v[this.ordinal() + 1];
} }
/**
* Returns the translation key of this controller type.
*
* @return The translation key.
*/
public @NotNull String getTranslationKey()
{
return "lambdacontrols.controller_type." + this.getName();
}
/** /**
* Gets the translated text of this controller type. * Gets the translated text of this controller type.
* *
* @return The translated text of this controller type. * @return The translated text of this controller type.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -97,8 +88,7 @@ public enum ControllerType implements Nameable
* @param id The identifier of the controller type. * @param id The identifier of the controller type.
* @return The controller type if found, else empty. * @return The controller type if found, else empty.
*/ */
public static @NotNull Optional<ControllerType> byId(@NotNull String id) public static @NotNull Optional<ControllerType> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,9 +7,8 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable; import org.aperlambda.lambdacommon.utils.Nameable;
@@ -25,15 +24,13 @@ import java.util.Optional;
* @version 1.4.0 * @version 1.4.0
* @since 1.0.0 * @since 1.0.0
*/ */
public enum HudSide implements Nameable public enum HudSide implements Nameable {
{
LEFT, LEFT,
RIGHT; RIGHT;
private final Text text; private final Text text;
HudSide() HudSide() {
{
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText(this.getTranslationKey());
} }
@@ -42,8 +39,7 @@ public enum HudSide implements Nameable
* *
* @return The next available side. * @return The next available side.
*/ */
public @NotNull HudSide next() public @NotNull HudSide next() {
{
HudSide[] v = values(); HudSide[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -55,8 +51,7 @@ public enum HudSide implements Nameable
* *
* @return The translation key of this hude side. * @return The translation key of this hude side.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.hud_side." + this.getName(); return "lambdacontrols.hud_side." + this.getName();
} }
@@ -65,14 +60,12 @@ public enum HudSide implements Nameable
* *
* @return The translated text of this hud side. * @return The translated text of this hud side.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
@@ -82,8 +75,7 @@ public enum HudSide implements Nameable
* @param id The identifier of the hud side. * @param id The identifier of the hud side.
* @return The hud side if found, else empty. * @return The hud side if found, else empty.
*/ */
public static @NotNull Optional<HudSide> byId(@NotNull String id) public static @NotNull Optional<HudSide> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,25 +7,29 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControls; import dev.lambdaurora.lambdacontrols.LambdaControls;
import me.lambdaurora.lambdacontrols.LambdaControlsConstants; import dev.lambdaurora.lambdacontrols.LambdaControlsConstants;
import me.lambdaurora.lambdacontrols.LambdaControlsFeature; import dev.lambdaurora.lambdacontrols.LambdaControlsFeature;
import me.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.Controller; import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.lambdacontrols.client.controller.InputManager; import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsHud; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsHud;
import me.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay; import dev.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay;
import dev.lambdaurora.lambdacontrols.client.ring.KeyBindingRingAction;
import dev.lambdaurora.lambdacontrols.client.ring.LambdaRing;
import me.lambdaurora.spruceui.event.OpenScreenCallback; import me.lambdaurora.spruceui.event.OpenScreenCallback;
import me.lambdaurora.spruceui.hud.HudManager; import me.lambdaurora.spruceui.hud.HudManager;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@@ -35,15 +39,16 @@ import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.io.File;
/** /**
* Represents the LambdaControls client mod. * Represents the LambdaControls client mod.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.2 * @version 1.6.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsClient extends LambdaControls implements ClientModInitializer public class LambdaControlsClient extends LambdaControls implements ClientModInitializer {
{
private static LambdaControlsClient INSTANCE; private static LambdaControlsClient INSTANCE;
public static final KeyBinding BINDING_LOOK_UP = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_up"), public static final KeyBinding BINDING_LOOK_UP = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_up"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_8, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_8, "key.categories.movement");
@@ -53,31 +58,43 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_2, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_2, "key.categories.movement");
public static final KeyBinding BINDING_LOOK_LEFT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_left"), public static final KeyBinding BINDING_LOOK_LEFT = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "look_left"),
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_4, "key.categories.movement"); InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_4, "key.categories.movement");
/*public static final KeyBinding BINDING_RING = InputManager.makeKeyBinding(new Identifier(LambdaControlsConstants.NAMESPACE, "ring"),
InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_5, "key.categories.misc");*/
public static final Identifier CONTROLLER_BUTTONS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_buttons.png"); public static final Identifier CONTROLLER_BUTTONS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_buttons.png");
public static final Identifier CONTROLLER_AXIS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_axis.png"); public static final Identifier CONTROLLER_AXIS = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/controller_axis.png");
public static final Identifier CURSOR_TEXTURE = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/cursor.png"); public static final Identifier CURSOR_TEXTURE = new Identifier(LambdaControlsConstants.NAMESPACE, "textures/gui/cursor.png");
public final static File MAPPINGS_FILE = new File("config/gamecontrollerdb.txt");
public final LambdaControlsConfig config = new LambdaControlsConfig(this); public final LambdaControlsConfig config = new LambdaControlsConfig(this);
public final LambdaInput input = new LambdaInput(this); public final LambdaInput input = new LambdaInput(this);
public final LambdaRing ring = new LambdaRing(this);
public final LambdaReacharound reacharound = new LambdaReacharound(); public final LambdaReacharound reacharound = new LambdaReacharound();
private LambdaControlsHud hud; private LambdaControlsHud hud;
private ControlsMode previousControlsMode; private ControlsMode previousControlsMode;
@Override @Override
public void onInitializeClient() public void onInitializeClient() {
{
INSTANCE = this; INSTANCE = this;
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_UP); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_UP);
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_RIGHT); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_RIGHT);
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_DOWN); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_DOWN);
KeyBindingHelper.registerKeyBinding(BINDING_LOOK_LEFT); KeyBindingHelper.registerKeyBinding(BINDING_LOOK_LEFT);
//KeyBindingHelper.registerKeyBinding(BINDING_RING);
ClientSidePacketRegistry.INSTANCE.register(CONTROLS_MODE_CHANNEL, (context, attachedData) -> context.getTaskQueue() this.ring.registerAction("keybinding", KeyBindingRingAction.FACTORY);
.execute(() -> ClientSidePacketRegistry.INSTANCE.sendToServer(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode()))));
ClientSidePacketRegistry.INSTANCE.register(FEATURE_CHANNEL, (context, attachedData) -> { ClientPlayNetworking.registerGlobalReceiver(CONTROLS_MODE_CHANNEL, (client, handler, buf, responseSender) -> {
String name = attachedData.readString(64); responseSender.sendPacket(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode()));
boolean allowed = attachedData.readBoolean();
LambdaControlsFeature.fromName(name).ifPresent(feature -> context.getTaskQueue().execute(() -> feature.setAllowed(allowed)));
}); });
ClientPlayNetworking.registerGlobalReceiver(FEATURE_CHANNEL, (client, handler, buf, responseSender) -> {
String name = buf.readString(64);
boolean allowed = buf.readBoolean();
LambdaControlsFeature.fromName(name).ifPresent(feature -> client.execute(() -> feature.setAllowed(allowed)));
});
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
sender.sendPacket(HELLO_CHANNEL, this.makeHello(this.config.getControlsMode()));
sender.sendPacket(CONTROLS_MODE_CHANNEL, this.makeControlsModeBuffer(this.config.getControlsMode()));
});
ClientPlayConnectionEvents.DISCONNECT.register(this::onLeave);
ClientTickEvents.START_CLIENT_TICK.register(this.reacharound::tick); ClientTickEvents.START_CLIENT_TICK.register(this.reacharound::tick);
ClientTickEvents.END_CLIENT_TICK.register(this::onTick); ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
@@ -99,8 +116,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
/** /**
* This method is called when Minecraft is initializing. * This method is called when Minecraft is initializing.
*/ */
public void onMcInit(@NotNull MinecraftClient client) public void onMcInit(@NotNull MinecraftClient client) {
{
ButtonBinding.init(client.options); ButtonBinding.init(client.options);
this.config.load(); this.config.load();
this.hud.setVisible(this.config.isHudEnabled()); this.hud.setVisible(this.config.isHudEnabled());
@@ -124,33 +140,33 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
/** /**
* This method is called every Minecraft tick. * This method is called every Minecraft tick.
* *
* @param client The client instance. * @param client the client instance
*/ */
public void onTick(@NotNull MinecraftClient client) public void onTick(@NotNull MinecraftClient client) {
{ this.input.tick(client);
this.input.onTick(client);
if (this.config.getControlsMode() == ControlsMode.CONTROLLER && (client.isWindowFocused() || this.config.hasUnfocusedInput())) if (this.config.getControlsMode() == ControlsMode.CONTROLLER && (client.isWindowFocused() || this.config.hasUnfocusedInput()))
this.input.onControllerTick(client); this.input.tickController(client);
/*if (BINDING_RING.wasPressed()) {
client.openScreen(new RingScreen());
}*/
} }
public void onRender(MinecraftClient client) public void onRender(MinecraftClient client) {
{
this.input.onRender(client.getTickDelta(), client); this.input.onRender(client.getTickDelta(), client);
} }
/** /**
* Called when leaving a server. * Called when leaving a server.
*/ */
public void onLeave() public void onLeave(ClientPlayNetworkHandler handler, MinecraftClient client) {
{
LambdaControlsFeature.resetAllAllowed(); LambdaControlsFeature.resetAllAllowed();
} }
/** /**
* Switches the controls mode if the auto switch is enabled. * Switches the controls mode if the auto switch is enabled.
*/ */
public void switchControlsMode() public void switchControlsMode() {
{
if (this.config.hasAutoSwitchMode()) { if (this.config.hasAutoSwitchMode()) {
if (this.config.getController().isGamepad()) { if (this.config.getController().isGamepad()) {
this.previousControlsMode = this.config.getControlsMode(); this.previousControlsMode = this.config.getControlsMode();
@@ -170,8 +186,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
* *
* @param enabled True if the HUD is enabled, else false. * @param enabled True if the HUD is enabled, else false.
*/ */
public void setHudEnabled(boolean enabled) public void setHudEnabled(boolean enabled) {
{
this.config.setHudEnabled(enabled); this.config.setHudEnabled(enabled);
this.hud.setVisible(enabled); this.hud.setVisible(enabled);
} }
@@ -181,8 +196,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
* *
* @return The LambdaControls client instance. * @return The LambdaControls client instance.
*/ */
public static LambdaControlsClient get() public static LambdaControlsClient get() {
{
return INSTANCE; return INSTANCE;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,14 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import com.electronwill.nightconfig.core.file.FileConfig; import com.electronwill.nightconfig.core.file.FileConfig;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControlsFeature; import dev.lambdaurora.lambdacontrols.LambdaControlsFeature;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.Controller; import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.lambdacontrols.client.controller.InputManager; import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@@ -31,25 +31,27 @@ import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y;
/** /**
* Represents LambdaControls configuration. * Represents LambdaControls configuration.
*/ */
public class LambdaControlsConfig public class LambdaControlsConfig {
{
// General // General
private static final ControlsMode DEFAULT_CONTROLS_MODE = ControlsMode.DEFAULT; private static final ControlsMode DEFAULT_CONTROLS_MODE = ControlsMode.DEFAULT;
private static final boolean DEFAULT_AUTO_SWITCH_MODE = false; private static final boolean DEFAULT_AUTO_SWITCH_MODE = false;
private static final boolean DEFAULT_DEBUG = false;
// HUD // HUD
private static final boolean DEFAULT_HUD_ENABLE = true; private static final boolean DEFAULT_HUD_ENABLE = true;
private static final HudSide DEFAULT_HUD_SIDE = HudSide.LEFT; private static final HudSide DEFAULT_HUD_SIDE = HudSide.LEFT;
// Gameplay // Gameplay
private static final boolean DEFAULT_ANALOG_MOVEMENT = true;
private static final boolean DEFAULT_FAST_BLOCK_INTERACTION = true; private static final boolean DEFAULT_FAST_BLOCK_INTERACTION = true;
private static final boolean DEFAULT_FLY_DRIFTING = false; private static final boolean DEFAULT_FLY_DRIFTING = false;
private static final boolean DEFAULT_FLY_VERTICAL_DRIFTING = true; private static final boolean DEFAULT_FLY_VERTICAL_DRIFTING = true;
private static final boolean DEFAULT_FRONT_BLOCK_PLACING = false; private static final boolean DEFAULT_HORIZONTAL_REACHAROUND = false;
private static final boolean DEFAULT_VERTICAL_REACHAROUND = false; private static final boolean DEFAULT_VERTICAL_REACHAROUND = false;
private static final boolean DEFAULT_REACHAROUND_OUTLINE = true; private static final boolean DEFAULT_REACHAROUND_OUTLINE = true;
private static final int[] DEFAULT_REACHAROUND_OUTLINE_COLOR = new int[]{255, 255, 255, 102}; private static final int[] DEFAULT_REACHAROUND_OUTLINE_COLOR = new int[]{255, 255, 255, 102};
// Controller // Controller
private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT; private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT;
private static final double DEFAULT_DEAD_ZONE = 0.25; private static final double DEFAULT_DEAD_ZONE = 0.25;
private static final double DEFAULT_MAX_VALUE = 1;
private static final double DEFAULT_ROTATION_SPEED = 40.0; private static final double DEFAULT_ROTATION_SPEED = 40.0;
private static final double DEFAULT_MOUSE_SPEED = 25.0; private static final double DEFAULT_MOUSE_SPEED = 25.0;
private static final boolean DEFAULT_UNFOCUSED_INPUT = false; private static final boolean DEFAULT_UNFOCUSED_INPUT = false;
@@ -63,10 +65,13 @@ public class LambdaControlsConfig
private ControlsMode controlsMode; private ControlsMode controlsMode;
private ControllerType controllerType; private ControllerType controllerType;
// Gameplay. // Gameplay.
private boolean analogMovement;
private boolean shouldRenderReacharoundOutline; private boolean shouldRenderReacharoundOutline;
private int[] reacharoundOutlineColor; private int[] reacharoundOutlineColor;
// Controller settings // Controller settings
private double deadZone; private double rightDeadZone;
private double leftDeadZone;
private double[] maxAnalogValues = new double[]{DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE};
private double rotationSpeed; private double rotationSpeed;
private double mouseSpeed; private double mouseSpeed;
private boolean unfocusedInput; private boolean unfocusedInput;
@@ -76,16 +81,14 @@ public class LambdaControlsConfig
private boolean hudEnable; private boolean hudEnable;
private HudSide hudSide; private HudSide hudSide;
public LambdaControlsConfig(@NotNull LambdaControlsClient mod) public LambdaControlsConfig(@NotNull LambdaControlsClient mod) {
{
this.mod = mod; this.mod = mod;
} }
/** /**
* Loads the configuration * Loads the configuration
*/ */
public void load() public void load() {
{
this.config.load(); this.config.load();
this.checkAndFix(); this.checkAndFix();
this.mod.log("Configuration loaded."); this.mod.log("Configuration loaded.");
@@ -94,39 +97,52 @@ public class LambdaControlsConfig
this.hudEnable = this.config.getOrElse("hud.enable", DEFAULT_HUD_ENABLE); this.hudEnable = this.config.getOrElse("hud.enable", DEFAULT_HUD_ENABLE);
this.hudSide = HudSide.byId(this.config.getOrElse("hud.side", DEFAULT_HUD_SIDE.getName())).orElse(DEFAULT_HUD_SIDE); this.hudSide = HudSide.byId(this.config.getOrElse("hud.side", DEFAULT_HUD_SIDE.getName())).orElse(DEFAULT_HUD_SIDE);
// Gameplay // Gameplay
this.analogMovement = this.config.getOrElse("gameplay.analog_movement", DEFAULT_ANALOG_MOVEMENT);
LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.fast_block_placing", DEFAULT_FAST_BLOCK_INTERACTION)); LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.fast_block_placing", DEFAULT_FAST_BLOCK_INTERACTION));
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(this.config.getOrElse("gameplay.reacharound.horizontal", DEFAULT_FRONT_BLOCK_PLACING)); LambdaControlsFeature.HORIZONTAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.horizontal", DEFAULT_HORIZONTAL_REACHAROUND));
LambdaControlsFeature.VERTICAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.vertical", DEFAULT_VERTICAL_REACHAROUND)); LambdaControlsFeature.VERTICAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.vertical", DEFAULT_VERTICAL_REACHAROUND));
this.shouldRenderReacharoundOutline = this.config.getOrElse("gameplay.reacharound.outline", DEFAULT_REACHAROUND_OUTLINE); this.shouldRenderReacharoundOutline = this.config.getOrElse("gameplay.reacharound.outline", DEFAULT_REACHAROUND_OUTLINE);
this.reacharoundOutlineColor = this.config.getOptional("gameplay.reacharound.outline_color").map(hex -> parseColor((String) hex)).orElse(DEFAULT_REACHAROUND_OUTLINE_COLOR); this.reacharoundOutlineColor = this.config.getOptional("gameplay.reacharound.outline_color")
.map(hex -> parseColor((String) hex))
.orElse(DEFAULT_REACHAROUND_OUTLINE_COLOR);
// Controller settings. // Controller settings.
this.controllerType = ControllerType.byId(this.config.getOrElse("controller.type", DEFAULT_CONTROLLER_TYPE.getName())).orElse(DEFAULT_CONTROLLER_TYPE); this.controllerType = ControllerType.byId(this.config.getOrElse("controller.type", DEFAULT_CONTROLLER_TYPE.getName())).orElse(DEFAULT_CONTROLLER_TYPE);
this.deadZone = this.config.getOrElse("controller.dead_zone", DEFAULT_DEAD_ZONE); this.rightDeadZone = this.config.getOrElse("controller.right_dead_zone", DEFAULT_DEAD_ZONE);
this.leftDeadZone = this.config.getOrElse("controller.left_dead_zone", DEFAULT_DEAD_ZONE);
this.rotationSpeed = this.config.getOrElse("controller.rotation_speed", DEFAULT_ROTATION_SPEED); this.rotationSpeed = this.config.getOrElse("controller.rotation_speed", DEFAULT_ROTATION_SPEED);
this.mouseSpeed = this.config.getOrElse("controller.mouse_speed", DEFAULT_MOUSE_SPEED); this.mouseSpeed = this.config.getOrElse("controller.mouse_speed", DEFAULT_MOUSE_SPEED);
this.unfocusedInput = this.config.getOrElse("controller.unfocused_input", DEFAULT_UNFOCUSED_INPUT); this.unfocusedInput = this.config.getOrElse("controller.unfocused_input", DEFAULT_UNFOCUSED_INPUT);
this.virtualMouse = this.config.getOrElse("controller.virtual_mouse", DEFAULT_VIRTUAL_MOUSE); this.virtualMouse = this.config.getOrElse("controller.virtual_mouse", DEFAULT_VIRTUAL_MOUSE);
this.virtualMouseSkin = VirtualMouseSkin.byId(this.config.getOrElse("controller.virtual_mouse_skin", DEFAULT_VIRTUAL_MOUSE_SKIN.getName())).orElse(DEFAULT_VIRTUAL_MOUSE_SKIN); this.virtualMouseSkin = VirtualMouseSkin.byId(this.config.getOrElse("controller.virtual_mouse_skin", DEFAULT_VIRTUAL_MOUSE_SKIN.getName())).orElse(DEFAULT_VIRTUAL_MOUSE_SKIN);
for (int i = 0; i < this.maxAnalogValues.length; i++) {
this.maxAnalogValues[i] = this.config.getOrElse("controller.max_value_" + i, DEFAULT_MAX_VALUE);
}
// Controller controls. // Controller controls.
InputManager.loadButtonBindings(this); InputManager.loadButtonBindings(this);
this.mod.ring.load(this.config);
} }
/** /**
* Saves the configuration. * Saves the configuration.
*/ */
public void save() public void save() {
{ this.config.set("controller.right_dead_zone", this.rightDeadZone);
this.config.set("controller.dead_zone", this.deadZone); this.config.set("controller.left_dead_zone", this.leftDeadZone);
this.config.set("controller.rotation_speed", this.rotationSpeed); this.config.set("controller.rotation_speed", this.rotationSpeed);
this.config.set("controller.mouse_speed", this.mouseSpeed); this.config.set("controller.mouse_speed", this.mouseSpeed);
this.config.set("controller.unfocused_input", this.unfocusedInput); this.config.set("controller.unfocused_input", this.unfocusedInput);
this.config.set("controller.virtual_mouse", this.virtualMouse); this.config.set("controller.virtual_mouse", this.virtualMouse);
for (int i = 0; i < this.maxAnalogValues.length; i++) {
this.config.set("controller.max_value_" + i, this.maxAnalogValues[i]);
}
this.config.save(); this.config.save();
this.mod.log("Configuration saved."); this.mod.log("Configuration saved.");
} }
public void checkAndFix() public void checkAndFix() {
{
InputManager.streamBindings().forEach(binding -> { InputManager.streamBindings().forEach(binding -> {
String path = "controller.controls." + binding.getName(); String path = "controller.controls." + binding.getName();
Object raw = this.config.getRaw(path); Object raw = this.config.getRaw(path);
@@ -137,7 +153,7 @@ public class LambdaControlsConfig
}); });
if (this.config.contains("gameplay.front_block_placing.enabled")) { if (this.config.contains("gameplay.front_block_placing.enabled")) {
this.setFrontBlockPlacing(this.config.getOrElse("gameplay.front_block_placing.enabled", DEFAULT_FRONT_BLOCK_PLACING)); this.setFrontBlockPlacing(this.config.getOrElse("gameplay.front_block_placing.enabled", DEFAULT_HORIZONTAL_REACHAROUND));
this.config.remove("gameplay.front_block_placing.enabled"); this.config.remove("gameplay.front_block_placing.enabled");
} }
@@ -151,12 +167,12 @@ public class LambdaControlsConfig
this.config.remove("gameplay.front_block_placing.outline_color"); this.config.remove("gameplay.front_block_placing.outline_color");
} }
this.renamed("controller.dead_zone", "controller.right_dead_zone");
this.renamed("controller.controls.tab_left", "controller.controls.tab_back"); this.renamed("controller.controls.tab_left", "controller.controls.tab_back");
this.renamed("controller.controls.tab_right", "controller.controls.tab_next"); this.renamed("controller.controls.tab_right", "controller.controls.tab_next");
} }
private void renamed(String oldPath, String newPath) private void renamed(String oldPath, String newPath) {
{
if (!this.config.contains(oldPath)) if (!this.config.contains(oldPath))
return; return;
Object raw = this.config.getRaw(oldPath); Object raw = this.config.getRaw(oldPath);
@@ -167,26 +183,30 @@ public class LambdaControlsConfig
/** /**
* Resets the configuration to default values. * Resets the configuration to default values.
*/ */
public void reset() public void reset() {
{
// General // General
this.setControlsMode(DEFAULT_CONTROLS_MODE); this.setControlsMode(DEFAULT_CONTROLS_MODE);
this.setAutoSwitchMode(DEFAULT_AUTO_SWITCH_MODE); this.setAutoSwitchMode(DEFAULT_AUTO_SWITCH_MODE);
this.setDebug(DEFAULT_DEBUG);
// Gameplay // Gameplay
this.setAnalogMovement(DEFAULT_ANALOG_MOVEMENT);
this.setFastBlockPlacing(DEFAULT_FAST_BLOCK_INTERACTION); this.setFastBlockPlacing(DEFAULT_FAST_BLOCK_INTERACTION);
this.setFlyDrifting(DEFAULT_FLY_DRIFTING); this.setFlyDrifting(DEFAULT_FLY_DRIFTING);
this.setFlyVerticalDrifting(DEFAULT_FLY_VERTICAL_DRIFTING); this.setFlyVerticalDrifting(DEFAULT_FLY_VERTICAL_DRIFTING);
this.setFrontBlockPlacing(DEFAULT_FRONT_BLOCK_PLACING); this.setFrontBlockPlacing(DEFAULT_HORIZONTAL_REACHAROUND);
this.setVerticalReacharound(DEFAULT_VERTICAL_REACHAROUND); this.setVerticalReacharound(DEFAULT_VERTICAL_REACHAROUND);
this.setRenderReacharoundOutline(DEFAULT_REACHAROUND_OUTLINE); this.setRenderReacharoundOutline(DEFAULT_REACHAROUND_OUTLINE);
// Controller // Controller
this.setControllerType(DEFAULT_CONTROLLER_TYPE); this.setControllerType(DEFAULT_CONTROLLER_TYPE);
this.setDeadZone(DEFAULT_DEAD_ZONE); this.setRightDeadZone(DEFAULT_DEAD_ZONE);
this.setLeftDeadZone(DEFAULT_DEAD_ZONE);
this.setRotationSpeed(DEFAULT_ROTATION_SPEED); this.setRotationSpeed(DEFAULT_ROTATION_SPEED);
this.setMouseSpeed(DEFAULT_MOUSE_SPEED); this.setMouseSpeed(DEFAULT_MOUSE_SPEED);
this.setUnfocusedInput(DEFAULT_UNFOCUSED_INPUT); this.setUnfocusedInput(DEFAULT_UNFOCUSED_INPUT);
this.setVirtualMouse(DEFAULT_VIRTUAL_MOUSE); this.setVirtualMouse(DEFAULT_VIRTUAL_MOUSE);
this.setVirtualMouseSkin(DEFAULT_VIRTUAL_MOUSE_SKIN); this.setVirtualMouseSkin(DEFAULT_VIRTUAL_MOUSE_SKIN);
Arrays.fill(this.maxAnalogValues, DEFAULT_MAX_VALUE);
// HUD // HUD
this.setHudEnabled(DEFAULT_HUD_ENABLE); this.setHudEnabled(DEFAULT_HUD_ENABLE);
this.setHudSide(DEFAULT_HUD_SIDE); this.setHudSide(DEFAULT_HUD_SIDE);
@@ -200,8 +220,7 @@ public class LambdaControlsConfig
* *
* @return The controls mode. * @return The controls mode.
*/ */
public @NotNull ControlsMode getControlsMode() public @NotNull ControlsMode getControlsMode() {
{
return this.controlsMode; return this.controlsMode;
} }
@@ -210,8 +229,7 @@ public class LambdaControlsConfig
* *
* @param controlsMode The controls mode. * @param controlsMode The controls mode.
*/ */
public void setControlsMode(@NotNull ControlsMode controlsMode) public void setControlsMode(@NotNull ControlsMode controlsMode) {
{
this.controlsMode = controlsMode; this.controlsMode = controlsMode;
this.config.set("controls", controlsMode.getName()); this.config.set("controls", controlsMode.getName());
} }
@@ -221,8 +239,7 @@ public class LambdaControlsConfig
* *
* @return True if the auto switch mode is enabled, else false. * @return True if the auto switch mode is enabled, else false.
*/ */
public boolean hasAutoSwitchMode() public boolean hasAutoSwitchMode() {
{
return this.config.getOrElse("auto_switch_mode", DEFAULT_AUTO_SWITCH_MODE); return this.config.getOrElse("auto_switch_mode", DEFAULT_AUTO_SWITCH_MODE);
} }
@@ -231,11 +248,28 @@ public class LambdaControlsConfig
* *
* @param autoSwitchMode True if the auto switch mode is enabled, else false. * @param autoSwitchMode True if the auto switch mode is enabled, else false.
*/ */
public void setAutoSwitchMode(boolean autoSwitchMode) public void setAutoSwitchMode(boolean autoSwitchMode) {
{
this.config.set("auto_switch_mode", autoSwitchMode); this.config.set("auto_switch_mode", autoSwitchMode);
} }
/**
* Returns whether the mod has debug enabled or not.
*
* @return True if debug is enabled, else false.
*/
public boolean hasDebug() {
return this.config.getOrElse("debug", DEFAULT_DEBUG);
}
/**
* Sets whether the mod has debug enabled or not.
*
* @param debug True if debug is enabled, else false.
*/
protected void setDebug(boolean debug) {
this.config.set("debug", debug);
}
/* /*
HUD settings HUD settings
*/ */
@@ -245,8 +279,7 @@ public class LambdaControlsConfig
* *
* @return True if the HUD is enabled, else false. * @return True if the HUD is enabled, else false.
*/ */
public boolean isHudEnabled() public boolean isHudEnabled() {
{
return this.hudEnable; return this.hudEnable;
} }
@@ -255,8 +288,7 @@ public class LambdaControlsConfig
* *
* @param enable True if the HUD is enabled, else false. * @param enable True if the HUD is enabled, else false.
*/ */
public void setHudEnabled(boolean enable) public void setHudEnabled(boolean enable) {
{
this.hudEnable = enable; this.hudEnable = enable;
this.config.set("hud.enable", this.hudEnable); this.config.set("hud.enable", this.hudEnable);
} }
@@ -266,8 +298,7 @@ public class LambdaControlsConfig
* *
* @return The HUD side. * @return The HUD side.
*/ */
public @NotNull HudSide getHudSide() public @NotNull HudSide getHudSide() {
{
return this.hudSide; return this.hudSide;
} }
@@ -276,8 +307,7 @@ public class LambdaControlsConfig
* *
* @param hudSide The HUD side. * @param hudSide The HUD side.
*/ */
public void setHudSide(@NotNull HudSide hudSide) public void setHudSide(@NotNull HudSide hudSide) {
{
this.hudSide = hudSide; this.hudSide = hudSide;
this.config.set("hud.side", hudSide.getName()); this.config.set("hud.side", hudSide.getName());
} }
@@ -286,13 +316,30 @@ public class LambdaControlsConfig
Gameplay settings Gameplay settings
*/ */
/**
* Gets whether analog movement is enabled.
*
* @return {@code true} if analog movement is enabled, else {@code false}
*/
public boolean hasAnalogMovement() {
return this.analogMovement;
}
/**
* Sets whether analog movement is enabled.
*
* @param analogMovement {@code true} if analog movement is enabled, else {@code false}
*/
public void setAnalogMovement(boolean analogMovement) {
this.config.set("gameplay.analog_movement", this.analogMovement = analogMovement);
}
/** /**
* Gets whether fast block placing is enabled or not. * Gets whether fast block placing is enabled or not.
* *
* @return True if fast block placing is enabled, else false. * @return True if fast block placing is enabled, else false.
*/ */
public boolean hasFastBlockPlacing() public boolean hasFastBlockPlacing() {
{
return LambdaControlsFeature.FAST_BLOCK_PLACING.isEnabled(); return LambdaControlsFeature.FAST_BLOCK_PLACING.isEnabled();
} }
@@ -301,8 +348,7 @@ public class LambdaControlsConfig
* *
* @param enable True if fast block placing is enabled, else false. * @param enable True if fast block placing is enabled, else false.
*/ */
public void setFastBlockPlacing(boolean enable) public void setFastBlockPlacing(boolean enable) {
{
LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(enable); LambdaControlsFeature.FAST_BLOCK_PLACING.setEnabled(enable);
this.config.set("gameplay.fast_block_placing", enable); this.config.set("gameplay.fast_block_placing", enable);
} }
@@ -312,8 +358,7 @@ public class LambdaControlsConfig
* *
* @return True if fly drifting is enabled, else false. * @return True if fly drifting is enabled, else false.
*/ */
public boolean hasFlyDrifting() public boolean hasFlyDrifting() {
{
return this.config.getOrElse("gameplay.fly.drifting", DEFAULT_FLY_DRIFTING); return this.config.getOrElse("gameplay.fly.drifting", DEFAULT_FLY_DRIFTING);
} }
@@ -322,8 +367,7 @@ public class LambdaControlsConfig
* *
* @param flyDrifting True if fly drifting is enabled, else false. * @param flyDrifting True if fly drifting is enabled, else false.
*/ */
public void setFlyDrifting(boolean flyDrifting) public void setFlyDrifting(boolean flyDrifting) {
{
this.config.set("gameplay.fly.drifting", flyDrifting); this.config.set("gameplay.fly.drifting", flyDrifting);
} }
@@ -332,8 +376,7 @@ public class LambdaControlsConfig
* *
* @return True if vertical fly drifting is enabled, else false. * @return True if vertical fly drifting is enabled, else false.
*/ */
public boolean hasFlyVerticalDrifting() public boolean hasFlyVerticalDrifting() {
{
return this.config.getOrElse("gameplay.fly.vertical_drifting", DEFAULT_FLY_VERTICAL_DRIFTING); return this.config.getOrElse("gameplay.fly.vertical_drifting", DEFAULT_FLY_VERTICAL_DRIFTING);
} }
@@ -342,8 +385,7 @@ public class LambdaControlsConfig
* *
* @param flyDrifting True if vertical fly drifting is enabled, else false. * @param flyDrifting True if vertical fly drifting is enabled, else false.
*/ */
public void setFlyVerticalDrifting(boolean flyDrifting) public void setFlyVerticalDrifting(boolean flyDrifting) {
{
this.config.set("gameplay.fly.vertical_drifting", flyDrifting); this.config.set("gameplay.fly.vertical_drifting", flyDrifting);
} }
@@ -352,9 +394,8 @@ public class LambdaControlsConfig
* *
* @return True if front block placing is enabled, else false. * @return True if front block placing is enabled, else false.
*/ */
public boolean hasFrontBlockPlacing() public boolean hasFrontBlockPlacing() {
{ return LambdaControlsFeature.HORIZONTAL_REACHAROUND.isEnabled();
return LambdaControlsFeature.FRONT_BLOCK_PLACING.isEnabled();
} }
/** /**
@@ -362,9 +403,8 @@ public class LambdaControlsConfig
* *
* @param enable True if front block placing is enabled, else false. * @param enable True if front block placing is enabled, else false.
*/ */
public void setFrontBlockPlacing(boolean enable) public void setFrontBlockPlacing(boolean enable) {
{ LambdaControlsFeature.HORIZONTAL_REACHAROUND.setEnabled(enable);
LambdaControlsFeature.FRONT_BLOCK_PLACING.setEnabled(enable);
this.config.set("gameplay.reacharound.horizontal", enable); this.config.set("gameplay.reacharound.horizontal", enable);
} }
@@ -373,8 +413,7 @@ public class LambdaControlsConfig
* *
* @return True if vertical reacharound is enabled, else false. * @return True if vertical reacharound is enabled, else false.
*/ */
public boolean hasVerticalReacharound() public boolean hasVerticalReacharound() {
{
return LambdaControlsFeature.VERTICAL_REACHAROUND.isEnabled(); return LambdaControlsFeature.VERTICAL_REACHAROUND.isEnabled();
} }
@@ -383,8 +422,7 @@ public class LambdaControlsConfig
* *
* @param enable True if vertical reacharound is enabled, else false. * @param enable True if vertical reacharound is enabled, else false.
*/ */
public void setVerticalReacharound(boolean enable) public void setVerticalReacharound(boolean enable) {
{
LambdaControlsFeature.VERTICAL_REACHAROUND.setEnabled(enable); LambdaControlsFeature.VERTICAL_REACHAROUND.setEnabled(enable);
this.config.set("gameplay.reacharound.vertical", enable); this.config.set("gameplay.reacharound.vertical", enable);
} }
@@ -394,8 +432,7 @@ public class LambdaControlsConfig
* *
* @return True if front block placing outline is enabled, else false. * @return True if front block placing outline is enabled, else false.
*/ */
public boolean shouldRenderReacharoundOutline() public boolean shouldRenderReacharoundOutline() {
{
return this.shouldRenderReacharoundOutline; return this.shouldRenderReacharoundOutline;
} }
@@ -404,8 +441,7 @@ public class LambdaControlsConfig
* *
* @param render True if front block placing outline is enabled, else false. * @param render True if front block placing outline is enabled, else false.
*/ */
public void setRenderReacharoundOutline(boolean render) public void setRenderReacharoundOutline(boolean render) {
{
this.config.set("gameplay.reacharound.outline", this.shouldRenderReacharoundOutline = render); this.config.set("gameplay.reacharound.outline", this.shouldRenderReacharoundOutline = render);
} }
@@ -416,8 +452,7 @@ public class LambdaControlsConfig
* *
* @return The color as a RGBA integer array. * @return The color as a RGBA integer array.
*/ */
public int[] getReacharoundOutlineColor() public int[] getReacharoundOutlineColor() {
{
return this.reacharoundOutlineColor; return this.reacharoundOutlineColor;
} }
@@ -428,10 +463,9 @@ public class LambdaControlsConfig
/** /**
* Gets the used controller. * Gets the used controller.
* *
* @return The used controller. * @return the controller
*/ */
public @NotNull Controller getController() public Controller getController() {
{
Object raw = this.config.getRaw("controller.id"); Object raw = this.config.getRaw("controller.id");
if (raw instanceof Number) { if (raw instanceof Number) {
return Controller.byId((Integer) raw); return Controller.byId((Integer) raw);
@@ -444,20 +478,18 @@ public class LambdaControlsConfig
/** /**
* Sets the used controller. * Sets the used controller.
* *
* @param controller The used controller. * @param controller the controller
*/ */
public void setController(@NotNull Controller controller) public void setController(Controller controller) {
{
this.config.set("controller.id", controller.getId()); this.config.set("controller.id", controller.getId());
} }
/** /**
* Gets the second controller (for Joy-Con supports). * Gets the second controller (for Joy-Con supports).
* *
* @return The second controller. * @return the second controller
*/ */
public @NotNull Optional<Controller> getSecondController() public Optional<Controller> getSecondController() {
{
Object raw = this.config.getRaw("controller.id2"); Object raw = this.config.getRaw("controller.id2");
if (raw instanceof Number) { if (raw instanceof Number) {
if ((int) raw == -1) if ((int) raw == -1)
@@ -472,10 +504,9 @@ public class LambdaControlsConfig
/** /**
* Sets the second controller. * Sets the second controller.
* *
* @param controller The second controller. * @param controller the second controller
*/ */
public void setSecondController(@Nullable Controller controller) public void setSecondController(@Nullable Controller controller) {
{
this.config.set("controller.id2", controller == null ? -1 : controller.getId()); this.config.set("controller.id2", controller == null ? -1 : controller.getId());
} }
@@ -484,8 +515,7 @@ public class LambdaControlsConfig
* *
* @return The controller's type. * @return The controller's type.
*/ */
public @NotNull ControllerType getControllerType() public @NotNull ControllerType getControllerType() {
{
return this.controllerType; return this.controllerType;
} }
@@ -494,30 +524,45 @@ public class LambdaControlsConfig
* *
* @param controllerType The controller's type. * @param controllerType The controller's type.
*/ */
public void setControllerType(@NotNull ControllerType controllerType) public void setControllerType(@NotNull ControllerType controllerType) {
{
this.controllerType = controllerType; this.controllerType = controllerType;
this.config.set("controller.type", controllerType.getName()); this.config.set("controller.type", controllerType.getName());
} }
/** /**
* Gets the controller's dead zone from the configuration. * Gets the controller's right dead zone from the configuration.
* *
* @return The controller's dead zone value. * @return the controller's right dead zone value
*/ */
public double getDeadZone() public double getRightDeadZone() {
{ return this.rightDeadZone;
return this.deadZone;
} }
/** /**
* Sets the controller's dead zone in the configuration. * Sets the controller's right dead zone in the configuration.
* *
* @param deadZone The new controller's dead zone value. * @param deadZone the controller's right dead zone value
*/ */
public void setDeadZone(double deadZone) public void setRightDeadZone(double deadZone) {
{ this.rightDeadZone = deadZone;
this.deadZone = deadZone; }
/**
* Gets the controller's left dead zone from the configuration.
*
* @return the controller's left dead zone value
*/
public double getLeftDeadZone() {
return this.leftDeadZone;
}
/**
* Sets the controller's left dead zone in the configuration.
*
* @param deadZone the controller's left dead zone value
*/
public void setLeftDeadZone(double deadZone) {
this.leftDeadZone = deadZone;
} }
/** /**
@@ -525,8 +570,7 @@ public class LambdaControlsConfig
* *
* @return The rotation speed. * @return The rotation speed.
*/ */
public double getRotationSpeed() public double getRotationSpeed() {
{
return this.rotationSpeed; return this.rotationSpeed;
} }
@@ -535,8 +579,7 @@ public class LambdaControlsConfig
* *
* @param rotationSpeed The rotation speed. * @param rotationSpeed The rotation speed.
*/ */
public void setRotationSpeed(double rotationSpeed) public void setRotationSpeed(double rotationSpeed) {
{
this.rotationSpeed = rotationSpeed; this.rotationSpeed = rotationSpeed;
} }
@@ -545,8 +588,7 @@ public class LambdaControlsConfig
* *
* @return The mouse speed. * @return The mouse speed.
*/ */
public double getMouseSpeed() public double getMouseSpeed() {
{
return this.mouseSpeed; return this.mouseSpeed;
} }
@@ -555,8 +597,7 @@ public class LambdaControlsConfig
* *
* @param mouseSpeed The mouse speed. * @param mouseSpeed The mouse speed.
*/ */
public void setMouseSpeed(double mouseSpeed) public void setMouseSpeed(double mouseSpeed) {
{
this.mouseSpeed = mouseSpeed; this.mouseSpeed = mouseSpeed;
} }
@@ -565,8 +606,7 @@ public class LambdaControlsConfig
* *
* @return True if the right X axis is inverted, else false. * @return True if the right X axis is inverted, else false.
*/ */
public boolean doesInvertRightXAxis() public boolean doesInvertRightXAxis() {
{
return this.config.getOrElse("controller.invert_right_x_axis", false); return this.config.getOrElse("controller.invert_right_x_axis", false);
} }
@@ -575,8 +615,7 @@ public class LambdaControlsConfig
* *
* @param invert True if the right X axis is inverted, else false. * @param invert True if the right X axis is inverted, else false.
*/ */
public void setInvertRightXAxis(boolean invert) public void setInvertRightXAxis(boolean invert) {
{
this.config.set("controller.invert_right_x_axis", invert); this.config.set("controller.invert_right_x_axis", invert);
} }
@@ -585,8 +624,7 @@ public class LambdaControlsConfig
* *
* @return True if the right Y axis is inverted, else false. * @return True if the right Y axis is inverted, else false.
*/ */
public boolean doesInvertRightYAxis() public boolean doesInvertRightYAxis() {
{
return this.config.getOrElse("controller.invert_right_y_axis", false); return this.config.getOrElse("controller.invert_right_y_axis", false);
} }
@@ -595,8 +633,7 @@ public class LambdaControlsConfig
* *
* @param invert True if the right Y axis is inverted, else false. * @param invert True if the right Y axis is inverted, else false.
*/ */
public void setInvertRightYAxis(boolean invert) public void setInvertRightYAxis(boolean invert) {
{
this.config.set("controller.invert_right_y_axis", invert); this.config.set("controller.invert_right_y_axis", invert);
} }
@@ -605,8 +642,7 @@ public class LambdaControlsConfig
* *
* @return True if unfocused controller input is allowed, else false. * @return True if unfocused controller input is allowed, else false.
*/ */
public boolean hasUnfocusedInput() public boolean hasUnfocusedInput() {
{
return this.unfocusedInput; return this.unfocusedInput;
} }
@@ -615,8 +651,7 @@ public class LambdaControlsConfig
* *
* @param unfocusedInput True if unfocused controller input is allowed, else false. * @param unfocusedInput True if unfocused controller input is allowed, else false.
*/ */
public void setUnfocusedInput(boolean unfocusedInput) public void setUnfocusedInput(boolean unfocusedInput) {
{
this.unfocusedInput = unfocusedInput; this.unfocusedInput = unfocusedInput;
} }
@@ -625,8 +660,7 @@ public class LambdaControlsConfig
* *
* @return True if the mouse is virtual, else false. * @return True if the mouse is virtual, else false.
*/ */
public boolean hasVirtualMouse() public boolean hasVirtualMouse() {
{
return this.virtualMouse; return this.virtualMouse;
} }
@@ -635,8 +669,7 @@ public class LambdaControlsConfig
* *
* @param virtualMouse True if the mouse is virtual, else false. * @param virtualMouse True if the mouse is virtual, else false.
*/ */
public void setVirtualMouse(boolean virtualMouse) public void setVirtualMouse(boolean virtualMouse) {
{
this.virtualMouse = virtualMouse; this.virtualMouse = virtualMouse;
} }
@@ -645,8 +678,7 @@ public class LambdaControlsConfig
* *
* @return The virtual mouse skin. * @return The virtual mouse skin.
*/ */
public VirtualMouseSkin getVirtualMouseSkin() public VirtualMouseSkin getVirtualMouseSkin() {
{
return this.virtualMouseSkin; return this.virtualMouseSkin;
} }
@@ -655,8 +687,7 @@ public class LambdaControlsConfig
* *
* @param skin The virtual mouse skin. * @param skin The virtual mouse skin.
*/ */
public void setVirtualMouseSkin(VirtualMouseSkin skin) public void setVirtualMouseSkin(VirtualMouseSkin skin) {
{
this.virtualMouseSkin = skin; this.virtualMouseSkin = skin;
this.config.set("controller.virtual_mouse_skin", skin.getName()); this.config.set("controller.virtual_mouse_skin", skin.getName());
} }
@@ -666,8 +697,7 @@ public class LambdaControlsConfig
* *
* @return The right X axis sign. * @return The right X axis sign.
*/ */
public double getRightXAxisSign() public double getRightXAxisSign() {
{
return this.doesInvertRightXAxis() ? -1.0 : 1.0; return this.doesInvertRightXAxis() ? -1.0 : 1.0;
} }
@@ -676,18 +706,27 @@ public class LambdaControlsConfig
* *
* @return The right Y axis sign. * @return The right Y axis sign.
*/ */
public double getRightYAxisSign() public double getRightYAxisSign() {
{
return this.doesInvertRightYAxis() ? -1.0 : 1.0; return this.doesInvertRightYAxis() ? -1.0 : 1.0;
} }
public double getAxisMaxValue(int axis) {
if (axis >= this.maxAnalogValues.length)
return DEFAULT_MAX_VALUE;
return this.maxAnalogValues[axis];
}
public void setAxisMaxValue(int axis, double value) {
if (axis < this.maxAnalogValues.length)
this.maxAnalogValues[axis] = value;
}
/** /**
* Loads the button binding from configuration. * Loads the button binding from configuration.
* *
* @param button The button binding. * @param button The button binding.
*/ */
public void loadButtonBinding(@NotNull ButtonBinding button) public void loadButtonBinding(@NotNull ButtonBinding button) {
{
button.setButton(button.getDefaultButton()); button.setButton(button.getDefaultButton());
String code = this.config.getOrElse("controller.controls." + button.getName(), button.getButtonCode()); String code = this.config.getOrElse("controller.controls." + button.getName(), button.getButtonCode());
@@ -717,8 +756,7 @@ public class LambdaControlsConfig
} }
} }
private boolean checkValidity(@NotNull ButtonBinding binding, @NotNull String input, String group) private boolean checkValidity(@NotNull ButtonBinding binding, @NotNull String input, String group) {
{
if (group == null) { if (group == null) {
this.mod.warn("Malformed config value \"" + input + "\" for binding \"" + binding.getName() + "\"."); this.mod.warn("Malformed config value \"" + input + "\" for binding \"" + binding.getName() + "\".");
this.config.set("controller.controls." + binding.getName(), binding.getButtonCode()); this.config.set("controller.controls." + binding.getName(), binding.getButtonCode());
@@ -733,35 +771,30 @@ public class LambdaControlsConfig
* @param binding The button binding. * @param binding The button binding.
* @param button The button. * @param button The button.
*/ */
public void setButtonBinding(@NotNull ButtonBinding binding, int[] button) public void setButtonBinding(@NotNull ButtonBinding binding, int[] button) {
{
binding.setButton(button); binding.setButton(button);
this.config.set("controller.controls." + binding.getName(), binding.getButtonCode()); this.config.set("controller.controls." + binding.getName(), binding.getButtonCode());
} }
public boolean isBackButton(int btn, boolean isBtn, int state) public boolean isBackButton(int btn, boolean isBtn, int state) {
{
if (!isBtn && state == 0) if (!isBtn && state == 0)
return false; return false;
return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, false) == ButtonBinding.axisAsButton(btn, state == 1); return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, false) == ButtonBinding.axisAsButton(btn, state == 1);
} }
public boolean isForwardButton(int btn, boolean isBtn, int state) public boolean isForwardButton(int btn, boolean isBtn, int state) {
{
if (!isBtn && state == 0) if (!isBtn && state == 0)
return false; return false;
return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, true) == ButtonBinding.axisAsButton(btn, state == 1); return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, true) == ButtonBinding.axisAsButton(btn, state == 1);
} }
public boolean isLeftButton(int btn, boolean isBtn, int state) public boolean isLeftButton(int btn, boolean isBtn, int state) {
{
if (!isBtn && state == 0) if (!isBtn && state == 0)
return false; return false;
return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, false) == ButtonBinding.axisAsButton(btn, state == 1); return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, false) == ButtonBinding.axisAsButton(btn, state == 1);
} }
public boolean isRightButton(int btn, boolean isBtn, int state) public boolean isRightButton(int btn, boolean isBtn, int state) {
{
if (!isBtn && state == 0) if (!isBtn && state == 0)
return false; return false;
return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, true) == ButtonBinding.axisAsButton(btn, state == 1); return ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, true) == ButtonBinding.axisAsButton(btn, state == 1);
@@ -773,8 +806,7 @@ public class LambdaControlsConfig
* @param axis The axis index. * @param axis The axis index.
* @return True if the axis is used for movements, else false. * @return True if the axis is used for movements, else false.
*/ */
public boolean isMovementAxis(int axis) public boolean isMovementAxis(int axis) {
{
return axis == GLFW_GAMEPAD_AXIS_LEFT_Y || axis == GLFW_GAMEPAD_AXIS_LEFT_X; return axis == GLFW_GAMEPAD_AXIS_LEFT_Y || axis == GLFW_GAMEPAD_AXIS_LEFT_X;
} }
@@ -784,8 +816,7 @@ public class LambdaControlsConfig
* @param hex The hexadecimal color. * @param hex The hexadecimal color.
* @return The color instance, null if invalid. * @return The color instance, null if invalid.
*/ */
private static int[] parseColor(String hex) private static int[] parseColor(String hex) {
{
hex = hex.replace("#", ""); hex = hex.replace("#", "");
switch (hex.length()) { switch (hex.length()) {
case 6: case 6:

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,11 +7,11 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi; import io.github.prospector.modmenu.api.ModMenuApi;
import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
/** /**
* Represents the API implementation of ModMenu for LambdaControls. * Represents the API implementation of ModMenu for LambdaControls.
@@ -20,11 +20,9 @@ import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
* @version 1.3.0 * @version 1.3.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsModMenu implements ModMenuApi public class LambdaControlsModMenu implements ModMenuApi {
{
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() public ConfigScreenFactory<?> getModConfigScreenFactory() {
{
return parent -> new LambdaControlsSettingsScreen(parent, false); return parent -> new LambdaControlsSettingsScreen(parent, false);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,21 +7,26 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import me.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.Controller; import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.lambdacontrols.client.controller.InputManager; import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.lambdacontrols.client.gui.ControllerControlsScreen; import dev.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay;
import me.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay; import dev.lambdaurora.lambdacontrols.client.gui.widget.ControllerControlsWidget;
import me.lambdaurora.lambdacontrols.client.mixin.AdvancementsScreenAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.AdvancementsScreenAccessor;
import me.lambdaurora.lambdacontrols.client.mixin.CreativeInventoryScreenAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.CreativeInventoryScreenAccessor;
import me.lambdaurora.lambdacontrols.client.mixin.EntryListWidgetAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.EntryListWidgetAccessor;
import me.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor; import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import me.lambdaurora.lambdacontrols.client.util.MouseAccessor; import dev.lambdaurora.lambdacontrols.client.util.MouseAccessor;
import me.lambdaurora.spruceui.SpruceLabelWidget; import me.lambdaurora.spruceui.navigation.NavigationDirection;
import me.lambdaurora.spruceui.screen.SpruceScreen;
import me.lambdaurora.spruceui.widget.AbstractSprucePressableButtonWidget;
import me.lambdaurora.spruceui.widget.SpruceElement;
import me.lambdaurora.spruceui.widget.SpruceLabelWidget;
import me.lambdaurora.spruceui.widget.container.SpruceParentWidget;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.ParentElement; import net.minecraft.client.gui.ParentElement;
@@ -32,7 +37,7 @@ import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget; import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
import net.minecraft.client.gui.screen.pack.ResourcePackScreen; import net.minecraft.client.gui.screen.pack.PackScreen;
import net.minecraft.client.gui.screen.world.WorldListWidget; import net.minecraft.client.gui.screen.world.WorldListWidget;
import net.minecraft.client.gui.widget.AbstractPressableButtonWidget; import net.minecraft.client.gui.widget.AbstractPressableButtonWidget;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
@@ -56,19 +61,18 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import static me.lambdaurora.lambdacontrols.client.controller.ButtonBinding.axisAsButton; import static dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding.axisAsButton;
import static me.lambdaurora.lambdacontrols.client.controller.InputManager.INPUT_MANAGER; import static dev.lambdaurora.lambdacontrols.client.controller.InputManager.INPUT_MANAGER;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
/** /**
* Represents the LambdaControls' input handler. * Represents the LambdaControls' input handler.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.6.0
* @since 1.0.0 * @since 1.0.0
*/ */
public class LambdaInput public class LambdaInput {
{
private static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>(); private static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>();
private final LambdaControlsConfig config; private final LambdaControlsConfig config;
// Cooldowns // Cooldowns
@@ -76,16 +80,17 @@ public class LambdaInput
private boolean ignoreNextARelease = false; private boolean ignoreNextARelease = false;
private double targetYaw = 0.0; private double targetYaw = 0.0;
private double targetPitch = 0.0; private double targetPitch = 0.0;
private float prevXAxis = 0.F; private float prevXAxis = 0.f;
private float prevYAxis = 0.F; private float prevYAxis = 0.f;
private int targetMouseX = 0; private int targetMouseX = 0;
private int targetMouseY = 0; private int targetMouseY = 0;
private float mouseSpeedX = 0.F; private float mouseSpeedX = 0.f;
private float mouseSpeedY = 0.F; private float mouseSpeedY = 0.f;
private int inventoryInteractionCooldown = 0; private int inventoryInteractionCooldown = 0;
public LambdaInput(@NotNull LambdaControlsClient mod) private ControllerControlsWidget controlsInput = null;
{
public LambdaInput(@NotNull LambdaControlsClient mod) {
this.config = mod.config; this.config = mod.config;
} }
@@ -94,8 +99,7 @@ public class LambdaInput
* *
* @param client The client instance. * @param client The client instance.
*/ */
public void onTick(@NotNull MinecraftClient client) public void tick(@NotNull MinecraftClient client) {
{
this.targetYaw = 0.F; this.targetYaw = 0.F;
this.targetPitch = 0.F; this.targetPitch = 0.F;
@@ -119,8 +123,7 @@ public class LambdaInput
* *
* @param client The client instance. * @param client The client instance.
*/ */
public void onControllerTick(@NotNull MinecraftClient client) public void tickController(@NotNull MinecraftClient client) {
{
BUTTON_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> BUTTON_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1)); BUTTON_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> BUTTON_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1));
// Decreases the cooldown for GUI actions. // Decreases the cooldown for GUI actions.
if (this.actionGuiCooldown > 0) if (this.actionGuiCooldown > 0)
@@ -143,20 +146,21 @@ public class LambdaInput
boolean allowInput = true; boolean allowInput = true;
if (client.currentScreen instanceof ControllerControlsScreen && ((ControllerControlsScreen) client.currentScreen).focusedBinding != null) if (this.controlsInput != null && this.controlsInput.focusedBinding != null)
allowInput = false; allowInput = false;
if (allowInput) if (allowInput)
InputManager.updateBindings(client); InputManager.updateBindings(client);
if (client.currentScreen instanceof ControllerControlsScreen && InputManager.STATES.entrySet().parallelStream().map(Map.Entry::getValue).allMatch(ButtonState::isUnpressed)) { if (this.controlsInput != null
ControllerControlsScreen screen = (ControllerControlsScreen) client.currentScreen; && InputManager.STATES.entrySet().parallelStream().map(Map.Entry::getValue).allMatch(ButtonState::isUnpressed)) {
if (screen.focusedBinding != null && !screen.waiting) { if (this.controlsInput.focusedBinding != null && !this.controlsInput.waiting) {
int[] buttons = new int[screen.currentButtons.size()]; int[] buttons = new int[this.controlsInput.currentButtons.size()];
for (int i = 0; i < screen.currentButtons.size(); i++) for (int i = 0; i < this.controlsInput.currentButtons.size(); i++)
buttons[i] = screen.currentButtons.get(i); buttons[i] = this.controlsInput.currentButtons.get(i);
screen.focusedBinding.setButton(buttons); this.controlsInput.focusedBinding.setButton(buttons);
screen.focusedBinding = null; this.controlsInput.focusedBinding = null;
this.controlsInput = null;
} }
} }
@@ -170,8 +174,7 @@ public class LambdaInput
* @param client The client instance. * @param client The client instance.
* @param screen The screen to render. * @param screen The screen to render.
*/ */
public void onPreRenderScreen(@NotNull MinecraftClient client, @NotNull Screen screen) public void onPreRenderScreen(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
if (!isScreenInteractive(screen)) { if (!isScreenInteractive(screen)) {
INPUT_MANAGER.updateMousePosition(client); INPUT_MANAGER.updateMousePosition(client);
} }
@@ -182,8 +185,7 @@ public class LambdaInput
* *
* @param client The client instance. * @param client The client instance.
*/ */
public void onRender(float tickDelta, @NotNull MinecraftClient client) public void onRender(float tickDelta, @NotNull MinecraftClient client) {
{
if (!(client.currentScreen == null || client.currentScreen instanceof TouchscreenOverlay)) if (!(client.currentScreen == null || client.currentScreen instanceof TouchscreenOverlay))
return; return;
@@ -191,13 +193,13 @@ public class LambdaInput
if (player == null) if (player == null)
return; return;
if (this.targetYaw != 0F || this.targetPitch != 0F) { if (this.targetYaw != 0.f || this.targetPitch != 0.f) {
float rotationYaw = (float) (player.prevYaw + (this.targetYaw / 0.10) * tickDelta); float rotationYaw = (float) (player.prevYaw + (this.targetYaw / 0.10) * tickDelta);
float rotationPitch = (float) (player.prevPitch + (this.targetPitch / 0.10) * tickDelta); float rotationPitch = (float) (player.prevPitch + (this.targetPitch / 0.10) * tickDelta);
client.player.yaw = rotationYaw; client.player.yaw = rotationYaw;
client.player.pitch = MathHelper.clamp(rotationPitch, -90.F, 90.F); client.player.pitch = MathHelper.clamp(rotationPitch, -90.f, 90.f);
if (client.player.isRiding()) { if (client.player.isRiding()) {
client.player.getVehicle().copyPositionAndRotation(client.player); client.player.getVehicle().onPassengerLookAround(client.player);
} }
client.getTutorialManager().onUpdateMouse(this.targetPitch, this.targetYaw); client.getTutorialManager().onUpdateMouse(this.targetPitch, this.targetYaw);
} }
@@ -210,20 +212,26 @@ public class LambdaInput
* @param windowWidth The window width. * @param windowWidth The window width.
* @param windowHeight The window height. * @param windowHeight The window height.
*/ */
public void onScreenOpen(@NotNull MinecraftClient client, int windowWidth, int windowHeight) public void onScreenOpen(@NotNull MinecraftClient client, int windowWidth, int windowHeight) {
{
if (client.currentScreen == null) { if (client.currentScreen == null) {
this.mouseSpeedX = this.mouseSpeedY = 0.0F; this.mouseSpeedX = this.mouseSpeedY = 0.0F;
INPUT_MANAGER.resetMousePosition(windowWidth, windowHeight); INPUT_MANAGER.resetMousePosition(windowWidth, windowHeight);
} else if (isScreenInteractive(client.currentScreen) && this.config.hasVirtualMouse()) { } else if (isScreenInteractive(client.currentScreen) && this.config.hasVirtualMouse()) {
((MouseAccessor) client.mouse).lambdacontrols_onCursorPos(client.getWindow().getHandle(), 0, 0); ((MouseAccessor) client.mouse).lambdacontrols$onCursorPos(client.getWindow().getHandle(), 0, 0);
INPUT_MANAGER.resetMouseTarget(client); INPUT_MANAGER.resetMouseTarget(client);
} }
this.inventoryInteractionCooldown = 5; this.inventoryInteractionCooldown = 5;
} }
private void fetchButtonInput(@NotNull MinecraftClient client, @NotNull GLFWGamepadState gamepadState, boolean leftJoycon) public void beginControlsInput(ControllerControlsWidget widget) {
{ this.controlsInput = widget;
if (widget != null) {
this.controlsInput.currentButtons.clear();
this.controlsInput.waiting = true;
}
}
private void fetchButtonInput(@NotNull MinecraftClient client, @NotNull GLFWGamepadState gamepadState, boolean leftJoycon) {
ByteBuffer buffer = gamepadState.buttons(); ByteBuffer buffer = gamepadState.buttons();
for (int i = 0; i < buffer.limit(); i++) { for (int i = 0; i < buffer.limit(); i++) {
int btn = leftJoycon ? ButtonBinding.controller2Button(i) : i; int btn = leftJoycon ? ButtonBinding.controller2Button(i) : i;
@@ -248,8 +256,7 @@ public class LambdaInput
} }
} }
private void fetchAxeInput(@NotNull MinecraftClient client, @NotNull GLFWGamepadState gamepadState, boolean leftJoycon) private void fetchAxeInput(@NotNull MinecraftClient client, @NotNull GLFWGamepadState gamepadState, boolean leftJoycon) {
{
FloatBuffer buffer = gamepadState.axes(); FloatBuffer buffer = gamepadState.axes();
for (int i = 0; i < buffer.limit(); i++) { for (int i = 0; i < buffer.limit(); i++) {
int axis = leftJoycon ? ButtonBinding.controller2Button(i) : i; int axis = leftJoycon ? ButtonBinding.controller2Button(i) : i;
@@ -259,29 +266,25 @@ public class LambdaInput
if (i == GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y) if (i == GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y)
value *= -1.0F; value *= -1.0F;
int state = value > this.config.getDeadZone() ? 1 : (value < -this.config.getDeadZone() ? 2 : 0); int state = value > this.config.getRightDeadZone() ? 1 : (value < -this.config.getRightDeadZone() ? 2 : 0);
this.handleAxe(client, axis, value, absValue, state); this.handleAxe(client, axis, value, absValue, state);
} }
} }
private void handleButton(@NotNull MinecraftClient client, int button, int action, boolean state) private void handleButton(@NotNull MinecraftClient client, int button, int action, boolean state) {
{ if (this.controlsInput != null && this.controlsInput.focusedBinding != null) {
if (client.currentScreen instanceof ControllerControlsScreen) { if (action == 0 && !this.controlsInput.currentButtons.contains(button)) {
ControllerControlsScreen screen = (ControllerControlsScreen) client.currentScreen; this.controlsInput.currentButtons.add(button);
if (screen.focusedBinding != null) {
if (action == 0 && !screen.currentButtons.contains(button)) {
screen.currentButtons.add(button);
int[] buttons = new int[screen.currentButtons.size()]; int[] buttons = new int[this.controlsInput.currentButtons.size()];
for (int i = 0; i < screen.currentButtons.size(); i++) for (int i = 0; i < this.controlsInput.currentButtons.size(); i++)
buttons[i] = screen.currentButtons.get(i); buttons[i] = this.controlsInput.currentButtons.get(i);
screen.focusedBinding.setButton(buttons); this.controlsInput.focusedBinding.setButton(buttons);
screen.waiting = false; this.controlsInput.waiting = false;
} }
return; return;
} }
}
if (action == 0 || action == 2) { if (action == 0 || action == 2) {
if (client.currentScreen != null && isScreenInteractive(client.currentScreen) if (client.currentScreen != null && isScreenInteractive(client.currentScreen)
@@ -289,9 +292,9 @@ public class LambdaInput
|| button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT || button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT)) { || button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT || button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT)) {
if (this.actionGuiCooldown == 0) { if (this.actionGuiCooldown == 0) {
if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP) { if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP) {
this.changeFocus(client.currentScreen, false); this.changeFocus(client.currentScreen, NavigationDirection.UP);
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN) { } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN) {
this.changeFocus(client.currentScreen, true); this.changeFocus(client.currentScreen, NavigationDirection.DOWN);
} else if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT) { } else if (button == GLFW.GLFW_GAMEPAD_BUTTON_DPAD_LEFT) {
this.handleLeftRight(client.currentScreen, false); this.handleLeftRight(client.currentScreen, false);
} else { } else {
@@ -355,8 +358,7 @@ public class LambdaInput
* @param button The button pressed. * @param button The button pressed.
* @return True if an inventory interaction was done. * @return True if an inventory interaction was done.
*/ */
private boolean handleInventory(@NotNull MinecraftClient client, int button) private boolean handleInventory(@NotNull MinecraftClient client, int button) {
{
if (!(client.currentScreen instanceof HandledScreen)) if (!(client.currentScreen instanceof HandledScreen))
return false; return false;
@@ -376,13 +378,13 @@ public class LambdaInput
HandledScreen screen = (HandledScreen) client.currentScreen; HandledScreen screen = (HandledScreen) client.currentScreen;
HandledScreenAccessor accessor = (HandledScreenAccessor) screen; HandledScreenAccessor accessor = (HandledScreenAccessor) screen;
Slot slot = ((HandledScreenAccessor) client.currentScreen).lambdacontrols_getSlotAt(x, y); Slot slot = ((HandledScreenAccessor) client.currentScreen).lambdacontrols$getSlotAt(x, y);
int slotId; int slotId;
if (slot == null) { if (slot == null) {
if (client.player.inventory.getCursorStack().isEmpty()) if (client.player.inventory.getCursorStack().isEmpty())
return false; return false;
slotId = accessor.lambdacontrols_isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1; slotId = accessor.lambdacontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1;
} else { } else {
slotId = slot.id; slotId = slot.id;
} }
@@ -392,7 +394,7 @@ public class LambdaInput
switch (button) { switch (button) {
case GLFW_GAMEPAD_BUTTON_A: case GLFW_GAMEPAD_BUTTON_A:
if (screen instanceof CreativeInventoryScreen) if (screen instanceof CreativeInventoryScreen)
if (((CreativeInventoryScreenAccessor) screen).lambdacontrols_isCreativeInventorySlot(slot)) if (((CreativeInventoryScreenAccessor) screen).lambdacontrols$isCreativeInventorySlot(slot))
actionType = SlotActionType.CLONE; actionType = SlotActionType.CLONE;
if (slot != null && LambdaControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot))) if (slot != null && LambdaControlsCompat.streamCompatHandlers().anyMatch(handler -> handler.isCreativeSlot(screen, slot)))
actionType = SlotActionType.CLONE; actionType = SlotActionType.CLONE;
@@ -407,7 +409,7 @@ public class LambdaInput
return false; return false;
} }
accessor.lambdacontrols_onMouseClick(slot, slotId, clickData, actionType); accessor.lambdacontrols$onMouseClick(slot, slotId, clickData, actionType);
return true; return true;
} }
@@ -417,8 +419,7 @@ public class LambdaInput
* @param screen The current screen. * @param screen The current screen.
* @return True if successful, else false. * @return True if successful, else false.
*/ */
public boolean tryGoBack(@NotNull Screen screen) public boolean tryGoBack(@NotNull Screen screen) {
{
ImmutableSet<String> set = ImmutableSet.of("gui.back", "gui.done", "gui.cancel", "gui.toTitle", "gui.toMenu"); ImmutableSet<String> set = ImmutableSet.of("gui.back", "gui.done", "gui.cancel", "gui.toTitle", "gui.toMenu");
return screen.children().stream().filter(element -> element instanceof AbstractPressableButtonWidget) return screen.children().stream().filter(element -> element instanceof AbstractPressableButtonWidget)
.map(element -> (AbstractPressableButtonWidget) element) .map(element -> (AbstractPressableButtonWidget) element)
@@ -432,12 +433,17 @@ public class LambdaInput
}); });
} }
private void handleAxe(@NotNull MinecraftClient client, int axis, float value, float absValue, int state) private double getDeadZoneValue(int axis) {
{ return (axis == GLFW_GAMEPAD_AXIS_LEFT_X || axis == GLFW_GAMEPAD_AXIS_LEFT_Y) ? this.config.getLeftDeadZone()
int asButtonState = value > 0.5F ? 1 : (value < -0.5F ? 2 : 0); : this.config.getRightDeadZone();
}
if (axis == GLFW_GAMEPAD_AXIS_LEFT_TRIGGER || axis == GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER || axis == ButtonBinding.controller2Button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER) || private void handleAxe(@NotNull MinecraftClient client, int axis, float value, float absValue, int state) {
axis == ButtonBinding.controller2Button(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER)) int asButtonState = value > .5f ? 1 : (value < -.5f ? 2 : 0);
if (axis == GLFW_GAMEPAD_AXIS_LEFT_TRIGGER || axis == GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER
|| axis == ButtonBinding.controller2Button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER)
|| axis == ButtonBinding.controller2Button(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER))
if (asButtonState == 2) if (asButtonState == 2)
asButtonState = 0; asButtonState = 0;
@@ -469,8 +475,11 @@ public class LambdaInput
} }
} }
float axisValue = absValue < this.config.getDeadZone() ? 0.f : (float) (absValue - this.config.getDeadZone()); double deadZone = this.getDeadZoneValue(axis);
axisValue /= (1.0 - this.config.getDeadZone()); float axisValue = absValue < deadZone ? 0.f : (float) (absValue - deadZone);
axisValue /= (1.0 - deadZone);
axisValue = (float) Math.min(axisValue / this.config.getAxisMaxValue(axis), 1);
if (currentPlusState) if (currentPlusState)
InputManager.BUTTON_VALUES.put(axisAsButton(axis, true), axisValue); InputManager.BUTTON_VALUES.put(axisAsButton(axis, true), axisValue);
else else
@@ -481,30 +490,27 @@ public class LambdaInput
InputManager.BUTTON_VALUES.put(axisAsButton(axis, false), 0.f); InputManager.BUTTON_VALUES.put(axisAsButton(axis, false), 0.f);
} }
double deadZone = this.config.getDeadZone(); double deadZone = this.getDeadZoneValue(axis);
if (client.currentScreen instanceof ControllerControlsScreen) { if (this.controlsInput != null && this.controlsInput.focusedBinding != null) {
ControllerControlsScreen screen = (ControllerControlsScreen) client.currentScreen; if (asButtonState != 0 && !this.controlsInput.currentButtons.contains(axisAsButton(axis, asButtonState == 1))) {
if (screen.focusedBinding != null) {
if (asButtonState != 0 && !screen.currentButtons.contains(axisAsButton(axis, asButtonState == 1))) {
screen.currentButtons.add(axisAsButton(axis, asButtonState == 1)); this.controlsInput.currentButtons.add(axisAsButton(axis, asButtonState == 1));
int[] buttons = new int[screen.currentButtons.size()]; int[] buttons = new int[this.controlsInput.currentButtons.size()];
for (int i = 0; i < screen.currentButtons.size(); i++) for (int i = 0; i < this.controlsInput.currentButtons.size(); i++)
buttons[i] = screen.currentButtons.get(i); buttons[i] = this.controlsInput.currentButtons.get(i);
screen.focusedBinding.setButton(buttons); this.controlsInput.focusedBinding.setButton(buttons);
screen.waiting = false; this.controlsInput.waiting = false;
} }
return; return;
}
} else if (client.currentScreen instanceof CreativeInventoryScreen) { } else if (client.currentScreen instanceof CreativeInventoryScreen) {
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) { if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) {
CreativeInventoryScreen screen = (CreativeInventoryScreen) client.currentScreen; CreativeInventoryScreen screen = (CreativeInventoryScreen) client.currentScreen;
CreativeInventoryScreenAccessor accessor = (CreativeInventoryScreenAccessor) screen; CreativeInventoryScreenAccessor accessor = (CreativeInventoryScreenAccessor) screen;
// @TODO allow rebinding to left stick // @TODO allow rebinding to left stick
if (accessor.lambdacontrols_hasScrollbar() && absValue >= deadZone) { if (accessor.lambdacontrols$hasScrollbar() && absValue >= deadZone) {
screen.mouseScrolled(0.0, 0.0, -value); screen.mouseScrolled(0.0, 0.0, -value);
} }
return; return;
@@ -521,18 +527,20 @@ public class LambdaInput
} }
} }
absValue -= deadZone;
absValue /= (1.0 - deadZone);
absValue = (float) MathHelper.clamp(absValue / this.config.getAxisMaxValue(axis), 0.f, 1.f);
if (client.currentScreen == null) { if (client.currentScreen == null) {
// Handles the look direction. // Handles the look direction.
absValue -= this.config.getDeadZone(); this.handleLook(client, axis, absValue, state);
this.handleLook(client, axis, (float) (absValue / (1.0 - this.config.getDeadZone())), state);
} else { } else {
boolean allowMouseControl = true; boolean allowMouseControl = true;
if (this.actionGuiCooldown == 0 && this.config.isMovementAxis(axis) && isScreenInteractive(client.currentScreen)) { if (this.actionGuiCooldown == 0 && this.config.isMovementAxis(axis) && isScreenInteractive(client.currentScreen)) {
if (this.config.isForwardButton(axis, false, asButtonState)) { if (this.config.isForwardButton(axis, false, asButtonState)) {
allowMouseControl = this.changeFocus(client.currentScreen, false); allowMouseControl = this.changeFocus(client.currentScreen, NavigationDirection.UP);
} else if (this.config.isBackButton(axis, false, asButtonState)) { } else if (this.config.isBackButton(axis, false, asButtonState)) {
allowMouseControl = this.changeFocus(client.currentScreen, true); allowMouseControl = this.changeFocus(client.currentScreen, NavigationDirection.DOWN);
} else if (this.config.isLeftButton(axis, false, asButtonState)) { } else if (this.config.isLeftButton(axis, false, asButtonState)) {
allowMouseControl = this.handleLeftRight(client.currentScreen, false); allowMouseControl = this.handleLeftRight(client.currentScreen, false);
} else if (this.config.isRightButton(axis, false, asButtonState)) { } else if (this.config.isRightButton(axis, false, asButtonState)) {
@@ -540,8 +548,8 @@ public class LambdaInput
} }
} }
float movementX = 0.0F; float movementX = 0.f;
float movementY = 0.0F; float movementY = 0.f;
if (this.config.isBackButton(axis, false, (value > 0 ? 1 : 2))) { if (this.config.isBackButton(axis, false, (value > 0 ? 1 : 2))) {
movementY = absValue; movementY = absValue;
@@ -554,7 +562,7 @@ public class LambdaInput
} }
if (client.currentScreen != null && allowMouseControl) { if (client.currentScreen != null && allowMouseControl) {
boolean moving = Math.abs(movementY) >= deadZone || Math.abs(movementX) >= deadZone; boolean moving = movementY != 0 || movementX != 0;
if (moving) { if (moving) {
/* /*
Updates the target mouse position when the initial movement stick movement is detected. Updates the target mouse position when the initial movement stick movement is detected.
@@ -564,22 +572,18 @@ public class LambdaInput
INPUT_MANAGER.resetMouseTarget(client); INPUT_MANAGER.resetMouseTarget(client);
} }
if (Math.abs(movementX) >= deadZone)
this.mouseSpeedX = movementX; this.mouseSpeedX = movementX;
else
this.mouseSpeedX = 0.F;
if (Math.abs(movementY) >= deadZone)
this.mouseSpeedY = movementY; this.mouseSpeedY = movementY;
else
this.mouseSpeedY = 0.F;
} else { } else {
this.mouseSpeedX = 0.F; this.mouseSpeedX = 0.f;
this.mouseSpeedY = 0.F; this.mouseSpeedY = 0.f;
} }
if (Math.abs(this.mouseSpeedX) >= .05F || Math.abs(this.mouseSpeedY) >= .05F) { if (Math.abs(this.mouseSpeedX) >= .05f || Math.abs(this.mouseSpeedY) >= .05f) {
InputManager.queueMoveMousePosition(this.mouseSpeedX * this.config.getMouseSpeed(), this.mouseSpeedY * this.config.getMouseSpeed()); InputManager.queueMoveMousePosition(
this.mouseSpeedX * this.config.getMouseSpeed(),
this.mouseSpeedY * this.config.getMouseSpeed()
);
} }
this.moveMouseToClosestSlot(client, client.currentScreen); this.moveMouseToClosestSlot(client, client.currentScreen);
@@ -590,19 +594,23 @@ public class LambdaInput
} }
} }
private boolean handleAButton(@NotNull Screen screen, @NotNull Element focused) private boolean handleAButton(@NotNull Screen screen, @NotNull Element focused) {
{
if (focused instanceof AbstractPressableButtonWidget) { if (focused instanceof AbstractPressableButtonWidget) {
AbstractPressableButtonWidget widget = (AbstractPressableButtonWidget) focused; AbstractPressableButtonWidget widget = (AbstractPressableButtonWidget) focused;
widget.playDownSound(MinecraftClient.getInstance().getSoundManager()); widget.playDownSound(MinecraftClient.getInstance().getSoundManager());
widget.onPress(); widget.onPress();
return true; return true;
} else if (focused instanceof AbstractSprucePressableButtonWidget) {
AbstractSprucePressableButtonWidget widget = (AbstractSprucePressableButtonWidget) focused;
widget.playDownSound();
widget.onPress();
return true;
} else if (focused instanceof SpruceLabelWidget) { } else if (focused instanceof SpruceLabelWidget) {
((SpruceLabelWidget) focused).onPress(); ((SpruceLabelWidget) focused).onPress();
return true; return true;
} else if (focused instanceof WorldListWidget) { } else if (focused instanceof WorldListWidget) {
WorldListWidget list = (WorldListWidget) focused; WorldListWidget list = (WorldListWidget) focused;
list.method_20159().ifPresent(WorldListWidget.Entry::play); list.getSelectedAsOptional().ifPresent(WorldListWidget.Entry::play);
return true; return true;
} else if (focused instanceof MultiplayerServerListWidget) { } else if (focused instanceof MultiplayerServerListWidget) {
MultiplayerServerListWidget list = (MultiplayerServerListWidget) focused; MultiplayerServerListWidget list = (MultiplayerServerListWidget) focused;
@@ -611,6 +619,10 @@ public class LambdaInput
((MultiplayerScreen) screen).select(entry); ((MultiplayerScreen) screen).select(entry);
((MultiplayerScreen) screen).connect(); ((MultiplayerScreen) screen).connect();
} }
} else if (focused instanceof SpruceParentWidget) {
Element childFocused = ((SpruceParentWidget<?>) focused).getFocused();
if (childFocused != null)
return this.handleAButton(screen, childFocused);
} else if (focused instanceof ParentElement) { } else if (focused instanceof ParentElement) {
Element childFocused = ((ParentElement) focused).getFocused(); Element childFocused = ((ParentElement) focused).getFocused();
if (childFocused != null) if (childFocused != null)
@@ -625,24 +637,32 @@ public class LambdaInput
* @param screen The current screen. * @param screen The current screen.
* @param right True if the right button is pressed, else false. * @param right True if the right button is pressed, else false.
*/ */
private boolean handleLeftRight(@NotNull Screen screen, boolean right) private boolean handleLeftRight(@NotNull Screen screen, boolean right) {
{ if (screen instanceof SpruceScreen) {
((SpruceScreen) screen).onNavigation(right ? NavigationDirection.RIGHT : NavigationDirection.LEFT, false);
this.actionGuiCooldown = 5;
return false;
}
Element focused = screen.getFocused(); Element focused = screen.getFocused();
if (focused != null) if (focused != null)
if (this.handleRightLeftElement(focused, right)) if (this.handleRightLeftElement(focused, right))
return this.changeFocus(screen, right); return this.changeFocus(screen, right ? NavigationDirection.RIGHT : NavigationDirection.LEFT);
return true; return true;
} }
private boolean handleRightLeftElement(@NotNull Element element, boolean right) private boolean handleRightLeftElement(@NotNull Element element, boolean right) {
{ if (element instanceof SpruceElement) {
if (((SpruceElement) element).requiresCursor())
return true;
return !((SpruceElement) element).onNavigation(right ? NavigationDirection.RIGHT : NavigationDirection.LEFT, false);
}
if (element instanceof SliderWidget) { if (element instanceof SliderWidget) {
SliderWidget slider = (SliderWidget) element; SliderWidget slider = (SliderWidget) element;
slider.keyPressed(right ? 262 : 263, 0, 0); slider.keyPressed(right ? 262 : 263, 0, 0);
this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks. this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks.
return false; return false;
} else if (element instanceof AlwaysSelectedEntryListWidget) { } else if (element instanceof AlwaysSelectedEntryListWidget) {
((EntryListWidgetAccessor) element).lambdacontrols_moveSelection(right ? EntryListWidget.MoveDirection.UP : EntryListWidget.MoveDirection.DOWN); ((EntryListWidgetAccessor) element).lambdacontrols$moveSelection(right ? EntryListWidget.MoveDirection.UP : EntryListWidget.MoveDirection.DOWN);
return false; return false;
} else if (element instanceof ParentElement) { } else if (element instanceof ParentElement) {
ParentElement entryList = (ParentElement) element; ParentElement entryList = (ParentElement) element;
@@ -662,32 +682,36 @@ public class LambdaInput
* @param value The value of the look. * @param value The value of the look.
* @param state The state. * @param state The state.
*/ */
public void handleLook(@NotNull MinecraftClient client, int axis, float value, int state) public void handleLook(@NotNull MinecraftClient client, int axis, float value, int state) {
{
// Handles the look direction. // Handles the look direction.
if (client.player != null) { if (client.player != null) {
double powValue = Math.pow(value, 2.0); double powValue = Math.pow(value, 2.0);
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) { if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) {
if (state == 2) { if (state == 2) {
this.targetPitch = -this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; this.targetPitch = -this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.11D;
} else if (state == 1) { } else if (state == 1) {
this.targetPitch = this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; this.targetPitch = this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.11D;
} }
} }
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_X) { if (axis == GLFW_GAMEPAD_AXIS_RIGHT_X) {
if (state == 2) { if (state == 2) {
this.targetYaw = -this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; this.targetYaw = -this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.11D;
} else if (state == 1) { } else if (state == 1) {
this.targetYaw = this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; this.targetYaw = this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.11D;
} }
} }
} }
} }
private boolean changeFocus(@NotNull Screen screen, boolean down) private boolean changeFocus(@NotNull Screen screen, NavigationDirection direction) {
{ if (screen instanceof SpruceScreen) {
if (!screen.changeFocus(down)) { if (((SpruceScreen) screen).onNavigation(direction, false)) {
if (screen.changeFocus(down)) { this.actionGuiCooldown = 5;
}
return false;
}
if (!screen.changeFocus(direction.isLookingForward())) {
if (screen.changeFocus(direction.isLookingForward())) {
this.actionGuiCooldown = 5; this.actionGuiCooldown = 5;
return false; return false;
} }
@@ -698,14 +722,14 @@ public class LambdaInput
} }
} }
public static boolean isScreenInteractive(@NotNull Screen screen) public static boolean isScreenInteractive(@NotNull Screen screen) {
{ return !(screen instanceof AdvancementsScreen || screen instanceof HandledScreen || screen instanceof PackScreen
return !(screen instanceof AdvancementsScreen || screen instanceof HandledScreen || screen instanceof ResourcePackScreen || LambdaControlsCompat.requireMouseOnScreen(screen)); || (screen instanceof SpruceScreen && ((SpruceScreen) screen).requiresCursor())
|| LambdaControlsCompat.requireMouseOnScreen(screen));
} }
// Inspired from https://github.com/MrCrayfish/Controllable/blob/1.14.X/src/main/java/com/mrcrayfish/controllable/client/ControllerInput.java#L686. // Inspired from https://github.com/MrCrayfish/Controllable/blob/1.14.X/src/main/java/com/mrcrayfish/controllable/client/ControllerInput.java#L686.
private void moveMouseToClosestSlot(@NotNull MinecraftClient client, @Nullable Screen screen) private void moveMouseToClosestSlot(@NotNull MinecraftClient client, @Nullable Screen screen) {
{
// Makes the mouse attracted to slots. This helps with selecting items when using a controller. // Makes the mouse attracted to slots. This helps with selecting items when using a controller.
if (screen instanceof HandledScreen) { if (screen instanceof HandledScreen) {
HandledScreen inventoryScreen = (HandledScreen) screen; HandledScreen inventoryScreen = (HandledScreen) screen;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,9 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import me.lambdaurora.lambdacontrols.LambdaControlsFeature; import dev.lambdaurora.lambdacontrols.LambdaControlsFeature;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock; import net.minecraft.block.FluidBlock;
@@ -23,26 +23,25 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RayTraceContext; import net.minecraft.world.RaycastContext;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
* Represents the reacharound API of LambdaControls. * Represents the reach-around API of LambdaControls.
* *
* @version 1.3.2 * @version 1.5.0
* @since 1.3.2 * @since 1.3.2
*/ */
public class LambdaReacharound public class LambdaReacharound {
{
private BlockHitResult lastReacharoundResult = null; private BlockHitResult lastReacharoundResult = null;
private boolean lastReacharoundVertical = false; private boolean lastReacharoundVertical = false;
private boolean onSlab = false;
public void tick(@NotNull MinecraftClient client) public void tick(@NotNull MinecraftClient client) {
{
this.lastReacharoundResult = this.tryVerticalReachAround(client); this.lastReacharoundResult = this.tryVerticalReachAround(client);
if (this.lastReacharoundResult == null) { if (this.lastReacharoundResult == null) {
this.lastReacharoundResult = this.tryFrontPlace(client); this.lastReacharoundResult = this.tryHorizontalReachAround(client);
this.lastReacharoundVertical = false; this.lastReacharoundVertical = false;
} else this.lastReacharoundVertical = true; } else this.lastReacharoundVertical = true;
} }
@@ -52,8 +51,7 @@ public class LambdaReacharound
* *
* @return The last reach around result. * @return The last reach around result.
*/ */
public @Nullable BlockHitResult getLastReacharoundResult() public @Nullable BlockHitResult getLastReacharoundResult() {
{
return this.lastReacharoundResult; return this.lastReacharoundResult;
} }
@@ -62,8 +60,7 @@ public class LambdaReacharound
* *
* @return True if the reach around is vertical. * @return True if the reach around is vertical.
*/ */
public boolean isLastReacharoundVertical() public boolean isLastReacharoundVertical() {
{
return this.lastReacharoundVertical; return this.lastReacharoundVertical;
} }
@@ -72,24 +69,21 @@ public class LambdaReacharound
* *
* @return True if reacharound is available, else false. * @return True if reacharound is available, else false.
*/ */
public boolean isReacharoundAvailable() public boolean isReacharoundAvailable() {
{ return LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable() || LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable();
return LambdaControlsFeature.FRONT_BLOCK_PLACING.isAvailable() || LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable();
} }
private float getPlayerRange(@NotNull MinecraftClient client) private float getPlayerRange(@NotNull MinecraftClient client) {
{
return client.interactionManager != null ? client.interactionManager.getReachDistance() : 0.f; return client.interactionManager != null ? client.interactionManager.getReachDistance() : 0.f;
} }
/** /**
* Returns a nullable block hit result if vertical reacharound is possible. * Returns a nullable block hit result if vertical reach-around is possible.
* *
* @param client The client instance. * @param client The client instance.
* @return A block hit result if vertical reacharound is possible, else null. * @return A block hit result if vertical reach-around is possible, else null.
*/ */
public @Nullable BlockHitResult tryVerticalReachAround(@NotNull MinecraftClient client) public @Nullable BlockHitResult tryVerticalReachAround(@NotNull MinecraftClient client) {
{
if (!LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable()) if (!LambdaControlsFeature.VERTICAL_REACHAROUND.isAvailable())
return null; return null;
if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.MISS if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.MISS
@@ -101,7 +95,7 @@ public class LambdaReacharound
Vec3d rotationVec = client.player.getRotationVec(1.0F); Vec3d rotationVec = client.player.getRotationVec(1.0F);
float range = getPlayerRange(client); float range = getPlayerRange(client);
Vec3d rayVec = pos.add(rotationVec.x * range, rotationVec.y * range, rotationVec.z * range).add(0, 0.75, 0); Vec3d rayVec = pos.add(rotationVec.x * range, rotationVec.y * range, rotationVec.z * range).add(0, 0.75, 0);
BlockHitResult result = client.world.rayTrace(new RayTraceContext(pos, rayVec, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, client.player)); BlockHitResult result = client.world.raycast(new RaycastContext(pos, rayVec, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, client.player));
if (result.getType() == HitResult.Type.BLOCK) { if (result.getType() == HitResult.Type.BLOCK) {
BlockPos blockPos = result.getBlockPos().down(); BlockPos blockPos = result.getBlockPos().down();
@@ -116,19 +110,25 @@ public class LambdaReacharound
} }
/** /**
* Returns a nullable block hit result if front placing is possible. * Returns a nullable block hit result if horizontal reach-around is possible.
* *
* @param client The client instance. * @param client The client instance.
* @return A block hit result if front placing is possible. * @return A block hit result if horizontal reach-around is possible.
*/ */
public @Nullable BlockHitResult tryFrontPlace(@NotNull MinecraftClient client) public @Nullable BlockHitResult tryHorizontalReachAround(@NotNull MinecraftClient client) {
{ if (!LambdaControlsFeature.HORIZONTAL_REACHAROUND.isAvailable())
if (!LambdaControlsFeature.FRONT_BLOCK_PLACING.isAvailable())
return null; return null;
if (client.player != null && client.crosshairTarget != null && client.crosshairTarget.getType() == HitResult.Type.MISS && client.player.isOnGround() && client.player.pitch > 35.0F) { if (client.player != null && client.crosshairTarget != null && client.crosshairTarget.getType() == HitResult.Type.MISS && client.player.isOnGround() && client.player.pitch > 35.0F) {
if (client.player.isRiding()) if (client.player.isRiding())
return null; return null;
BlockPos playerPos = client.player.getBlockPos().down(); BlockPos playerPos = client.player.getBlockPos().down();
if (client.player.getY() - playerPos.getY() - 1.0 >= 0.25) {
playerPos = playerPos.up();
this.onSlab = true;
} else {
this.onSlab = false;
}
BlockPos targetPos = new BlockPos(client.crosshairTarget.getPos()).subtract(playerPos); BlockPos targetPos = new BlockPos(client.crosshairTarget.getPos()).subtract(playerPos);
BlockPos vector = new BlockPos(MathHelper.clamp(targetPos.getX(), -1, 1), 0, MathHelper.clamp(targetPos.getZ(), -1, 1)); BlockPos vector = new BlockPos(MathHelper.clamp(targetPos.getX(), -1, 1), 0, MathHelper.clamp(targetPos.getZ(), -1, 1));
BlockPos blockPos = playerPos.add(vector); BlockPos blockPos = playerPos.add(vector);
@@ -148,17 +148,17 @@ public class LambdaReacharound
return null; return null;
} }
public static @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @Nullable ItemStack stack) public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @Nullable ItemStack stack) {
{
if (stack == null || stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) if (stack == null || stack.isEmpty() || !(stack.getItem() instanceof BlockItem))
return result; return result;
return withSideForReacharound(result, Block.getBlockFromItem(stack.getItem())); return withSideForReacharound(result, Block.getBlockFromItem(stack.getItem()));
} }
public static @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @NotNull Block block) public @NotNull BlockHitResult withSideForReacharound(@NotNull BlockHitResult result, @NotNull Block block) {
{ if (block instanceof SlabBlock) {
if (block instanceof SlabBlock) if (this.onSlab) result = result.withSide(Direction.UP);
result = result.withSide(Direction.DOWN); else result = result.withSide(Direction.DOWN);
}
return result; return result;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client; package dev.lambdaurora.lambdacontrols.client;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@@ -23,8 +23,7 @@ import java.util.Optional;
* @version 1.4.0 * @version 1.4.0
* @since 1.2.0 * @since 1.2.0
*/ */
public enum VirtualMouseSkin implements Nameable public enum VirtualMouseSkin implements Nameable {
{
DEFAULT_LIGHT("default_light"), DEFAULT_LIGHT("default_light"),
DEFAULT_DARK("default_dark"), DEFAULT_DARK("default_dark"),
SECOND_LIGHT("second_light"), SECOND_LIGHT("second_light"),
@@ -33,8 +32,7 @@ public enum VirtualMouseSkin implements Nameable
private final String name; private final String name;
private final Text text; private final Text text;
VirtualMouseSkin(String name) VirtualMouseSkin(String name) {
{
this.name = name; this.name = name;
this.text = new TranslatableText(this.getTranslationKey()); this.text = new TranslatableText(this.getTranslationKey());
} }
@@ -44,8 +42,7 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The next available virtual mouse skin. * @return The next available virtual mouse skin.
*/ */
public @NotNull VirtualMouseSkin next() public @NotNull VirtualMouseSkin next() {
{
VirtualMouseSkin[] v = values(); VirtualMouseSkin[] v = values();
if (v.length == this.ordinal() + 1) if (v.length == this.ordinal() + 1)
return v[0]; return v[0];
@@ -57,8 +54,7 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The virtual mouse skin's translation key. * @return The virtual mouse skin's translation key.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.virtual_mouse.skin." + this.getName(); return "lambdacontrols.virtual_mouse.skin." + this.getName();
} }
@@ -67,14 +63,12 @@ public enum VirtualMouseSkin implements Nameable
* *
* @return The translated text of this virtual mouse skin. * @return The translated text of this virtual mouse skin.
*/ */
public @NotNull Text getTranslatedText() public @NotNull Text getTranslatedText() {
{
return this.text; return this.text;
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.name; return this.name;
} }
@@ -84,8 +78,7 @@ public enum VirtualMouseSkin implements Nameable
* @param id The identifier of the virtual mouse skin. * @param id The identifier of the virtual mouse skin.
* @return The virtual mouse skin if found, else empty. * @return The virtual mouse skin if found, else empty.
*/ */
public static @NotNull Optional<VirtualMouseSkin> byId(@NotNull String id) public static @NotNull Optional<VirtualMouseSkin> byId(@NotNull String id) {
{
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,14 +7,15 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat; package dev.lambdaurora.lambdacontrols.client.compat;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -22,11 +23,10 @@ import org.jetbrains.annotations.Nullable;
* Represents a compatibility handler for a mod. * Represents a compatibility handler for a mod.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.2 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public interface CompatHandler public interface CompatHandler {
{
/** /**
* Handles compatibility of a mod. * Handles compatibility of a mod.
* *
@@ -40,11 +40,23 @@ public interface CompatHandler
* @param screen The screen. * @param screen The screen.
* @return True if the mouse is required on the specified screen, else false. * @return True if the mouse is required on the specified screen, else false.
*/ */
default boolean requireMouseOnScreen(Screen screen) default boolean requireMouseOnScreen(Screen screen) {
{
return false; return false;
} }
/**
* Returns a slot at the specified location if possible.
*
* @param screen The screen.
* @param mouseX The mouse X-coordinate.
* @param mouseY The mouse Y-coordinate.
* @return A slot if present, else null.
* @since 1.5.0
*/
default @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
return null;
}
/** /**
* Returns whether the current slot is a creative slot or not. * Returns whether the current slot is a creative slot or not.
* *
@@ -52,8 +64,7 @@ public interface CompatHandler
* @param slot The slot to check. * @param slot The slot to check.
* @return True if the slot is a creative slot, else false. * @return True if the slot is a creative slot, else false.
*/ */
default boolean isCreativeSlot(@NotNull HandledScreen screen, @NotNull Slot slot) default boolean isCreativeSlot(@NotNull HandledScreen screen, @NotNull Slot slot) {
{
return false; return false;
} }
@@ -64,8 +75,7 @@ public interface CompatHandler
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
default String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) default String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
return null; return null;
} }
@@ -76,8 +86,7 @@ public interface CompatHandler
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
default String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) default String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
return null; return null;
} }
@@ -88,8 +97,7 @@ public interface CompatHandler
* @param screen The screen. * @param screen The screen.
* @return True if the handle was fired and succeed, else false. * @return True if the handle was fired and succeed, else false.
*/ */
default boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) default boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
return false; return false;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,9 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat; package dev.lambdaurora.lambdacontrols.client.compat;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import org.aperlambda.lambdacommon.utils.LambdaReflection; import org.aperlambda.lambdacommon.utils.LambdaReflection;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -25,20 +25,17 @@ import java.util.Optional;
* @version 1.3.2 * @version 1.3.2
* @since 1.3.2 * @since 1.3.2
*/ */
public class HQMCompat implements CompatHandler public class HQMCompat implements CompatHandler {
{
public static final String GUI_BASE_CLASS_PATH = "hardcorequesting.client.interfaces.GuiBase"; public static final String GUI_BASE_CLASS_PATH = "hardcorequesting.client.interfaces.GuiBase";
private Optional<Class<?>> guiBaseClass; private Optional<Class<?>> guiBaseClass;
@Override @Override
public void handle(@NotNull LambdaControlsClient mod) public void handle(@NotNull LambdaControlsClient mod) {
{
this.guiBaseClass = LambdaReflection.getClass(GUI_BASE_CLASS_PATH); this.guiBaseClass = LambdaReflection.getClass(GUI_BASE_CLASS_PATH);
} }
@Override @Override
public boolean requireMouseOnScreen(Screen screen) public boolean requireMouseOnScreen(Screen screen) {
{
return this.guiBaseClass.map(clazz -> clazz.isInstance(screen)).orElse(false); return this.guiBaseClass.map(clazz -> clazz.isInstance(screen)).orElse(false);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,15 +7,16 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat; package dev.lambdaurora.lambdacontrols.client.compat;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.controller.InputManager; import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import org.aperlambda.lambdacommon.utils.LambdaReflection; import org.aperlambda.lambdacommon.utils.LambdaReflection;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -27,11 +28,10 @@ import java.util.stream.Stream;
* Represents a compatibility handler. * Represents a compatibility handler.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.2 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class LambdaControlsCompat public class LambdaControlsCompat {
{
private static final List<CompatHandler> HANDLERS = new ArrayList<>(); private static final List<CompatHandler> HANDLERS = new ArrayList<>();
/** /**
@@ -39,8 +39,7 @@ public class LambdaControlsCompat
* *
* @param mod The mod instance. * @param mod The mod instance.
*/ */
public static void init(@NotNull LambdaControlsClient mod) public static void init(@NotNull LambdaControlsClient mod) {
{
if (FabricLoader.getInstance().isModLoaded("okzoomer")) { if (FabricLoader.getInstance().isModLoaded("okzoomer")) {
mod.log("Adding okzoomer compatibility..."); mod.log("Adding okzoomer compatibility...");
HANDLERS.add(new OkZoomerCompat()); HANDLERS.add(new OkZoomerCompat());
@@ -62,8 +61,7 @@ public class LambdaControlsCompat
* *
* @param handler The compatibility handler to register. * @param handler The compatibility handler to register.
*/ */
public static void registerCompatHandler(@NotNull CompatHandler handler) public static void registerCompatHandler(@NotNull CompatHandler handler) {
{
HANDLERS.add(handler); HANDLERS.add(handler);
} }
@@ -72,8 +70,7 @@ public class LambdaControlsCompat
* *
* @return A stream of compatibility handlers. * @return A stream of compatibility handlers.
*/ */
public static Stream<CompatHandler> streamCompatHandlers() public static Stream<CompatHandler> streamCompatHandlers() {
{
return HANDLERS.stream(); return HANDLERS.stream();
} }
@@ -83,11 +80,27 @@ public class LambdaControlsCompat
* @param screen The screen. * @param screen The screen.
* @return True if the mouse is requried on the specified screen, else false. * @return True if the mouse is requried on the specified screen, else false.
*/ */
public static boolean requireMouseOnScreen(Screen screen) public static boolean requireMouseOnScreen(Screen screen) {
{
return HANDLERS.stream().anyMatch(handler -> handler.requireMouseOnScreen(screen)); return HANDLERS.stream().anyMatch(handler -> handler.requireMouseOnScreen(screen));
} }
/**
* Returns a slot at the specified location if possible.
*
* @param screen The screen.
* @param mouseX The mouse X-coordinate.
* @param mouseY The mouse Y-coordinate.
* @return A slot if present, else null.
*/
public static @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
for (CompatHandler handler : HANDLERS) {
Pair<Integer, Integer> slot = handler.getSlotAt(screen, mouseX, mouseY);
if (slot != null)
return slot;
}
return null;
}
/** /**
* Returns a custom translation key to make custom attack action strings on the HUD. * Returns a custom translation key to make custom attack action strings on the HUD.
* *
@@ -95,8 +108,7 @@ public class LambdaControlsCompat
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
public static String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) public static String getAttackActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
String action = handler.getAttackActionAt(client, placeResult); String action = handler.getAttackActionAt(client, placeResult);
if (action != null) { if (action != null) {
@@ -113,8 +125,7 @@ public class LambdaControlsCompat
* @param placeResult The last place block result. * @param placeResult The last place block result.
* @return Null if untouched, else a translation key. * @return Null if untouched, else a translation key.
*/ */
public static String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) public static String getUseActionAt(@NotNull MinecraftClient client, @Nullable BlockHitResult placeResult) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
String action = handler.getUseActionAt(client, placeResult); String action = handler.getUseActionAt(client, placeResult);
if (action != null) { if (action != null) {
@@ -131,8 +142,7 @@ public class LambdaControlsCompat
* @param screen The screen. * @param screen The screen.
* @return True if the handle was fired and succeed, else false. * @return True if the handle was fired and succeed, else false.
*/ */
public static boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) public static boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
{
for (CompatHandler handler : HANDLERS) { for (CompatHandler handler : HANDLERS) {
if (handler.handleMenuBack(client, screen)) if (handler.handleMenuBack(client, screen))
return true; return true;
@@ -145,8 +155,7 @@ public class LambdaControlsCompat
* *
* @return True if Roughly Enough Items is present, else false. * @return True if Roughly Enough Items is present, else false.
*/ */
public static boolean isReiPresent() public static boolean isReiPresent() {
{
return FabricLoader.getInstance().isModLoaded("roughlyenoughitems"); return FabricLoader.getInstance().isModLoaded("roughlyenoughitems");
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,8 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat; package dev.lambdaurora.lambdacontrols.client.compat;
import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
@@ -21,54 +22,51 @@ import java.util.Set;
* This plugin is only present for the conditional mixins. * This plugin is only present for the conditional mixins.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.2.0 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
public class LambdaControlsMixinPlugin implements IMixinConfigPlugin public class LambdaControlsMixinPlugin implements IMixinConfigPlugin {
{
private final HashMap<String, Boolean> conditionalMixins = new HashMap<>(); private final HashMap<String, Boolean> conditionalMixins = new HashMap<>();
public LambdaControlsMixinPlugin() public LambdaControlsMixinPlugin() {
{ this.putConditionalMixin("EntryListWidgetAccessor", LambdaControlsCompat.isReiPresent());
this.conditionalMixins.put("me.lambdaurora.lambdacontrols.client.compat.mixin.RecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("EntryWidgetAccessor", LambdaControlsCompat.isReiPresent());
this.conditionalMixins.put("me.lambdaurora.lambdacontrols.client.compat.mixin.VillagerRecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent()); this.putConditionalMixin("RecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent());
this.putConditionalMixin("VillagerRecipeViewingScreenAccessor", LambdaControlsCompat.isReiPresent());
}
private void putConditionalMixin(@NotNull String path, boolean condition) {
this.conditionalMixins.put("me.lambdaurora.lambdacontrols.client.compat.mixin." + path, condition);
} }
@Override @Override
public void onLoad(String mixinPackage) public void onLoad(String mixinPackage) {
{
} }
@Override @Override
public String getRefMapperConfig() public String getRefMapperConfig() {
{
return null; return null;
} }
@Override @Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
{
return this.conditionalMixins.getOrDefault(mixinClassName, Boolean.TRUE); return this.conditionalMixins.getOrDefault(mixinClassName, Boolean.TRUE);
} }
@Override @Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
{
} }
@Override @Override
public List<String> getMixins() public List<String> getMixins() {
{
return null; return null;
} }
@Override @Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
{
} }
@Override @Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
{
} }
} }

View File

@@ -0,0 +1,59 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.compat;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import io.github.joaoh1.okzoomer.client.keybinds.ZoomKeybinds;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
/**
* Represents a compatibility handler for OkZoomer.
*
* @author LambdAurora
* @version 1.4.3
* @since 1.1.0
*/
public class OkZoomerCompat implements CompatHandler {
@Override
public void handle(@NotNull LambdaControlsClient mod) {
new ButtonBinding.Builder("zoom")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X)
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.zoomKey)
.register();
if (ZoomKeybinds.areExtraKeybindsEnabled()) {
new ButtonBinding.Builder("zoom_in")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.increaseZoomKey)
.register();
new ButtonBinding.Builder("zoom_out")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.decreaseZoomKey)
.register();
new ButtonBinding.Builder("zoom_reset")
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(ZoomKeybinds.resetZoomKey)
.register();
}
}
}

View File

@@ -0,0 +1,360 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.compat;
import dev.lambdaurora.lambdacontrols.client.ButtonState;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.compat.mixin.EntryListWidgetAccessor;
import dev.lambdaurora.lambdacontrols.client.compat.mixin.EntryWidgetAccessor;
import dev.lambdaurora.lambdacontrols.client.compat.mixin.RecipeViewingScreenAccessor;
import dev.lambdaurora.lambdacontrols.client.compat.mixin.VillagerRecipeViewingScreenAccessor;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.InputHandlers;
import dev.lambdaurora.lambdacontrols.client.controller.PressAction;
import me.shedaniel.rei.api.*;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.PreRecipeViewingScreen;
import me.shedaniel.rei.gui.RecipeViewingScreen;
import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
import me.shedaniel.rei.gui.widget.EntryListEntryWidget;
import me.shedaniel.rei.gui.widget.EntryListWidget;
import me.shedaniel.rei.gui.widget.EntryWidget;
import me.shedaniel.rei.gui.widget.WidgetWithBounds;
import me.shedaniel.rei.impl.ScreenHelper;
import me.shedaniel.rei.impl.widgets.ButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Identifier;
import org.aperlambda.lambdacommon.utils.LambdaReflection;
import org.aperlambda.lambdacommon.utils.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
import static org.lwjgl.glfw.GLFW.*;
/**
* Represents a compatibility handler for REI.
*
* @author LambdAurora
* @version 1.5.0
* @since 1.2.0
*/
public class ReiCompat implements CompatHandler {
private static final Pair<Integer, Integer> INVALID_SLOT = new Pair<>(-1, -1);
private static EntryListWidget ENTRY_LIST_WIDGET;
@Override
public void handle(@NotNull LambdaControlsClient mod) {
ButtonBinding.builder(new Identifier("rei", "category_back"))
.buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleTab(false))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "category_next"))
.buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleTab(true))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "page_back"))
.buttons(ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_X, false))
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handlePage(false))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "page_next"))
.buttons(ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_X, true))
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handlePage(true))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "recipe_back"))
.buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleRecipe(false))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "recipe_next"))
.buttons(GLFW_GAMEPAD_BUTTON_DPAD_DOWN)
.filter((client, binding) -> isViewingScreen(client.currentScreen))
.action(handleRecipe(true))
.cooldown(true)
.register();
// For some reasons this is broken.
ButtonBinding.builder(new Identifier("rei", "show_usage"))
.buttons(GLFW_GAMEPAD_BUTTON_RIGHT_THUMB)
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handleShowRecipeUsage(true))
.cooldown(true)
.register();
ButtonBinding.builder(new Identifier("rei", "show_recipe"))
.buttons(GLFW_GAMEPAD_BUTTON_LEFT_THUMB)
.filter((client, binding) -> InputHandlers.inInventory(client, binding) || isViewingScreen(client.currentScreen))
.action(handleShowRecipeUsage(false))
.cooldown(true)
.register();
}
@Override
public boolean requireMouseOnScreen(Screen screen) {
return isViewingScreen(screen) || screen instanceof PreRecipeViewingScreen;
}
@Override
public @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Screen screen, int mouseX, int mouseY) {
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (overlay.isPresent() && overlay.get().isInside(mouseX, mouseY)) {
EntryListWidget widget = getEntryListWidget();
if (widget == null)
return null;
Pair<Integer, Integer> slot = this.getSlotAt(widget, mouseX, mouseY, false);
if (slot != null && slot != INVALID_SLOT)
return slot;
} else if (isViewingScreen(screen)) {
for (Element element : screen.children()) {
Pair<Integer, Integer> slot = this.getSlotAt(element, mouseX, mouseY, true);
if (slot != null && slot != INVALID_SLOT)
return slot;
}
}
return null;
}
private @Nullable Pair<Integer, Integer> getSlotAt(@NotNull Element element, int mouseX, int mouseY, boolean allowEmpty) {
if (element instanceof EntryWidget) {
EntryWidget entry = (EntryWidget) element;
if (entry.containsMouse(mouseX, mouseY)) {
if (!allowEmpty && entry.entries().isEmpty())
return INVALID_SLOT;
return Pair.of(entry.getBounds().getX() + 1, entry.getBounds().getY() + 1);
}
} else if (element instanceof EntryListWidget) {
List<EntryListEntryWidget> entries = ((EntryListWidgetAccessor) element).getEntries();
for (EntryListEntryWidget entry : entries) {
Pair<Integer, Integer> slot = this.getSlotAt(entry, mouseX, mouseY, allowEmpty);
if (slot != null && slot != INVALID_SLOT)
return slot;
}
} else if (!(element instanceof ButtonWidget) && element instanceof WidgetWithBounds) {
for (Element child : ((WidgetWithBounds) element).children()) {
Pair<Integer, Integer> slot = this.getSlotAt(child, mouseX, mouseY, allowEmpty);
if (slot != null && slot != INVALID_SLOT)
return slot;
}
}
return null;
}
private static boolean isViewingScreen(Screen screen) {
return screen instanceof RecipeViewingScreen || screen instanceof VillagerRecipeViewingScreen;
}
@Override
public boolean handleMenuBack(@NotNull MinecraftClient client, @NotNull Screen screen) {
if (!isViewingScreen(screen))
return false;
MinecraftClient.getInstance().openScreen(REIHelper.getInstance().getPreviousContainerScreen());
ScreenHelper.getLastOverlay().init();
return true;
}
private static EntryListWidget getEntryListWidget() {
if (ENTRY_LIST_WIDGET == null) {
ENTRY_LIST_WIDGET = LambdaReflection.getFirstFieldOfType(ContainerScreenOverlay.class, EntryListWidget.class)
.map(field -> (EntryListWidget) LambdaReflection.getFieldValue(null, field))
.orElse(null);
}
return ENTRY_LIST_WIDGET;
}
private static @Nullable EntryStack getCurrentStack(@NotNull MinecraftClient client) {
double x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
double y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
if (isViewingScreen(client.currentScreen)) {
for (Element element : client.currentScreen.children()) {
EntryStack stack = getCurrentStack(element, x, y);
if (stack != null)
return stack;
}
}
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (!overlay.isPresent())
return RecipeHelper.getInstance().getScreenFocusedStack(client.currentScreen);
EntryListWidget widget = getEntryListWidget();
if (widget == null)
return RecipeHelper.getInstance().getScreenFocusedStack(client.currentScreen);
return getCurrentStack(widget, x, y);
}
private static @Nullable EntryStack getCurrentStack(@NotNull Element element, double mouseX, double mouseY) {
if (element instanceof EntryWidget) {
EntryWidget entry = (EntryWidget) element;
if (entry.containsMouse(mouseX, mouseY))
return ((EntryWidgetAccessor) entry).lambdacontrols_getCurrentEntry();
} else if (element instanceof EntryListWidget) {
List<EntryListEntryWidget> entries = ((EntryListWidgetAccessor) element).getEntries();
for (EntryListEntryWidget entry : entries) {
if (entry.containsMouse(mouseX, mouseY)) {
return ((EntryWidgetAccessor) entry).lambdacontrols_getCurrentEntry();
}
}
} else if (!(element instanceof ButtonWidget) && element instanceof WidgetWithBounds) {
for (Element child : ((WidgetWithBounds) element).children()) {
EntryStack stack = getCurrentStack(child, mouseX, mouseY);
if (stack != null)
return stack;
}
}
return null;
}
private static PressAction handleShowRecipeUsage(boolean usage) {
return (client, button, value, action) -> {
if (action.isUnpressed())
return false;
EntryStack stack = RecipeHelper.getInstance().getScreenFocusedStack(client.currentScreen);
if (stack == null) {
stack = getCurrentStack(client);
}
if (stack != null && !stack.isEmpty()) {
stack = stack.copy();
if (usage) {
return ClientHelper.getInstance().openView(ClientHelper.ViewSearchBuilder.builder().addUsagesFor(stack).setInputNotice(stack).fillPreferredOpenedCategory());
} else {
return ClientHelper.getInstance().openView(ClientHelper.ViewSearchBuilder.builder().addRecipesFor(stack).setOutputNotice(stack).fillPreferredOpenedCategory());
}
}
return false;
};
}
private static PressAction handlePage(boolean next) {
return (client, button, value, action) -> {
if (action == ButtonState.RELEASE)
return false;
Optional<ContainerScreenOverlay> overlay = ScreenHelper.getOptionalOverlay();
if (!overlay.isPresent())
return false;
EntryListWidget widget = getEntryListWidget();
if (widget == null)
return false;
if (next)
widget.nextPage();
else
widget.previousPage();
widget.updateEntriesPosition();
return true;
};
}
/**
* Returns the handler for category tabs buttons.
*
* @param next True if the action is to switch to the next tab.
* @return The handler.
*/
private static PressAction handleTab(boolean next) {
return (client, button, value, action) -> {
if (action != ButtonState.RELEASE)
return false;
if (client.currentScreen instanceof RecipeViewingScreen) {
RecipeViewingScreenAccessor screen = (RecipeViewingScreenAccessor) client.currentScreen;
if (next)
screen.getCategoryNext().onClick();
else
screen.getCategoryBack().onClick();
return true;
} else if (client.currentScreen instanceof VillagerRecipeViewingScreen) {
VillagerRecipeViewingScreenAccessor screen = (VillagerRecipeViewingScreenAccessor) client.currentScreen;
List<RecipeCategory<?>> categories = screen.getCategories();
int currentTab = screen.getSelectedCategoryIndex();
screen.setSelectedCategoryIndex(getNextIndex(currentTab, categories.size(), next));
screen.setSelectedRecipeIndex(0);
screen.lambdacontrols_init();
return true;
}
return false;
};
}
private static PressAction handleRecipe(boolean next) {
return (client, button, value, action) -> {
if (action.isUnpressed())
return false;
if (client.currentScreen instanceof RecipeViewingScreen) {
RecipeViewingScreenAccessor screen = (RecipeViewingScreenAccessor) client.currentScreen;
if (next)
screen.getRecipeNext().onClick();
else
screen.getRecipeBack().onClick();
return true;
} else if (client.currentScreen instanceof VillagerRecipeViewingScreen) {
VillagerRecipeViewingScreenAccessor screen = (VillagerRecipeViewingScreenAccessor) client.currentScreen;
List<RecipeCategory<?>> categories = screen.getCategories();
int currentTab = screen.getSelectedCategoryIndex();
List<RecipeDisplay> recipes = screen.getCategoryMap().get(categories.get(currentTab));
if (recipes.size() == 0)
return true;
int currentRecipe = screen.getSelectedRecipeIndex();
int nextRecipe = getNextIndex(currentRecipe, recipes.size(), next);
if (nextRecipe == 0) {
screen.getScrolling().scrollTo(0.0, true);
} else if (nextRecipe == recipes.size() - 1) {
screen.getScrolling().scrollTo(screen.getScrolling().getMaxScroll(), true);
} else {
double scrollAmount = screen.getScrolling().getMaxScroll() / (float) recipes.size();
screen.getScrolling().offset(next ? scrollAmount : -scrollAmount, true);
}
screen.setSelectedRecipeIndex(nextRecipe);
screen.lambdacontrols_init();
return true;
}
return false;
};
}
private static int getNextIndex(int currentIndex, int size, boolean next) {
int nextIndex = currentIndex + (next ? 1 : -1);
if (nextIndex < 0)
nextIndex = size - 1;
else if (nextIndex >= size)
nextIndex = 0;
return nextIndex;
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.compat.mixin;
import me.shedaniel.rei.gui.widget.EntryListEntryWidget;
import me.shedaniel.rei.gui.widget.EntryListWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
/**
* Represents an accessor to REI's EntryListWidget.
*
* @author LambdAurora
* @version 1.5.0
* @since 1.5.0
*/
@Mixin(value = EntryListWidget.class, remap = false)
public interface EntryListWidgetAccessor {
@Accessor(value = "entries")
List<EntryListEntryWidget> getEntries();
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.compat.mixin;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.gui.widget.EntryWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
/**
* Represents an accessor to REI's EntryWidget.
*
* @author LambdAurora
* @version 1.5.0
* @since 1.5.0
*/
@Mixin(value = EntryWidget.class, remap = false)
public interface EntryWidgetAccessor {
@Invoker("getCurrentEntry")
EntryStack lambdacontrols_getCurrentEntry();
}

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat.mixin; package dev.lambdaurora.lambdacontrols.client.compat.mixin;
import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Button;
import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen;
@@ -18,15 +18,20 @@ import org.spongepowered.asm.mixin.gen.Accessor;
* Represents an accessor to REI's RecipeViewingScreen. * Represents an accessor to REI's RecipeViewingScreen.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
@Mixin(value = RecipeViewingScreen.class, remap = false) @Mixin(value = RecipeViewingScreen.class, remap = false)
public interface RecipeViewingScreenAccessor public interface RecipeViewingScreenAccessor {
{
@Accessor("categoryBack") @Accessor("categoryBack")
Button getCategoryBack(); Button getCategoryBack();
@Accessor("categoryNext") @Accessor("categoryNext")
Button getCategoryNext(); Button getCategoryNext();
@Accessor("recipeBack")
Button getRecipeBack();
@Accessor("recipeNext")
Button getRecipeNext();
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,26 +7,31 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.compat.mixin; package dev.lambdaurora.lambdacontrols.client.compat.mixin;
import me.shedaniel.clothconfig2.api.ScrollingContainer;
import me.shedaniel.rei.api.RecipeCategory; import me.shedaniel.rei.api.RecipeCategory;
import me.shedaniel.rei.api.RecipeDisplay;
import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Represents an accessor to REI's VillagerRecipeViewingScreen. * Represents an accessor to REI's VillagerRecipeViewingScreen.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.1 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
@Mixin(VillagerRecipeViewingScreen.class) @Mixin(VillagerRecipeViewingScreen.class)
public interface VillagerRecipeViewingScreenAccessor public interface VillagerRecipeViewingScreenAccessor {
{ @Accessor(value = "categoryMap", remap = false)
Map<RecipeCategory<?>, List<RecipeDisplay>> getCategoryMap();
@Accessor(value = "categories", remap = false) @Accessor(value = "categories", remap = false)
List<RecipeCategory<?>> getCategories(); List<RecipeCategory<?>> getCategories();
@@ -36,6 +41,15 @@ public interface VillagerRecipeViewingScreenAccessor
@Accessor(value = "selectedCategoryIndex", remap = false) @Accessor(value = "selectedCategoryIndex", remap = false)
void setSelectedCategoryIndex(int selectedCategoryIndex); void setSelectedCategoryIndex(int selectedCategoryIndex);
@Accessor(value = "selectedRecipeIndex", remap = false)
int getSelectedRecipeIndex();
@Accessor(value = "selectedRecipeIndex", remap = false)
void setSelectedRecipeIndex(int selectedRecipeIndex);
@Accessor(value = "scrolling", remap = false)
ScrollingContainer getScrolling();
@Invoker("init") @Invoker("init")
void lambdacontrols_init(); void lambdacontrols_init();
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,9 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.client.ButtonState; import dev.lambdaurora.lambdacontrols.client.ButtonState;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.GameOptions; import net.minecraft.client.options.GameOptions;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
@@ -25,18 +25,16 @@ import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static me.lambdaurora.lambdacontrols.client.controller.InputManager.registerDefaultCategory;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
/** /**
* Represents a button binding. * Represents a button binding.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.5.0
* @since 1.0.0 * @since 1.0.0
*/ */
public class ButtonBinding implements Nameable public class ButtonBinding implements Nameable {
{
public static final ButtonCategory MOVEMENT_CATEGORY; public static final ButtonCategory MOVEMENT_CATEGORY;
public static final ButtonCategory GAMEPLAY_CATEGORY; public static final ButtonCategory GAMEPLAY_CATEGORY;
public static final ButtonCategory INVENTORY_CATEGORY; public static final ButtonCategory INVENTORY_CATEGORY;
@@ -46,48 +44,49 @@ public class ButtonBinding implements Nameable
public static final ButtonBinding ATTACK = new Builder("attack").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true)).onlyInGame().register(); public static final ButtonBinding ATTACK = new Builder("attack").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true)).onlyInGame().register();
public static final ButtonBinding BACK = new Builder("back").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, false)) public static final ButtonBinding BACK = new Builder("back").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, false))
.action(MovementHandler.HANDLER).onlyInGame().register(); .action(MovementHandler.HANDLER).onlyInGame().register();
public static final ButtonBinding CHAT = new Builder("chat").buttons(GLFW_GAMEPAD_BUTTON_DPAD_RIGHT).onlyInGame().cooldown(true).register(); public static final ButtonBinding CHAT = new Builder("chat").buttons(GLFW_GAMEPAD_BUTTON_DPAD_RIGHT).onlyInGame().cooldown().register();
public static final ButtonBinding DROP_ITEM = new Builder("drop_item").buttons(GLFW_GAMEPAD_BUTTON_B).onlyInGame().cooldown(true).register(); public static final ButtonBinding DROP_ITEM = new Builder("drop_item").buttons(GLFW_GAMEPAD_BUTTON_B).onlyInGame().cooldown().register();
public static final ButtonBinding FORWARD = new Builder("forward").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, true)) public static final ButtonBinding FORWARD = new Builder("forward").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_Y, true))
.action(MovementHandler.HANDLER).onlyInGame().register(); .action(MovementHandler.HANDLER).onlyInGame().register();
public static final ButtonBinding HOTBAR_LEFT = new Builder("hotbar_left").buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER) public static final ButtonBinding HOTBAR_LEFT = new Builder("hotbar_left").buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.action(InputHandlers.handleHotbar(false)).onlyInGame().cooldown(true).register(); .action(InputHandlers.handleHotbar(false)).onlyInGame().cooldown().register();
public static final ButtonBinding HOTBAR_RIGHT = new Builder("hotbar_right").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER) public static final ButtonBinding HOTBAR_RIGHT = new Builder("hotbar_right").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.action(InputHandlers.handleHotbar(true)).onlyInGame().cooldown(true).register(); .action(InputHandlers.handleHotbar(true)).onlyInGame().cooldown().register();
public static final ButtonBinding INVENTORY = new Builder("inventory").buttons(GLFW_GAMEPAD_BUTTON_Y).onlyInGame().cooldown(true).register(); public static final ButtonBinding INVENTORY = new Builder("inventory").buttons(GLFW_GAMEPAD_BUTTON_Y).onlyInGame().cooldown().register();
public static final ButtonBinding JUMP = new Builder("jump").buttons(GLFW_GAMEPAD_BUTTON_A).onlyInGame().register(); public static final ButtonBinding JUMP = new Builder("jump").buttons(GLFW_GAMEPAD_BUTTON_A).onlyInGame().register();
public static final ButtonBinding LEFT = new Builder("left").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, false)) public static final ButtonBinding LEFT = new Builder("left").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, false))
.action(MovementHandler.HANDLER).onlyInGame().register(); .action(MovementHandler.HANDLER).onlyInGame().register();
public static final ButtonBinding PAUSE_GAME = new Builder("pause_game").buttons(GLFW_GAMEPAD_BUTTON_START).action(InputHandlers::handlePauseGame).cooldown(true).register(); public static final ButtonBinding PAUSE_GAME = new Builder("pause_game").buttons(GLFW_GAMEPAD_BUTTON_START).action(InputHandlers::handlePauseGame).cooldown().register();
public static final ButtonBinding PICK_BLOCK = new Builder("pick_block").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT).onlyInGame().cooldown(true).register(); public static final ButtonBinding PICK_BLOCK = new Builder("pick_block").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT).onlyInGame().cooldown().register();
public static final ButtonBinding PLAYER_LIST = new Builder("player_list").buttons(GLFW_GAMEPAD_BUTTON_BACK).onlyInGame().register(); public static final ButtonBinding PLAYER_LIST = new Builder("player_list").buttons(GLFW_GAMEPAD_BUTTON_BACK).onlyInGame().register();
public static final ButtonBinding RIGHT = new Builder("right").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, true)) public static final ButtonBinding RIGHT = new Builder("right").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_X, true))
.action(MovementHandler.HANDLER).register(); .action(MovementHandler.HANDLER).onlyInGame().register();
public static final ButtonBinding SCREENSHOT = new Builder("screenshot").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_A) public static final ButtonBinding SCREENSHOT = new Builder("screenshot").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_A)
.action(InputHandlers::handleScreenshot).cooldown(true).register(); .action(InputHandlers::handleScreenshot).cooldown().register();
public static final ButtonBinding SLOT_DOWN = new Builder("slot_down").buttons(GLFW_GAMEPAD_BUTTON_DPAD_DOWN) public static final ButtonBinding SLOT_DOWN = new Builder("slot_down").buttons(GLFW_GAMEPAD_BUTTON_DPAD_DOWN)
.action(InputHandlers.handleInventorySlotPad(1)).onlyInInventory().cooldown(true).register(); .action(InputHandlers.handleInventorySlotPad(1)).onlyInInventory().cooldown().register();
public static final ButtonBinding SLOT_LEFT = new Builder("slot_left").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT) public static final ButtonBinding SLOT_LEFT = new Builder("slot_left").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT)
.action(InputHandlers.handleInventorySlotPad(3)).onlyInInventory().cooldown(true).register(); .action(InputHandlers.handleInventorySlotPad(3)).onlyInInventory().cooldown().register();
public static final ButtonBinding SLOT_RIGHT = new Builder("slot_right").buttons(GLFW_GAMEPAD_BUTTON_DPAD_RIGHT) public static final ButtonBinding SLOT_RIGHT = new Builder("slot_right").buttons(GLFW_GAMEPAD_BUTTON_DPAD_RIGHT)
.action(InputHandlers.handleInventorySlotPad(2)).onlyInInventory().cooldown(true).register(); .action(InputHandlers.handleInventorySlotPad(2)).onlyInInventory().cooldown().register();
public static final ButtonBinding SLOT_UP = new Builder("slot_up").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP) public static final ButtonBinding SLOT_UP = new Builder("slot_up").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP)
.action(InputHandlers.handleInventorySlotPad(0)).onlyInInventory().cooldown(true).register(); .action(InputHandlers.handleInventorySlotPad(0)).onlyInInventory().cooldown().register();
public static final ButtonBinding SMOOTH_CAMERA = new Builder("toggle_smooth_camera").cooldown(true).register(); public static final ButtonBinding SMOOTH_CAMERA = new Builder("toggle_smooth_camera").onlyInGame().cooldown().register();
public static final ButtonBinding SNEAK = new Builder("sneak").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_THUMB) public static final ButtonBinding SNEAK = new Builder("sneak").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_THUMB)
.actions(PressAction.DEFAULT_ACTION, InputHandlers::handleToggleSneak).onlyInGame().cooldown(true).register(); .actions(InputHandlers::handleToggleSneak).onlyInGame().cooldown().register();
public static final ButtonBinding SPRINT = new Builder("sprint").buttons(GLFW_GAMEPAD_BUTTON_LEFT_THUMB).register(); public static final ButtonBinding SPRINT = new Builder("sprint").buttons(GLFW_GAMEPAD_BUTTON_LEFT_THUMB).onlyInGame().register();
public static final ButtonBinding SWAP_HANDS = new Builder("swap_hands").buttons(GLFW_GAMEPAD_BUTTON_X).cooldown(true).register(); public static final ButtonBinding SWAP_HANDS = new Builder("swap_hands").buttons(GLFW_GAMEPAD_BUTTON_X).onlyInGame().cooldown().register();
public static final ButtonBinding TAB_LEFT = new Builder("tab_back").buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER) public static final ButtonBinding TAB_LEFT = new Builder("tab_back").buttons(GLFW_GAMEPAD_BUTTON_LEFT_BUMPER)
.action(InputHandlers.handleHotbar(false)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements)).cooldown(true).register(); .action(InputHandlers.handleHotbar(false)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements)).cooldown().register();
public static final ButtonBinding TAB_RIGHT = new Builder("tab_next").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER) public static final ButtonBinding TAB_RIGHT = new Builder("tab_next").buttons(GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER)
.action(InputHandlers.handleHotbar(true)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements)).cooldown(true).register(); .action(InputHandlers.handleHotbar(true)).filter(Predicates.or(InputHandlers::inInventory, InputHandlers::inAdvancements)).cooldown().register();
public static final ButtonBinding TOGGLE_PERSPECTIVE = new Builder("toggle_perspective").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_Y).cooldown(true).register(); public static final ButtonBinding TOGGLE_PERSPECTIVE = new Builder("toggle_perspective").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_Y).cooldown().register();
public static final ButtonBinding USE = new Builder("use").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true)).register(); public static final ButtonBinding USE = new Builder("use").buttons(axisAsButton(GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true)).register();
private int[] button; private int[] button;
private int[] defaultButton; private final int[] defaultButton;
private String key; private final String key;
private final Text text;
private KeyBinding mcKeyBinding = null; private KeyBinding mcKeyBinding = null;
protected PairPredicate<MinecraftClient, ButtonBinding> filter; protected PairPredicate<MinecraftClient, ButtonBinding> filter;
private List<PressAction> actions = new ArrayList<>(Collections.singletonList(PressAction.DEFAULT_ACTION)); private List<PressAction> actions = new ArrayList<>(Collections.singletonList(PressAction.DEFAULT_ACTION));
@@ -95,17 +94,16 @@ public class ButtonBinding implements Nameable
private int cooldown = 0; private int cooldown = 0;
boolean pressed = false; boolean pressed = false;
public ButtonBinding(@NotNull String key, int[] defaultButton, @NotNull List<PressAction> actions, PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) public ButtonBinding(@NotNull String key, int[] defaultButton, @NotNull List<PressAction> actions, PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
{
this.setButton(this.defaultButton = defaultButton); this.setButton(this.defaultButton = defaultButton);
this.key = key; this.key = key;
this.text = new TranslatableText(this.key);
this.filter = filter; this.filter = filter;
this.actions.addAll(actions); this.actions.addAll(actions);
this.hasCooldown = hasCooldown; this.hasCooldown = hasCooldown;
} }
public ButtonBinding(@NotNull String key, int[] defaultButton, boolean hasCooldown) public ButtonBinding(@NotNull String key, int[] defaultButton, boolean hasCooldown) {
{
this(key, defaultButton, Collections.emptyList(), Predicates.pairAlwaysTrue(), hasCooldown); this(key, defaultButton, Collections.emptyList(), Predicates.pairAlwaysTrue(), hasCooldown);
} }
@@ -114,8 +112,7 @@ public class ButtonBinding implements Nameable
* *
* @return The bound button. * @return The bound button.
*/ */
public int[] getButton() public int[] getButton() {
{
return this.button; return this.button;
} }
@@ -124,8 +121,7 @@ public class ButtonBinding implements Nameable
* *
* @param button The bound button. * @param button The bound button.
*/ */
public void setButton(int[] button) public void setButton(int[] button) {
{
this.button = button; this.button = button;
if (InputManager.hasBinding(this)) if (InputManager.hasBinding(this))
@@ -138,8 +134,7 @@ public class ButtonBinding implements Nameable
* @param button The button to check. * @param button The button to check.
* @return True if the bound button is the specified button, else false. * @return True if the bound button is the specified button, else false.
*/ */
public boolean isButton(int[] button) public boolean isButton(int[] button) {
{
return InputManager.areButtonsEquivalent(button, this.button); return InputManager.areButtonsEquivalent(button, this.button);
} }
@@ -148,8 +143,7 @@ public class ButtonBinding implements Nameable
* *
* @return True if the button is down, else false. * @return True if the button is down, else false.
*/ */
public boolean isButtonDown() public boolean isButtonDown() {
{
return this.pressed; return this.pressed;
} }
@@ -158,8 +152,7 @@ public class ButtonBinding implements Nameable
* *
* @return True if this button binding is bound, else false. * @return True if this button binding is bound, else false.
*/ */
public boolean isNotBound() public boolean isNotBound() {
{
return this.button.length == 0 || this.button[0] == -1; return this.button.length == 0 || this.button[0] == -1;
} }
@@ -168,8 +161,7 @@ public class ButtonBinding implements Nameable
* *
* @return The default button. * @return The default button.
*/ */
public int[] getDefaultButton() public int[] getDefaultButton() {
{
return this.defaultButton; return this.defaultButton;
} }
@@ -178,8 +170,7 @@ public class ButtonBinding implements Nameable
* *
* @return True if the assigned button is the default button, else false. * @return True if the assigned button is the default button, else false.
*/ */
public boolean isDefault() public boolean isDefault() {
{
return this.button.length == this.defaultButton.length && InputManager.areButtonsEquivalent(this.button, this.defaultButton); return this.button.length == this.defaultButton.length && InputManager.areButtonsEquivalent(this.button, this.defaultButton);
} }
@@ -189,8 +180,7 @@ public class ButtonBinding implements Nameable
* @return The button code. * @return The button code.
*/ */
public @NotNull public @NotNull
String getButtonCode() String getButtonCode() {
{
return Arrays.stream(this.button) return Arrays.stream(this.button)
.mapToObj(btn -> Integer.valueOf(btn).toString()) .mapToObj(btn -> Integer.valueOf(btn).toString())
.collect(Collectors.joining("+")); .collect(Collectors.joining("+"));
@@ -201,8 +191,7 @@ public class ButtonBinding implements Nameable
* *
* @param keyBinding The optional key binding. * @param keyBinding The optional key binding.
*/ */
public void setKeyBinding(@Nullable KeyBinding keyBinding) public void setKeyBinding(@Nullable KeyBinding keyBinding) {
{
this.mcKeyBinding = keyBinding; this.mcKeyBinding = keyBinding;
} }
@@ -212,16 +201,14 @@ public class ButtonBinding implements Nameable
* @param client The client instance. * @param client The client instance.
* @return True if the button binding is available, else false. * @return True if the button binding is available, else false.
*/ */
public boolean isAvailable(@NotNull MinecraftClient client) public boolean isAvailable(@NotNull MinecraftClient client) {
{
return this.filter.test(client, this); return this.filter.test(client, this);
} }
/** /**
* Updates the button binding cooldown. * Updates the button binding cooldown.
*/ */
public void update() public void update() {
{
if (this.hasCooldown && this.cooldown > 0) if (this.hasCooldown && this.cooldown > 0)
this.cooldown--; this.cooldown--;
} }
@@ -232,13 +219,11 @@ public class ButtonBinding implements Nameable
* @param client The client instance. * @param client The client instance.
* @param state The state. * @param state The state.
*/ */
public void handle(@NotNull MinecraftClient client, float value, @NotNull ButtonState state) public void handle(@NotNull MinecraftClient client, float value, @NotNull ButtonState state) {
{
if (state == ButtonState.REPEAT && this.hasCooldown && this.cooldown != 0) if (state == ButtonState.REPEAT && this.hasCooldown && this.cooldown != 0)
return; return;
if (this.hasCooldown && state.isPressed()) { if (this.hasCooldown && state.isPressed()) {
this.cooldown = 5; this.cooldown = 5;
} }
for (int i = this.actions.size() - 1; i >= 0; i--) { for (int i = this.actions.size() - 1; i >= 0; i--) {
if (this.actions.get(i).press(client, this, value, state)) if (this.actions.get(i).press(client, this, value, state))
@@ -247,8 +232,7 @@ public class ButtonBinding implements Nameable
} }
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
return this.key; return this.key;
} }
@@ -257,22 +241,30 @@ public class ButtonBinding implements Nameable
* *
* @return The translation key. * @return The translation key.
*/ */
public @NotNull String getTranslationKey() public @NotNull String getTranslationKey() {
{
return "lambdacontrols.action." + this.getName(); return "lambdacontrols.action." + this.getName();
} }
public @NotNull Text getText() {
return this.text;
}
/** /**
* Returns the key binding equivalent of this button binding. * Returns the key binding equivalent of this button binding.
* *
* @return The key binding equivalent. * @return The key binding equivalent.
*/ */
public @NotNull public @NotNull Optional<KeyBinding> asKeyBinding() {
Optional<KeyBinding> asKeyBinding()
{
return Optional.ofNullable(this.mcKeyBinding); return Optional.ofNullable(this.mcKeyBinding);
} }
@Override
public String toString() {
return "ButtonBinding{id=\"" + this.key + "\","
+ "hasCooldown=" + this.hasCooldown
+ "}";
}
/** /**
* Returns the specified axis as a button. * Returns the specified axis as a button.
* *
@@ -280,8 +272,7 @@ public class ButtonBinding implements Nameable
* @param positive True if the axis part is positive, else false. * @param positive True if the axis part is positive, else false.
* @return The axis as a button. * @return The axis as a button.
*/ */
public static int axisAsButton(int axis, boolean positive) public static int axisAsButton(int axis, boolean positive) {
{
return positive ? 100 + axis : 200 + axis; return positive ? 100 + axis : 200 + axis;
} }
@@ -291,8 +282,7 @@ public class ButtonBinding implements Nameable
* @param button The button. * @param button The button.
* @return True if the button is an axis, else false. * @return True if the button is an axis, else false.
*/ */
public static boolean isAxis(int button) public static boolean isAxis(int button) {
{
button %= 500; button %= 500;
return button >= 100; return button >= 100;
} }
@@ -303,13 +293,11 @@ public class ButtonBinding implements Nameable
* @param button The raw button code. * @param button The raw button code.
* @return The second Joycon's button code. * @return The second Joycon's button code.
*/ */
public static int controller2Button(int button) public static int controller2Button(int button) {
{
return 500 + button; return 500 + button;
} }
public static void init(@NotNull GameOptions options) public static void init(@NotNull GameOptions options) {
{
ATTACK.mcKeyBinding = options.keyAttack; ATTACK.mcKeyBinding = options.keyAttack;
BACK.mcKeyBinding = options.keyBack; BACK.mcKeyBinding = options.keyBack;
CHAT.mcKeyBinding = options.keyChat; CHAT.mcKeyBinding = options.keyChat;
@@ -336,8 +324,7 @@ public class ButtonBinding implements Nameable
* @param button The button. * @param button The button.
* @return The localized name of the button. * @return The localized name of the button.
*/ */
public static @NotNull Text getLocalizedButtonName(int button) public static @NotNull Text getLocalizedButtonName(int button) {
{
switch (button % 500) { switch (button % 500) {
case -1: case -1:
return new TranslatableText("key.keyboard.unknown"); return new TranslatableText("key.keyboard.unknown");
@@ -397,7 +384,7 @@ public class ButtonBinding implements Nameable
} }
static { static {
MOVEMENT_CATEGORY = registerDefaultCategory("key.categories.movement", category -> category.registerAllBindings( MOVEMENT_CATEGORY = InputManager.registerDefaultCategory("key.categories.movement", category -> category.registerAllBindings(
ButtonBinding.FORWARD, ButtonBinding.FORWARD,
ButtonBinding.BACK, ButtonBinding.BACK,
ButtonBinding.LEFT, ButtonBinding.LEFT,
@@ -405,36 +392,58 @@ public class ButtonBinding implements Nameable
ButtonBinding.JUMP, ButtonBinding.JUMP,
ButtonBinding.SNEAK, ButtonBinding.SNEAK,
ButtonBinding.SPRINT)); ButtonBinding.SPRINT));
GAMEPLAY_CATEGORY = registerDefaultCategory("key.categories.gameplay", category -> category.registerAllBindings( GAMEPLAY_CATEGORY = InputManager.registerDefaultCategory("key.categories.gameplay", category -> category.registerAllBindings(
ButtonBinding.ATTACK, ButtonBinding.ATTACK,
ButtonBinding.PICK_BLOCK, ButtonBinding.PICK_BLOCK,
ButtonBinding.USE ButtonBinding.USE
)); ));
INVENTORY_CATEGORY = registerDefaultCategory("key.categories.inventory", category -> category.registerAllBindings( INVENTORY_CATEGORY = InputManager.registerDefaultCategory("key.categories.inventory", category -> category.registerAllBindings(
ButtonBinding.DROP_ITEM, ButtonBinding.DROP_ITEM,
ButtonBinding.HOTBAR_LEFT, ButtonBinding.HOTBAR_LEFT,
ButtonBinding.HOTBAR_RIGHT, ButtonBinding.HOTBAR_RIGHT,
ButtonBinding.INVENTORY, ButtonBinding.INVENTORY,
ButtonBinding.SWAP_HANDS ButtonBinding.SWAP_HANDS
)); ));
MULTIPLAYER_CATEGORY = registerDefaultCategory("key.categories.multiplayer", MULTIPLAYER_CATEGORY = InputManager.registerDefaultCategory("key.categories.multiplayer",
category -> category.registerAllBindings(ButtonBinding.CHAT, ButtonBinding.PLAYER_LIST)); category -> category.registerAllBindings(ButtonBinding.CHAT, ButtonBinding.PLAYER_LIST));
MISC_CATEGORY = registerDefaultCategory("key.categories.misc", category -> category.registerAllBindings( MISC_CATEGORY = InputManager.registerDefaultCategory("key.categories.misc", category -> category.registerAllBindings(
ButtonBinding.SCREENSHOT, ButtonBinding.SCREENSHOT,
//SMOOTH_CAMERA, //SMOOTH_CAMERA,
ButtonBinding.TOGGLE_PERSPECTIVE ButtonBinding.TOGGLE_PERSPECTIVE
)); ));
} }
/**
* Returns a builder instance.
*
* @param identifier The identifier of the button binding.
* @return The builder instance
* @since 1.5.0
*/
public static Builder builder(@NotNull Identifier identifier) {
return new Builder(identifier);
}
/**
* Returns a builder instance.
*
* @param identifier The identifier of the button binding.
* @return The builder instance.
* @since 1.5.0
*/
public static Builder builder(@NotNull net.minecraft.util.Identifier identifier) {
return new Builder(identifier);
}
/** /**
* Represents a quick {@link ButtonBinding} builder. * Represents a quick {@link ButtonBinding} builder.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.1.0 * @version 1.5.0
* @since 1.1.0 * @since 1.1.0
*/ */
public static class Builder public static class Builder {
{
private final String key; private final String key;
private int[] buttons = new int[0]; private int[] buttons = new int[0];
private List<PressAction> actions = new ArrayList<>(); private List<PressAction> actions = new ArrayList<>();
@@ -448,19 +457,16 @@ public class ButtonBinding implements Nameable
* *
* @param key The key with format {@code "<namespace>.<name>"}. * @param key The key with format {@code "<namespace>.<name>"}.
*/ */
public Builder(@NotNull String key) public Builder(@NotNull String key) {
{
this.key = key; this.key = key;
this.unbound(); this.unbound();
} }
public Builder(@NotNull Identifier identifier) public Builder(@NotNull Identifier identifier) {
{
this(identifier.getNamespace() + "." + identifier.getName()); this(identifier.getNamespace() + "." + identifier.getName());
} }
public Builder(@NotNull net.minecraft.util.Identifier identifier) public Builder(@NotNull net.minecraft.util.Identifier identifier) {
{
this(new Identifier(identifier.toString())); this(new Identifier(identifier.toString()));
} }
@@ -470,8 +476,7 @@ public class ButtonBinding implements Nameable
* @param buttons The default buttons. * @param buttons The default buttons.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder buttons(int... buttons) public Builder buttons(int... buttons) {
{
this.buttons = buttons; this.buttons = buttons;
return this; return this;
} }
@@ -481,8 +486,7 @@ public class ButtonBinding implements Nameable
* *
* @return The builder instance. * @return The builder instance.
*/ */
public Builder unbound() public Builder unbound() {
{
return this.buttons(-1); return this.buttons(-1);
} }
@@ -492,8 +496,7 @@ public class ButtonBinding implements Nameable
* @param actions The actions to add. * @param actions The actions to add.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder actions(@NotNull PressAction... actions) public Builder actions(@NotNull PressAction... actions) {
{
this.actions.addAll(Arrays.asList(actions)); this.actions.addAll(Arrays.asList(actions));
return this; return this;
} }
@@ -504,8 +507,7 @@ public class ButtonBinding implements Nameable
* @param action The action to add. * @param action The action to add.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder action(@NotNull PressAction action) public Builder action(@NotNull PressAction action) {
{
this.actions.add(action); this.actions.add(action);
return this; return this;
} }
@@ -516,8 +518,7 @@ public class ButtonBinding implements Nameable
* @param filter The filter. * @param filter The filter.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder filter(@NotNull PairPredicate<MinecraftClient, ButtonBinding> filter) public Builder filter(@NotNull PairPredicate<MinecraftClient, ButtonBinding> filter) {
{
this.filter = filter; this.filter = filter;
return this; return this;
} }
@@ -529,8 +530,7 @@ public class ButtonBinding implements Nameable
* @see #filter(PairPredicate) * @see #filter(PairPredicate)
* @see InputHandlers#inGame(MinecraftClient, ButtonBinding) * @see InputHandlers#inGame(MinecraftClient, ButtonBinding)
*/ */
public Builder onlyInGame() public Builder onlyInGame() {
{
return this.filter(InputHandlers::inGame); return this.filter(InputHandlers::inGame);
} }
@@ -541,8 +541,7 @@ public class ButtonBinding implements Nameable
* @see #filter(PairPredicate) * @see #filter(PairPredicate)
* @see InputHandlers#inInventory(MinecraftClient, ButtonBinding) * @see InputHandlers#inInventory(MinecraftClient, ButtonBinding)
*/ */
public Builder onlyInInventory() public Builder onlyInInventory() {
{
return this.filter(InputHandlers::inInventory); return this.filter(InputHandlers::inInventory);
} }
@@ -552,20 +551,28 @@ public class ButtonBinding implements Nameable
* @param cooldown True if the {@link ButtonBinding} has a cooldown, else false. * @param cooldown True if the {@link ButtonBinding} has a cooldown, else false.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder cooldown(boolean cooldown) public Builder cooldown(boolean cooldown) {
{
this.cooldown = cooldown; this.cooldown = cooldown;
return this; return this;
} }
/**
* Puts a cooldown on the {@link ButtonBinding}.
*
* @return The builder instance.
* @since 1.5.0
*/
public Builder cooldown() {
return this.cooldown(true);
}
/** /**
* Sets the category of the {@link ButtonBinding}. * Sets the category of the {@link ButtonBinding}.
* *
* @param category The category. * @param category The category.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder category(@Nullable ButtonCategory category) public Builder category(@Nullable ButtonCategory category) {
{
this.category = category; this.category = category;
return this; return this;
} }
@@ -576,8 +583,7 @@ public class ButtonBinding implements Nameable
* @param binding The keybinding to link. * @param binding The keybinding to link.
* @return The builder instance. * @return The builder instance.
*/ */
public Builder linkKeybind(@Nullable KeyBinding binding) public Builder linkKeybind(@Nullable KeyBinding binding) {
{
this.mcBinding = binding; this.mcBinding = binding;
return this; return this;
} }
@@ -587,8 +593,7 @@ public class ButtonBinding implements Nameable
* *
* @return The built {@link ButtonBinding}. * @return The built {@link ButtonBinding}.
*/ */
public ButtonBinding build() public ButtonBinding build() {
{
ButtonBinding binding = new ButtonBinding(this.key, this.buttons, this.actions, this.filter, this.cooldown); ButtonBinding binding = new ButtonBinding(this.key, this.buttons, this.actions, this.filter, this.cooldown);
if (this.category != null) if (this.category != null)
this.category.registerBinding(binding); this.category.registerBinding(binding);
@@ -603,8 +608,7 @@ public class ButtonBinding implements Nameable
* @return The built {@link ButtonBinding}. * @return The built {@link ButtonBinding}.
* @see #build() * @see #build()
*/ */
public ButtonBinding register() public ButtonBinding register() {
{
return InputManager.registerBinding(this.build()); return InputManager.registerBinding(this.build());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import org.aperlambda.lambdacommon.Identifier; import org.aperlambda.lambdacommon.Identifier;
@@ -26,37 +26,31 @@ import java.util.List;
* @version 1.1.0 * @version 1.1.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class ButtonCategory implements Identifiable public class ButtonCategory implements Identifiable {
{
private final List<ButtonBinding> bindings = new ArrayList<>(); private final List<ButtonBinding> bindings = new ArrayList<>();
private final Identifier id; private final Identifier id;
private int priority; private int priority;
public ButtonCategory(@NotNull Identifier id, int priority) public ButtonCategory(@NotNull Identifier id, int priority) {
{
this.id = id; this.id = id;
this.priority = priority; this.priority = priority;
} }
public ButtonCategory(@NotNull Identifier id) public ButtonCategory(@NotNull Identifier id) {
{
this(id, 100); this(id, 100);
} }
public void registerBinding(@NotNull ButtonBinding binding) public void registerBinding(@NotNull ButtonBinding binding) {
{
if (this.bindings.contains(binding)) if (this.bindings.contains(binding))
throw new IllegalStateException("Cannot register twice a button binding in the same category."); throw new IllegalStateException("Cannot register twice a button binding in the same category.");
this.bindings.add(binding); this.bindings.add(binding);
} }
public void registerAllBindings(@NotNull ButtonBinding... bindings) public void registerAllBindings(@NotNull ButtonBinding... bindings) {
{
this.registerAllBindings(Arrays.asList(bindings)); this.registerAllBindings(Arrays.asList(bindings));
} }
public void registerAllBindings(@NotNull List<ButtonBinding> bindings) public void registerAllBindings(@NotNull List<ButtonBinding> bindings) {
{
bindings.forEach(this::registerBinding); bindings.forEach(this::registerBinding);
} }
@@ -65,8 +59,7 @@ public class ButtonCategory implements Identifiable
* *
* @return The bindings assigned to this category. * @return The bindings assigned to this category.
*/ */
public @NotNull List<ButtonBinding> getBindings() public @NotNull List<ButtonBinding> getBindings() {
{
return Collections.unmodifiableList(this.bindings); return Collections.unmodifiableList(this.bindings);
} }
@@ -77,8 +70,7 @@ public class ButtonCategory implements Identifiable
* *
* @return The translated name. * @return The translated name.
*/ */
public @NotNull String getTranslatedName() public @NotNull String getTranslatedName() {
{
if (this.id.getNamespace().equals("minecraft")) if (this.id.getNamespace().equals("minecraft"))
return I18n.translate(this.id.getName()); return I18n.translate(this.id.getName());
else else
@@ -91,14 +83,12 @@ public class ButtonCategory implements Identifiable
* *
* @return The priority of this category. * @return The priority of this category.
*/ */
public int getPriority() public int getPriority() {
{
return this.priority; return this.priority;
} }
@Override @Override
public @NotNull Identifier getIdentifier() public @NotNull Identifier getIdentifier() {
{
return this.id; return this.id;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,15 +7,22 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.Nameable; import org.aperlambda.lambdacommon.utils.Nameable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWGamepadState; import org.lwjgl.glfw.GLFWGamepadState;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.Buffer; import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@@ -34,16 +41,14 @@ import static org.lwjgl.BufferUtils.createByteBuffer;
* Represents a controller. * Represents a controller.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.0.0 * @version 1.4.3
* @since 1.0.0 * @since 1.0.0
*/ */
public class Controller implements Nameable public class Controller implements Nameable {
{
private static final Map<Integer, Controller> CONTROLLERS = new HashMap<>(); private static final Map<Integer, Controller> CONTROLLERS = new HashMap<>();
private final int id; private final int id;
public Controller(int id) public Controller(int id) {
{
this.id = id; this.id = id;
} }
@@ -52,8 +57,7 @@ public class Controller implements Nameable
* *
* @return The identifier of this controller. * @return The identifier of this controller.
*/ */
public int getId() public int getId() {
{
return this.id; return this.id;
} }
@@ -62,8 +66,7 @@ public class Controller implements Nameable
* *
* @return The controller's GUID. * @return The controller's GUID.
*/ */
public String getGuid() public String getGuid() {
{
String guid = GLFW.glfwGetJoystickGUID(this.id); String guid = GLFW.glfwGetJoystickGUID(this.id);
return guid == null ? "" : guid; return guid == null ? "" : guid;
} }
@@ -73,8 +76,7 @@ public class Controller implements Nameable
* *
* @return True if this controller is connected, else false. * @return True if this controller is connected, else false.
*/ */
public boolean isConnected() public boolean isConnected() {
{
return GLFW.glfwJoystickPresent(this.id); return GLFW.glfwJoystickPresent(this.id);
} }
@@ -83,8 +85,7 @@ public class Controller implements Nameable
* *
* @return True if this controller is a gamepad, else false. * @return True if this controller is a gamepad, else false.
*/ */
public boolean isGamepad() public boolean isGamepad() {
{
return this.isConnected() && GLFW.glfwJoystickIsGamepad(this.id); return this.isConnected() && GLFW.glfwJoystickIsGamepad(this.id);
} }
@@ -94,8 +95,7 @@ public class Controller implements Nameable
* @return The controller's name. * @return The controller's name.
*/ */
@Override @Override
public @NotNull String getName() public @NotNull String getName() {
{
String name = this.isGamepad() ? GLFW.glfwGetGamepadName(this.id) : GLFW.glfwGetJoystickName(this.id); String name = this.isGamepad() ? GLFW.glfwGetGamepadName(this.id) : GLFW.glfwGetJoystickName(this.id);
return name == null ? String.valueOf(this.getId()) : name; return name == null ? String.valueOf(this.getId()) : name;
} }
@@ -105,16 +105,14 @@ public class Controller implements Nameable
* *
* @return The state of the controller input. * @return The state of the controller input.
*/ */
public GLFWGamepadState getState() public GLFWGamepadState getState() {
{
GLFWGamepadState state = GLFWGamepadState.create(); GLFWGamepadState state = GLFWGamepadState.create();
if (this.isGamepad()) if (this.isGamepad())
GLFW.glfwGetGamepadState(this.id, state); GLFW.glfwGetGamepadState(this.id, state);
return state; return state;
} }
public static @NotNull Controller byId(int id) public static @NotNull Controller byId(int id) {
{
if (id > GLFW.GLFW_JOYSTICK_LAST) { if (id > GLFW.GLFW_JOYSTICK_LAST) {
LambdaControlsClient.get().log("Controller '" + id + "' doesn't exist."); LambdaControlsClient.get().log("Controller '" + id + "' doesn't exist.");
id = GLFW.GLFW_JOYSTICK_LAST; id = GLFW.GLFW_JOYSTICK_LAST;
@@ -129,8 +127,7 @@ public class Controller implements Nameable
} }
} }
public static @NotNull Optional<Controller> byGuid(@NotNull String guid) public static @NotNull Optional<Controller> byGuid(@NotNull String guid) {
{
return CONTROLLERS.values().stream().filter(Controller::isConnected) return CONTROLLERS.values().stream().filter(Controller::isConnected)
.filter(controller -> controller.getGuid().equals(guid)) .filter(controller -> controller.getGuid().equals(guid))
.max(Comparator.comparingInt(Controller::getId)); .max(Comparator.comparingInt(Controller::getId));
@@ -144,8 +141,7 @@ public class Controller implements Nameable
* @return The resource data. * @return The resource data.
* @throws IOException If an IO error occurs. * @throws IOException If an IO error occurs.
*/ */
private static ByteBuffer ioResourceToBuffer(String resource, int bufferSize) throws IOException private static ByteBuffer ioResourceToBuffer(String resource, int bufferSize) throws IOException {
{
ByteBuffer buffer = null; ByteBuffer buffer = null;
Path path = Paths.get(resource); Path path = Paths.get(resource);
@@ -164,17 +160,49 @@ public class Controller implements Nameable
/** /**
* Updates the controller mappings. * Updates the controller mappings.
*/ */
public static void updateMappings() public static void updateMappings() {
{
try { try {
File mappingsFile = new File("config/gamecontrollerdb.txt"); if (!LambdaControlsClient.MAPPINGS_FILE.exists())
if (!mappingsFile.exists())
return; return;
LambdaControlsClient.get().log("Updating controller mappings..."); LambdaControlsClient.get().log("Updating controller mappings...");
ByteBuffer buffer = ioResourceToBuffer(mappingsFile.getPath(), 1024); ByteBuffer buffer = ioResourceToBuffer(LambdaControlsClient.MAPPINGS_FILE.getPath(), 1024);
GLFW.glfwUpdateGamepadMappings(buffer); GLFW.glfwUpdateGamepadMappings(buffer);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
MemoryStack memoryStack = MemoryStack.stackPush();
try {
PointerBuffer pointerBuffer = memoryStack.mallocPointer(1);
int i = GLFW.glfwGetError(pointerBuffer);
if (i != 0) {
long l = pointerBuffer.get();
String string = l == 0L ? "" : MemoryUtil.memUTF8(l);
MinecraftClient client = MinecraftClient.getInstance();
if (client != null) {
client.getToastManager().add(SystemToast.create(client, SystemToast.Type.TUTORIAL_HINT,
new TranslatableText("lambdacontrols.controller.mappings.error"), new LiteralText(string)));
}
}
} catch (Throwable e) {
/* Ignored :concern: */
} finally {
memoryStack.close();
}
if (LambdaControlsClient.get().config.hasDebug()) {
for (int i = GLFW.GLFW_JOYSTICK_1; i <= GLFW.GLFW_JOYSTICK_16; i++) {
Controller controller = byId(i);
if (!controller.isConnected())
continue;
LambdaControls.get().log(String.format("Controller #%d name: \"%s\"\n GUID: %s\n Gamepad: %s",
controller.id,
controller.getName(),
controller.getGuid(),
controller.isGamepad()));
}
}
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,15 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.client.ButtonState; import dev.lambdaurora.lambdacontrols.client.ButtonState;
import me.lambdaurora.lambdacontrols.client.LambdaInput; import dev.lambdaurora.lambdacontrols.client.LambdaInput;
import me.lambdaurora.lambdacontrols.client.mixin.AdvancementsScreenAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.AdvancementsScreenAccessor;
import me.lambdaurora.lambdacontrols.client.mixin.CreativeInventoryScreenAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.CreativeInventoryScreenAccessor;
import me.lambdaurora.lambdacontrols.client.mixin.RecipeBookWidgetAccessor; import dev.lambdaurora.lambdacontrols.client.mixin.RecipeBookWidgetAccessor;
import me.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor; import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.advancement.AdvancementTab; import net.minecraft.client.gui.screen.advancement.AdvancementTab;
import net.minecraft.client.gui.screen.advancement.AdvancementsScreen; import net.minecraft.client.gui.screen.advancement.AdvancementsScreen;
@@ -39,17 +38,14 @@ import java.util.stream.Collectors;
* Represents some input handlers. * Represents some input handlers.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.4.3
* @since 1.1.0 * @since 1.1.0
*/ */
public class InputHandlers public class InputHandlers {
{ private InputHandlers() {
private InputHandlers()
{
} }
public static PressAction handleHotbar(boolean next) public static PressAction handleHotbar(boolean next) {
{
return (client, button, value, action) -> { return (client, button, value, action) -> {
if (action == ButtonState.RELEASE) if (action == ButtonState.RELEASE)
return false; return false;
@@ -69,7 +65,7 @@ public class InputHandlers
nextTab = ItemGroup.GROUPS.length - 1; nextTab = ItemGroup.GROUPS.length - 1;
else if (nextTab >= ItemGroup.GROUPS.length) else if (nextTab >= ItemGroup.GROUPS.length)
nextTab = 0; nextTab = 0;
inventory.lambdacontrols_setSelectedTab(ItemGroup.GROUPS[nextTab]); inventory.lambdacontrols$setSelectedTab(ItemGroup.GROUPS[nextTab]);
return true; return true;
} else if (client.currentScreen instanceof InventoryScreen) { } else if (client.currentScreen instanceof InventoryScreen) {
RecipeBookWidgetAccessor recipeBook = (RecipeBookWidgetAccessor) ((InventoryScreen) client.currentScreen).getRecipeBookWidget(); RecipeBookWidgetAccessor recipeBook = (RecipeBookWidgetAccessor) ((InventoryScreen) client.currentScreen).getRecipeBookWidget();
@@ -85,7 +81,7 @@ public class InputHandlers
currentTab.setToggled(false); currentTab.setToggled(false);
recipeBook.setCurrentTab(currentTab = tabs.get(nextTab)); recipeBook.setCurrentTab(currentTab = tabs.get(nextTab));
currentTab.setToggled(true); currentTab.setToggled(true);
recipeBook.lambdacontrols_refreshResults(true); recipeBook.lambdacontrols$refreshResults(true);
return true; return true;
} else if (client.currentScreen instanceof AdvancementsScreen) { } else if (client.currentScreen instanceof AdvancementsScreen) {
AdvancementsScreenAccessor screen = (AdvancementsScreenAccessor) client.currentScreen; AdvancementsScreenAccessor screen = (AdvancementsScreenAccessor) client.currentScreen;
@@ -110,8 +106,7 @@ public class InputHandlers
}; };
} }
public static boolean handlePauseGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) public static boolean handlePauseGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) {
{
if (action == ButtonState.PRESS) { if (action == ButtonState.PRESS) {
// If in game, then pause the game. // If in game, then pause the game.
if (client.currentScreen == null) if (client.currentScreen == null)
@@ -132,25 +127,26 @@ public class InputHandlers
* @param action The action done on the binding. * @param action The action done on the binding.
* @return True if handled, else false. * @return True if handled, else false.
*/ */
public static boolean handleScreenshot(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) public static boolean handleScreenshot(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, float value, @NotNull ButtonState action) {
{
if (action == ButtonState.RELEASE) if (action == ButtonState.RELEASE)
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(), ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(),
text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text))); text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
return true; return true;
} }
public static boolean handleToggleSneak(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) public static boolean handleToggleSneak(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) {
{ button.asKeyBinding().ifPresent(binding -> {
if (client.player != null && !client.player.abilities.flying) { boolean sneakToggled = client.options.sneakToggled;
button.asKeyBinding().filter(binding -> action == ButtonState.PRESS).ifPresent(binding -> ((KeyBindingAccessor) binding).lambdacontrols_handlePressState(!binding.isPressed())); if (client.player.abilities.flying && sneakToggled)
client.options.sneakToggled = false;
binding.setPressed(button.pressed);
if (client.player.abilities.flying && sneakToggled)
client.options.sneakToggled = true;
});
return true; return true;
} }
return false;
}
public static PressAction handleInventorySlotPad(int direction) public static PressAction handleInventorySlotPad(int direction) {
{
return (client, binding, value, action) -> { return (client, binding, value, action) -> {
if (!(client.currentScreen instanceof HandledScreen && action != ButtonState.RELEASE)) if (!(client.currentScreen instanceof HandledScreen && action != ButtonState.RELEASE))
return false; return false;
@@ -163,7 +159,7 @@ public class InputHandlers
double mouseY = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); double mouseY = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
// Finds the hovered slot. // Finds the hovered slot.
Slot mouseSlot = accessor.lambdacontrols_getSlotAt(mouseX, mouseY); Slot mouseSlot = accessor.lambdacontrols$getSlotAt(mouseX, mouseY);
// Finds the closest slot in the GUI within 14 pixels. // Finds the closest slot in the GUI within 14 pixels.
Optional<Slot> closestSlot = inventory.getScreenHandler().slots.parallelStream() Optional<Slot> closestSlot = inventory.getScreenHandler().slots.parallelStream()
@@ -225,8 +221,7 @@ public class InputHandlers
* @param binding The affected binding. * @param binding The affected binding.
* @return True. * @return True.
*/ */
public static boolean always(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean always(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return true; return true;
} }
@@ -237,8 +232,7 @@ public class InputHandlers
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in game, else false. * @return True if the client is in game, else false.
*/ */
public static boolean inGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inGame(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen == null; return client.currentScreen == null;
} }
@@ -249,8 +243,7 @@ public class InputHandlers
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in a non-interactive screen, else false. * @return True if the client is in a non-interactive screen, else false.
*/ */
public static boolean inNonInteractiveScreens(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inNonInteractiveScreens(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
if (client.currentScreen == null) if (client.currentScreen == null)
return false; return false;
return !LambdaInput.isScreenInteractive(client.currentScreen); return !LambdaInput.isScreenInteractive(client.currentScreen);
@@ -263,8 +256,7 @@ public class InputHandlers
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in an inventory, else false. * @return True if the client is in an inventory, else false.
*/ */
public static boolean inInventory(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inInventory(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen instanceof HandledScreen; return client.currentScreen instanceof HandledScreen;
} }
@@ -275,8 +267,7 @@ public class InputHandlers
* @param binding The affected binding. * @param binding The affected binding.
* @return True if the client is in the advancements screen, else false. * @return True if the client is in the advancements screen, else false.
*/ */
public static boolean inAdvancements(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) public static boolean inAdvancements(@NotNull MinecraftClient client, @NotNull ButtonBinding binding) {
{
return client.currentScreen instanceof AdvancementsScreen; return client.currentScreen instanceof AdvancementsScreen;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,13 +7,13 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.client.ButtonState; import dev.lambdaurora.lambdacontrols.client.ButtonState;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaControlsConfig; import dev.lambdaurora.lambdacontrols.client.LambdaControlsConfig;
import me.lambdaurora.lambdacontrols.client.util.MouseAccessor; import dev.lambdaurora.lambdacontrols.client.util.MouseAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@@ -36,8 +36,7 @@ import java.util.stream.Stream;
* @version 1.4.0 * @version 1.4.0
* @since 1.1.0 * @since 1.1.0
*/ */
public class InputManager public class InputManager {
{
public static final InputManager INPUT_MANAGER = new InputManager(); public static final InputManager INPUT_MANAGER = new InputManager();
private static final List<ButtonBinding> BINDINGS = new ArrayList<>(); private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
private static final List<ButtonCategory> CATEGORIES = new ArrayList<>(); private static final List<ButtonCategory> CATEGORIES = new ArrayList<>();
@@ -48,19 +47,16 @@ public class InputManager
private int targetMouseX = 0; private int targetMouseX = 0;
private int targetMouseY = 0; private int targetMouseY = 0;
protected InputManager() protected InputManager() {
{
} }
public void tick(@NotNull MinecraftClient client) public void tick(@NotNull MinecraftClient client) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
this.controllerTick(client); this.controllerTick(client);
} }
} }
public void controllerTick(@NotNull MinecraftClient client) public void controllerTick(@NotNull MinecraftClient client) {
{
this.prevTargetMouseX = this.targetMouseX; this.prevTargetMouseX = this.targetMouseX;
this.prevTargetMouseY = this.targetMouseY; this.prevTargetMouseY = this.targetMouseY;
} }
@@ -70,15 +66,14 @@ public class InputManager
* *
* @param client The client instance. * @param client The client instance.
*/ */
public void updateMousePosition(@NotNull MinecraftClient client) public void updateMousePosition(@NotNull MinecraftClient client) {
{
Objects.requireNonNull(client, "Client instance cannot be null."); Objects.requireNonNull(client, "Client instance cannot be null.");
if (this.prevTargetMouseX != this.targetMouseX || this.prevTargetMouseY != this.targetMouseY) { if (this.prevTargetMouseX != this.targetMouseX || this.prevTargetMouseY != this.targetMouseY) {
double mouseX = this.prevTargetMouseX + (this.targetMouseX - this.prevTargetMouseX) * client.getTickDelta() + 0.5; double mouseX = this.prevTargetMouseX + (this.targetMouseX - this.prevTargetMouseX) * client.getTickDelta() + 0.5;
double mouseY = this.prevTargetMouseY + (this.targetMouseY - this.prevTargetMouseY) * client.getTickDelta() + 0.5; double mouseY = this.prevTargetMouseY + (this.targetMouseY - this.prevTargetMouseY) * client.getTickDelta() + 0.5;
if (!LambdaControlsClient.get().config.hasVirtualMouse()) if (!LambdaControlsClient.get().config.hasVirtualMouse())
GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouseX, mouseY); GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouseX, mouseY);
((MouseAccessor) client.mouse).lambdacontrols_onCursorPos(client.getWindow().getHandle(), mouseX, mouseY); ((MouseAccessor) client.mouse).lambdacontrols$onCursorPos(client.getWindow().getHandle(), mouseX, mouseY);
} }
} }
@@ -88,14 +83,12 @@ public class InputManager
* @param windowWidth The window width. * @param windowWidth The window width.
* @param windowHeight The window height. * @param windowHeight The window height.
*/ */
public void resetMousePosition(int windowWidth, int windowHeight) public void resetMousePosition(int windowWidth, int windowHeight) {
{
this.targetMouseX = this.prevTargetMouseX = (int) (windowWidth / 2.F); this.targetMouseX = this.prevTargetMouseX = (int) (windowWidth / 2.F);
this.targetMouseY = this.prevTargetMouseY = (int) (windowHeight / 2.F); this.targetMouseY = this.prevTargetMouseY = (int) (windowHeight / 2.F);
} }
public void resetMouseTarget(@NotNull MinecraftClient client) public void resetMouseTarget(@NotNull MinecraftClient client) {
{
double mouseX = client.mouse.getX(); double mouseX = client.mouse.getX();
double mouseY = client.mouse.getY(); double mouseY = client.mouse.getY();
this.prevTargetMouseX = this.targetMouseX = (int) mouseX; this.prevTargetMouseX = this.targetMouseX = (int) mouseX;
@@ -108,8 +101,7 @@ public class InputManager
* @param binding The binding to check. * @param binding The binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull ButtonBinding binding) public static boolean hasBinding(@NotNull ButtonBinding binding) {
{
return BINDINGS.contains(binding); return BINDINGS.contains(binding);
} }
@@ -119,8 +111,7 @@ public class InputManager
* @param name The name of the binding to check. * @param name The name of the binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull String name) public static boolean hasBinding(@NotNull String name) {
{
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)); return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
} }
@@ -130,8 +121,7 @@ public class InputManager
* @param identifier The identifier of the binding to check. * @param identifier The identifier of the binding to check.
* @return True if the binding is registered, else false. * @return True if the binding is registered, else false.
*/ */
public static boolean hasBinding(@NotNull Identifier identifier) public static boolean hasBinding(@NotNull Identifier identifier) {
{
return hasBinding(identifier.getNamespace() + "." + identifier.getName()); return hasBinding(identifier.getNamespace() + "." + identifier.getName());
} }
@@ -141,39 +131,33 @@ public class InputManager
* @param binding The binding to register. * @param binding The binding to register.
* @return The registered binding. * @return The registered binding.
*/ */
public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) {
{
if (hasBinding(binding)) if (hasBinding(binding))
throw new IllegalStateException("Cannot register twice a button binding in the registry."); throw new IllegalStateException("Cannot register twice a button binding in the registry.");
BINDINGS.add(binding); BINDINGS.add(binding);
return binding; return binding;
} }
public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
{
return registerBinding(new ButtonBinding(id.getNamespace() + "." + id.getName(), defaultButton, actions, filter, hasCooldown)); return registerBinding(new ButtonBinding(id.getNamespace() + "." + id.getName(), defaultButton, actions, filter, hasCooldown));
} }
public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull Identifier id, int[] defaultButton, boolean hasCooldown) {
{
return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown); return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown);
} }
public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, @NotNull List<PressAction> actions, @NotNull PairPredicate<MinecraftClient, ButtonBinding> filter, boolean hasCooldown) {
{
return registerBinding(new Identifier(id.getNamespace(), id.getPath()), defaultButton, actions, filter, hasCooldown); return registerBinding(new Identifier(id.getNamespace(), id.getPath()), defaultButton, actions, filter, hasCooldown);
} }
public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, boolean hasCooldown) public static @NotNull ButtonBinding registerBinding(@NotNull net.minecraft.util.Identifier id, int[] defaultButton, boolean hasCooldown) {
{
return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown); return registerBinding(id, defaultButton, Collections.emptyList(), InputHandlers::always, hasCooldown);
} }
/** /**
* Sorts bindings to get bindings with the higher button counts first. * Sorts bindings to get bindings with the higher button counts first.
*/ */
public static void sortBindings() public static void sortBindings() {
{
synchronized (BINDINGS) { synchronized (BINDINGS) {
List<ButtonBinding> sorted = BINDINGS.stream().sorted(Collections.reverseOrder(Comparator.comparingInt(binding -> binding.getButton().length))) List<ButtonBinding> sorted = BINDINGS.stream().sorted(Collections.reverseOrder(Comparator.comparingInt(binding -> binding.getButton().length)))
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -188,24 +172,20 @@ public class InputManager
* @param category The category to register. * @param category The category to register.
* @return The registered category. * @return The registered category.
*/ */
public static ButtonCategory registerCategory(@NotNull ButtonCategory category) public static ButtonCategory registerCategory(@NotNull ButtonCategory category) {
{
CATEGORIES.add(category); CATEGORIES.add(category);
return category; return category;
} }
public static ButtonCategory registerCategory(@NotNull Identifier identifier, int priority) public static ButtonCategory registerCategory(@NotNull Identifier identifier, int priority) {
{
return registerCategory(new ButtonCategory(identifier, priority)); return registerCategory(new ButtonCategory(identifier, priority));
} }
public static ButtonCategory registerCategory(@NotNull Identifier identifier) public static ButtonCategory registerCategory(@NotNull Identifier identifier) {
{
return registerCategory(new ButtonCategory(identifier)); return registerCategory(new ButtonCategory(identifier));
} }
protected static ButtonCategory registerDefaultCategory(@NotNull String key, @NotNull Consumer<ButtonCategory> keyAdder) protected static ButtonCategory registerDefaultCategory(@NotNull String key, @NotNull Consumer<ButtonCategory> keyAdder) {
{
ButtonCategory category = registerCategory(new Identifier("minecraft", key), CATEGORIES.size()); ButtonCategory category = registerCategory(new Identifier("minecraft", key), CATEGORIES.size());
keyAdder.accept(category); keyAdder.accept(category);
return category; return category;
@@ -216,8 +196,7 @@ public class InputManager
* *
* @param config The configuration instance. * @param config The configuration instance.
*/ */
public static void loadButtonBindings(@NotNull LambdaControlsConfig config) public static void loadButtonBindings(@NotNull LambdaControlsConfig config) {
{
List<ButtonBinding> queue = new ArrayList<>(BINDINGS); List<ButtonBinding> queue = new ArrayList<>(BINDINGS);
queue.forEach(config::loadButtonBinding); queue.forEach(config::loadButtonBinding);
} }
@@ -228,8 +207,7 @@ public class InputManager
* @param binding The binding. * @param binding The binding.
* @return The current state of the binding. * @return The current state of the binding.
*/ */
public static @NotNull ButtonState getBindingState(@NotNull ButtonBinding binding) public static @NotNull ButtonState getBindingState(@NotNull ButtonBinding binding) {
{
ButtonState state = ButtonState.REPEAT; ButtonState state = ButtonState.REPEAT;
for (int btn : binding.getButton()) { for (int btn : binding.getButton()) {
ButtonState btnState = InputManager.STATES.getOrDefault(btn, ButtonState.NONE); ButtonState btnState = InputManager.STATES.getOrDefault(btn, ButtonState.NONE);
@@ -246,8 +224,7 @@ public class InputManager
return state; return state;
} }
public static float getBindingValue(@NotNull ButtonBinding binding, @NotNull ButtonState state) public static float getBindingValue(@NotNull ButtonBinding binding, @NotNull ButtonState state) {
{
if (state.isUnpressed()) if (state.isUnpressed())
return 0.f; return 0.f;
@@ -269,8 +246,7 @@ public class InputManager
* @param button The button to check. * @param button The button to check.
* @return True if the button has duplicated bindings, else false. * @return True if the button has duplicated bindings, else false.
*/ */
public static boolean hasDuplicatedBindings(int[] button) public static boolean hasDuplicatedBindings(int[] button) {
{
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1; return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
} }
@@ -280,8 +256,7 @@ public class InputManager
* @param binding The binding to check. * @param binding The binding to check.
* @return True if the button has duplicated bindings, else false. * @return True if the button has duplicated bindings, else false.
*/ */
public static boolean hasDuplicatedBindings(ButtonBinding binding) public static boolean hasDuplicatedBindings(ButtonBinding binding) {
{
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1; return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
} }
@@ -292,8 +267,7 @@ public class InputManager
* @param buttons2 Second set of buttons. * @param buttons2 Second set of buttons.
* @return True if the two sets of buttons are equivalent, else false. * @return True if the two sets of buttons are equivalent, else false.
*/ */
public static boolean areButtonsEquivalent(int[] buttons1, int[] buttons2) public static boolean areButtonsEquivalent(int[] buttons1, int[] buttons2) {
{
if (buttons1.length != buttons2.length) if (buttons1.length != buttons2.length)
return false; return false;
int count = 0; int count = 0;
@@ -315,16 +289,14 @@ public class InputManager
* @param button The button to check. * @param button The button to check.
* @return True if the button set contains the specified button, else false. * @return True if the button set contains the specified button, else false.
*/ */
public static boolean containsButton(int[] buttons, int button) public static boolean containsButton(int[] buttons, int button) {
{
return Arrays.stream(buttons).anyMatch(btn -> btn == button); return Arrays.stream(buttons).anyMatch(btn -> btn == button);
} }
/** /**
* Updates the button states. * Updates the button states.
*/ */
public static void updateStates() public static void updateStates() {
{
STATES.forEach((btn, state) -> { STATES.forEach((btn, state) -> {
if (state == ButtonState.PRESS) if (state == ButtonState.PRESS)
STATES.put(btn, ButtonState.REPEAT); STATES.put(btn, ButtonState.REPEAT);
@@ -333,8 +305,7 @@ public class InputManager
}); });
} }
public static void updateBindings(@NotNull MinecraftClient client) public static void updateBindings(@NotNull MinecraftClient client) {
{
List<Integer> skipButtons = new ArrayList<>(); List<Integer> skipButtons = new ArrayList<>();
Map<ButtonBinding, Pair<ButtonState, Float>> states = new HashMap<>(); Map<ButtonBinding, Pair<ButtonState, Float>> states = new HashMap<>();
for (ButtonBinding binding : BINDINGS) { for (ButtonBinding binding : BINDINGS) {
@@ -345,6 +316,11 @@ public class InputManager
else else
state = ButtonState.NONE; state = ButtonState.NONE;
} }
if (state == ButtonState.RELEASE && !binding.pressed) {
state = ButtonState.NONE;
}
binding.pressed = state.isPressed(); binding.pressed = state.isPressed();
binding.update(); binding.update();
if (binding.pressed) if (binding.pressed)
@@ -362,24 +338,20 @@ public class InputManager
}); });
} }
public static void queueMousePosition(double x, double y) public static void queueMousePosition(double x, double y) {
{
INPUT_MANAGER.targetMouseX = (int) MathHelper.clamp(x, 0, MinecraftClient.getInstance().getWindow().getWidth()); INPUT_MANAGER.targetMouseX = (int) MathHelper.clamp(x, 0, MinecraftClient.getInstance().getWindow().getWidth());
INPUT_MANAGER.targetMouseY = (int) MathHelper.clamp(y, 0, MinecraftClient.getInstance().getWindow().getHeight()); INPUT_MANAGER.targetMouseY = (int) MathHelper.clamp(y, 0, MinecraftClient.getInstance().getWindow().getHeight());
} }
public static void queueMoveMousePosition(double x, double y) public static void queueMoveMousePosition(double x, double y) {
{
queueMousePosition(INPUT_MANAGER.targetMouseX + x, INPUT_MANAGER.targetMouseY + y); queueMousePosition(INPUT_MANAGER.targetMouseX + x, INPUT_MANAGER.targetMouseY + y);
} }
public static @NotNull Stream<ButtonBinding> streamBindings() public static @NotNull Stream<ButtonBinding> streamBindings() {
{
return BINDINGS.stream(); return BINDINGS.stream();
} }
public static @NotNull Stream<ButtonCategory> streamCategories() public static @NotNull Stream<ButtonCategory> streamCategories() {
{
return CATEGORIES.stream(); return CATEGORIES.stream();
} }
@@ -393,8 +365,7 @@ public class InputManager
* @return The key binding. * @return The key binding.
* @see #makeKeyBinding(Identifier, InputUtil.Type, int, String) * @see #makeKeyBinding(Identifier, InputUtil.Type, int, String)
*/ */
public static @NotNull KeyBinding makeKeyBinding(@NotNull net.minecraft.util.Identifier id, InputUtil.Type type, int code, @NotNull String category) public static @NotNull KeyBinding makeKeyBinding(@NotNull net.minecraft.util.Identifier id, InputUtil.Type type, int code, @NotNull String category) {
{
return makeKeyBinding(new Identifier(id.getNamespace(), id.getPath()), type, code, category); return makeKeyBinding(new Identifier(id.getNamespace(), id.getPath()), type, code, category);
} }
@@ -408,8 +379,7 @@ public class InputManager
* @return The key binding. * @return The key binding.
* @see #makeKeyBinding(net.minecraft.util.Identifier, InputUtil.Type, int, String) * @see #makeKeyBinding(net.minecraft.util.Identifier, InputUtil.Type, int, String)
*/ */
public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) {
{
return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getName()), type, code, category); return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getName()), type, code, category);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,9 +7,10 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.client.ButtonState; import dev.lambdaurora.lambdacontrols.client.ButtonState;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -18,11 +19,10 @@ import org.jetbrains.annotations.NotNull;
* Represents the movement handler. * Represents the movement handler.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.6.0
* @since 1.4.0 * @since 1.4.0
*/ */
public final class MovementHandler implements PressAction public final class MovementHandler implements PressAction {
{
public static final MovementHandler HANDLER = new MovementHandler(); public static final MovementHandler HANDLER = new MovementHandler();
private boolean shouldOverrideMovement = false; private boolean shouldOverrideMovement = false;
private boolean pressingForward = false; private boolean pressingForward = false;
@@ -32,8 +32,7 @@ public final class MovementHandler implements PressAction
private float movementForward = 0.f; private float movementForward = 0.f;
private float movementSideways = 0.f; private float movementSideways = 0.f;
private MovementHandler() private MovementHandler() {
{
} }
/** /**
@@ -41,8 +40,7 @@ public final class MovementHandler implements PressAction
* *
* @param player The client player. * @param player The client player.
*/ */
public void applyMovement(@NotNull ClientPlayerEntity player) public void applyMovement(@NotNull ClientPlayerEntity player) {
{
if (!this.shouldOverrideMovement) if (!this.shouldOverrideMovement)
return; return;
player.input.pressingForward = this.pressingForward; player.input.pressingForward = this.pressingForward;
@@ -55,8 +53,7 @@ public final class MovementHandler implements PressAction
} }
@Override @Override
public boolean press(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) public boolean press(@NotNull MinecraftClient client, @NotNull ButtonBinding button, float value, @NotNull ButtonState action) {
{
if (client.currentScreen != null || client.player == null) if (client.currentScreen != null || client.player == null)
return this.shouldOverrideMovement = false; return this.shouldOverrideMovement = false;
@@ -66,12 +63,14 @@ public final class MovementHandler implements PressAction
else if (button == ButtonBinding.BACK || button == ButtonBinding.RIGHT) else if (button == ButtonBinding.BACK || button == ButtonBinding.RIGHT)
direction = -1; direction = -1;
if (direction == 0) if (action.isUnpressed())
return false; direction = 0;
this.shouldOverrideMovement = true; this.shouldOverrideMovement = direction != 0;
if (LambdaControlsClient.get().config.hasAnalogMovement()) {
value = (float) Math.pow(value, 2); value = (float) Math.pow(value, 2);
} else value = 1.f;
if (button == ButtonBinding.FORWARD || button == ButtonBinding.BACK) { if (button == ButtonBinding.FORWARD || button == ButtonBinding.BACK) {
// Handle forward movement. // Handle forward movement.
@@ -93,6 +92,6 @@ public final class MovementHandler implements PressAction
this.movementSideways *= 0.3D; this.movementSideways *= 0.3D;
} }
return true; return this.shouldOverrideMovement;
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,27 +7,32 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.controller; package dev.lambdaurora.lambdacontrols.client.controller;
import me.lambdaurora.lambdacontrols.client.ButtonState; import dev.lambdaurora.lambdacontrols.client.ButtonState;
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor; import dev.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.StickyKeyBinding;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Represents a press action callback. * Represents a press action callback.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.4.0 * @version 1.4.3
* @since 1.0.0 * @since 1.0.0
*/ */
@FunctionalInterface @FunctionalInterface
public interface PressAction public interface PressAction {
{
PressAction DEFAULT_ACTION = (client, button, value, action) -> { PressAction DEFAULT_ACTION = (client, button, value, action) -> {
if (action == ButtonState.REPEAT || client.currentScreen != null) if (action == ButtonState.REPEAT || client.currentScreen != null)
return false; return false;
button.asKeyBinding().ifPresent(binding -> ((KeyBindingAccessor) binding).lambdacontrols_handlePressState(button.isButtonDown())); button.asKeyBinding().ifPresent(binding -> {
if (binding instanceof StickyKeyBinding)
binding.setPressed(button.pressed);
else
((KeyBindingAccessor) binding).lambdacontrols_handlePressState(button.isButtonDown());
});
return true; return true;
}; };

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,14 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.LambdaControlsConstants; import dev.lambdaurora.lambdacontrols.LambdaControlsConstants;
import me.lambdaurora.lambdacontrols.client.HudSide; import dev.lambdaurora.lambdacontrols.client.HudSide;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.spruceui.hud.Hud; import me.lambdaurora.spruceui.hud.Hud;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
@@ -35,8 +35,7 @@ import org.jetbrains.annotations.Nullable;
* @version 1.3.2 * @version 1.3.2
* @since 1.0.0 * @since 1.0.0
*/ */
public class LambdaControlsHud extends Hud public class LambdaControlsHud extends Hud {
{
private final LambdaControlsClient mod; private final LambdaControlsClient mod;
private MinecraftClient client; private MinecraftClient client;
private int attackWidth = 0; private int attackWidth = 0;
@@ -54,15 +53,13 @@ public class LambdaControlsHud extends Hud
private String placeAction = ""; private String placeAction = "";
private int ticksDisplayedCrosshair = 0; private int ticksDisplayedCrosshair = 0;
public LambdaControlsHud(@NotNull LambdaControlsClient mod) public LambdaControlsHud(@NotNull LambdaControlsClient mod) {
{
super(new Identifier(LambdaControlsConstants.NAMESPACE, "hud/button_indicator")); super(new Identifier(LambdaControlsConstants.NAMESPACE, "hud/button_indicator"));
this.mod = mod; this.mod = mod;
} }
@Override @Override
public void init(@NotNull MinecraftClient client, int screenWidth, int screenHeight) public void init(@NotNull MinecraftClient client, int screenWidth, int screenHeight) {
{
super.init(client, screenWidth, screenHeight); super.init(client, screenWidth, screenHeight);
this.client = client; this.client = client;
this.inventoryWidth = this.width(ButtonBinding.INVENTORY); this.inventoryWidth = this.width(ButtonBinding.INVENTORY);
@@ -79,8 +76,7 @@ public class LambdaControlsHud extends Hud
* Renders the LambdaControls' HUD. * Renders the LambdaControls' HUD.
*/ */
@Override @Override
public void render(MatrixStack matrices, float tickDelta) public void render(MatrixStack matrices, float tickDelta) {
{
if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER && this.client.currentScreen == null) { if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER && this.client.currentScreen == null) {
int y = bottom(2); int y = bottom(2);
this.renderFirstIcons(matrices, this.mod.config.getHudSide() == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y); this.renderFirstIcons(matrices, this.mod.config.getHudSide() == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
@@ -103,8 +99,7 @@ public class LambdaControlsHud extends Hud
} }
} }
public void renderFirstIcons(MatrixStack matrices, int x, int y) public void renderFirstIcons(MatrixStack matrices, int x, int y) {
{
int offset = 2 + this.inventoryWidth + this.inventoryButtonWidth + 4; int offset = 2 + this.inventoryWidth + this.inventoryButtonWidth + 4;
int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x : x - this.inventoryButtonWidth; int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x : x - this.inventoryButtonWidth;
this.drawButton(matrices, currentX, y, ButtonBinding.INVENTORY, true); this.drawButton(matrices, currentX, y, ButtonBinding.INVENTORY, true);
@@ -119,8 +114,7 @@ public class LambdaControlsHud extends Hud
this.drawButton(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty()); this.drawButton(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty());
} }
public void renderSecondIcons(MatrixStack matrices, int x, int y) public void renderSecondIcons(MatrixStack matrices, int x, int y) {
{
int offset; int offset;
int currentX = x; int currentX = x;
if (!this.placeAction.isEmpty()) { if (!this.placeAction.isEmpty()) {
@@ -142,8 +136,7 @@ public class LambdaControlsHud extends Hud
this.drawButton(matrices, currentX, y, ButtonBinding.ATTACK, this.attackWidth != 0); this.drawButton(matrices, currentX, y, ButtonBinding.ATTACK, this.attackWidth != 0);
} }
public void renderFirstSection(MatrixStack matrices, int x, int y) public void renderFirstSection(MatrixStack matrices, int x, int y) {
{
int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x + this.inventoryButtonWidth + 2 : x - this.inventoryButtonWidth - 2 - this.inventoryWidth; int currentX = this.mod.config.getHudSide() == HudSide.LEFT ? x + this.inventoryButtonWidth + 2 : x - this.inventoryButtonWidth - 2 - this.inventoryWidth;
this.drawTip(matrices, currentX, y, ButtonBinding.INVENTORY, true); this.drawTip(matrices, currentX, y, ButtonBinding.INVENTORY, true);
currentX += this.mod.config.getHudSide() == HudSide.LEFT ? this.inventoryWidth + 4 + this.swapHandsButtonWidth + 2 currentX += this.mod.config.getHudSide() == HudSide.LEFT ? this.inventoryWidth + 4 + this.swapHandsButtonWidth + 2
@@ -158,8 +151,7 @@ public class LambdaControlsHud extends Hud
this.drawTip(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty()); this.drawTip(matrices, currentX, y, ButtonBinding.DROP_ITEM, !this.client.player.getMainHandStack().isEmpty());
} }
public void renderSecondSection(MatrixStack matrices, int x, int y) public void renderSecondSection(MatrixStack matrices, int x, int y) {
{
int currentX = x; int currentX = x;
if (!this.placeAction.isEmpty()) { if (!this.placeAction.isEmpty()) {
@@ -181,8 +173,7 @@ public class LambdaControlsHud extends Hud
} }
@Override @Override
public void tick() public void tick() {
{
super.tick(); super.tick();
if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER) { if (this.mod.config.getControlsMode() == ControlsMode.CONTROLLER) {
if (this.client.crosshairTarget == null) if (this.client.crosshairTarget == null)
@@ -249,41 +240,34 @@ public class LambdaControlsHud extends Hud
} }
@Override @Override
public boolean hasTicks() public boolean hasTicks() {
{
return true; return true;
} }
private int bottom(int y) private int bottom(int y) {
{
return this.client.getWindow().getScaledHeight() - y - LambdaControlsRenderer.ICON_SIZE; return this.client.getWindow().getScaledHeight() - y - LambdaControlsRenderer.ICON_SIZE;
} }
private int width(@NotNull ButtonBinding binding) private int width(@NotNull ButtonBinding binding) {
{
return this.width(binding.getTranslationKey()); return this.width(binding.getTranslationKey());
} }
private int width(@Nullable String text) private int width(@Nullable String text) {
{
if (text == null || text.isEmpty()) if (text == null || text.isEmpty())
return 0; return 0;
return this.client.textRenderer.getWidth(I18n.translate(text)); return this.client.textRenderer.getWidth(I18n.translate(text));
} }
private void drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) private void drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) {
{
if (display) if (display)
LambdaControlsRenderer.drawButton(matrices, x, y, button, this.client); LambdaControlsRenderer.drawButton(matrices, x, y, button, this.client);
} }
private void drawTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) private void drawTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display) {
{
this.drawTip(matrices, x, y, button.getTranslationKey(), display); this.drawTip(matrices, x, y, button.getTranslationKey(), display);
} }
private void drawTip(MatrixStack matrices, int x, int y, @NotNull String action, boolean display) private void drawTip(MatrixStack matrices, int x, int y, @NotNull String action, boolean display) {
{
if (!display) if (!display)
return; return;
String translatedAction = I18n.translate(action); String translatedAction = I18n.translate(action);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,13 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaInput; import dev.lambdaurora.lambdacontrols.client.LambdaInput;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import me.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.DrawableHelper;
@@ -29,17 +30,15 @@ import org.lwjgl.glfw.GLFW;
* Represents the LambdaControls renderer. * Represents the LambdaControls renderer.
* *
* @author LambdAurora * @author LambdAurora
* @version 1.3.2 * @version 1.5.0
* @since 1.2.0 * @since 1.2.0
*/ */
public class LambdaControlsRenderer public class LambdaControlsRenderer {
{
public static final int ICON_SIZE = 20; public static final int ICON_SIZE = 20;
private static final int BUTTON_SIZE = 15; private static final int BUTTON_SIZE = 15;
private static final int AXIS_SIZE = 18; private static final int AXIS_SIZE = 18;
public static int getButtonSize(int button) public static int getButtonSize(int button) {
{
switch (button) { switch (button) {
case -1: case -1:
return 0; return 0;
@@ -63,8 +62,7 @@ public class LambdaControlsRenderer
* @param binding The binding. * @param binding The binding.
* @return The width. * @return The width.
*/ */
public static int getBindingIconWidth(@NotNull ButtonBinding binding) public static int getBindingIconWidth(@NotNull ButtonBinding binding) {
{
return getBindingIconWidth(binding.getButton()); return getBindingIconWidth(binding.getButton());
} }
@@ -74,8 +72,7 @@ public class LambdaControlsRenderer
* @param buttons The buttons. * @param buttons The buttons.
* @return The width. * @return The width.
*/ */
public static int getBindingIconWidth(int[] buttons) public static int getBindingIconWidth(int[] buttons) {
{
int width = 0; int width = 0;
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
width += ICON_SIZE; width += ICON_SIZE;
@@ -86,13 +83,11 @@ public class LambdaControlsRenderer
return width; return width;
} }
public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, @NotNull MinecraftClient client) public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, @NotNull MinecraftClient client) {
{
return drawButton(matrices, x, y, button.getButton(), client); return drawButton(matrices, x, y, button.getButton(), client);
} }
public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, int[] buttons, @NotNull MinecraftClient client) public static Pair<Integer, Integer> drawButton(MatrixStack matrices, int x, int y, int[] buttons, @NotNull MinecraftClient client) {
{
int height = 0; int height = 0;
int length = 0; int length = 0;
int currentX = x; int currentX = x;
@@ -111,8 +106,7 @@ public class LambdaControlsRenderer
} }
@SuppressWarnings("deprecated") @SuppressWarnings("deprecated")
public static int drawButton(MatrixStack matrices, int x, int y, int button, @NotNull MinecraftClient client) public static int drawButton(MatrixStack matrices, int x, int y, int button, @NotNull MinecraftClient client) {
{
boolean second = false; boolean second = false;
if (button == -1) if (button == -1)
return 0; return 0;
@@ -203,13 +197,11 @@ public class LambdaControlsRenderer
return ICON_SIZE; return ICON_SIZE;
} }
public static int drawButtonTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display, @NotNull MinecraftClient client) public static int drawButtonTip(MatrixStack matrices, int x, int y, @NotNull ButtonBinding button, boolean display, @NotNull MinecraftClient client) {
{
return drawButtonTip(matrices, x, y, button.getButton(), button.getTranslationKey(), display, client); return drawButtonTip(matrices, x, y, button.getButton(), button.getTranslationKey(), display, client);
} }
public static int drawButtonTip(MatrixStack matrices, int x, int y, int[] button, @NotNull String action, boolean display, @NotNull MinecraftClient client) public static int drawButtonTip(MatrixStack matrices, int x, int y, int[] button, @NotNull String action, boolean display, @NotNull MinecraftClient client) {
{
if (display) { if (display) {
int buttonWidth = drawButton(matrices, x, y, button, client).key; int buttonWidth = drawButton(matrices, x, y, button, client).key;
@@ -222,13 +214,11 @@ public class LambdaControlsRenderer
return -10; return -10;
} }
private static int getButtonTipWidth(@NotNull String action, @NotNull TextRenderer textRenderer) private static int getButtonTipWidth(@NotNull String action, @NotNull TextRenderer textRenderer) {
{
return 15 + 5 + textRenderer.getWidth(action); return 15 + 5 + textRenderer.getWidth(action);
} }
public static void renderVirtualCursor(@NotNull MatrixStack matrices, @NotNull MinecraftClient client) public static void renderVirtualCursor(@NotNull MatrixStack matrices, @NotNull MinecraftClient client) {
{
if (!LambdaControlsClient.get().config.hasVirtualMouse() || (client.currentScreen == null || LambdaInput.isScreenInteractive(client.currentScreen))) if (!LambdaControlsClient.get().config.hasVirtualMouse() || (client.currentScreen == null || LambdaInput.isScreenInteractive(client.currentScreen)))
return; return;
@@ -242,7 +232,7 @@ public class LambdaControlsRenderer
int guiLeft = inventoryScreen.getX(); int guiLeft = inventoryScreen.getX();
int guiTop = inventoryScreen.getY(); int guiTop = inventoryScreen.getY();
Slot slot = inventoryScreen.lambdacontrols_getSlotAt(mouseX, mouseY); Slot slot = inventoryScreen.lambdacontrols$getSlotAt(mouseX, mouseY);
if (slot != null) { if (slot != null) {
mouseX = guiLeft + slot.x; mouseX = guiLeft + slot.x;
@@ -251,6 +241,16 @@ public class LambdaControlsRenderer
} }
} }
if (!hoverSlot) {
Pair<Integer, Integer> slot = LambdaControlsCompat.getSlotAt(client.currentScreen, mouseX, mouseY);
if (slot != null) {
mouseX = slot.getFirst();
mouseY = slot.getSecond();
hoverSlot = true;
}
}
if (!hoverSlot) { if (!hoverSlot) {
mouseX -= 8; mouseX -= 8;
mouseY -= 8; mouseY -= 8;
@@ -268,8 +268,7 @@ public class LambdaControlsRenderer
* @param hoverSlot True if hovering a slot, else false. * @param hoverSlot True if hovering a slot, else false.
* @param client The client instance. * @param client The client instance.
*/ */
public static void drawCursor(@NotNull MatrixStack matrices, int x, int y, boolean hoverSlot, @NotNull MinecraftClient client) public static void drawCursor(@NotNull MatrixStack matrices, int x, int y, boolean hoverSlot, @NotNull MinecraftClient client) {
{
client.getTextureManager().bindTexture(LambdaControlsClient.CURSOR_TEXTURE); client.getTextureManager().bindTexture(LambdaControlsClient.CURSOR_TEXTURE);
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();

View File

@@ -0,0 +1,396 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.ControlsMode;
import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsConfig;
import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import dev.lambdaurora.lambdacontrols.client.gui.widget.ControllerControlsWidget;
import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.option.*;
import me.lambdaurora.spruceui.screen.SpruceScreen;
import me.lambdaurora.spruceui.widget.AbstractSpruceWidget;
import me.lambdaurora.spruceui.widget.SpruceLabelWidget;
import me.lambdaurora.spruceui.widget.container.SpruceContainerWidget;
import me.lambdaurora.spruceui.widget.container.SpruceOptionListWidget;
import me.lambdaurora.spruceui.widget.container.tabbed.SpruceTabbedWidget;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
import org.lwjgl.glfw.GLFW;
/**
* Represents the LambdaControls settings screen.
*/
public class LambdaControlsSettingsScreen extends SpruceScreen {
private static final Text SDL2_GAMEPAD_TOOL = new LiteralText("SDL2 Gamepad Tool").formatted(Formatting.GREEN);
public static final String GAMEPAD_TOOL_URL = "https://generalarcade.com/gamepadtool/";
final LambdaControlsClient mod = LambdaControlsClient.get();
private final LambdaControlsConfig config = this.mod.config;
private final Screen parent;
// General options
private final SpruceOption inputModeOption;
private final SpruceOption autoSwitchModeOption;
private final SpruceOption rotationSpeedOption;
private final SpruceOption mouseSpeedOption;
private final SpruceOption virtualMouseOption;
private final SpruceOption resetOption;
// Gameplay options
private final SpruceOption analogMovementOption;
private final SpruceOption autoJumpOption;
private final SpruceOption fastBlockPlacingOption;
private final SpruceOption frontBlockPlacingOption;
private final SpruceOption verticalReacharoundOption;
private final SpruceOption flyDriftingOption;
private final SpruceOption flyVerticalDriftingOption;
// Appearance options
private final SpruceOption controllerTypeOption;
private final SpruceOption virtualMouseSkinOption;
private final SpruceOption hudEnableOption;
private final SpruceOption hudSideOption;
// Controller options
private final SpruceOption controllerOption =
new SpruceCyclingOption("lambdacontrols.menu.controller",
amount -> {
int id = this.config.getController().getId();
id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST)
id = GLFW.GLFW_JOYSTICK_1;
id = searchNextAvailableController(id, false);
this.config.setController(Controller.byId(id));
},
option -> {
Controller controller = this.config.getController();
String controllerName = controller.getName();
if (!controller.isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
else if (!controller.isGamepad())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD));
else
return option.getDisplayText(new LiteralText(controllerName));
}, null);
private final SpruceOption secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2",
amount -> {
int id = this.config.getSecondController().map(Controller::getId).orElse(-1);
id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST)
id = -1;
id = searchNextAvailableController(id, true);
this.config.setSecondController(id == -1 ? null : Controller.byId(id));
},
option -> this.config.getSecondController().map(controller -> {
String controllerName = controller.getName();
if (!controller.isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
else if (!controller.isGamepad())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD));
else
return option.getDisplayText(new LiteralText(controllerName));
}).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))),
new TranslatableText("lambdacontrols.tooltip.controller2"));
private final SpruceOption unfocusedInputOption;
private final SpruceOption invertsRightXAxis;
private final SpruceOption invertsRightYAxis;
private final SpruceOption rightDeadZoneOption;
private final SpruceOption leftDeadZoneOption;
private final SpruceOption[] maxAnalogValueOptions = new SpruceOption[]{
maxAnalogValueOption(this.config, "lambdacontrols.menu.max_left_x_value", GLFW.GLFW_GAMEPAD_AXIS_LEFT_X),
maxAnalogValueOption(this.config, "lambdacontrols.menu.max_left_y_value", GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y),
maxAnalogValueOption(this.config, "lambdacontrols.menu.max_right_x_value", GLFW.GLFW_GAMEPAD_AXIS_RIGHT_X),
maxAnalogValueOption(this.config, "lambdacontrols.menu.max_right_y_value", GLFW.GLFW_GAMEPAD_AXIS_RIGHT_Y)
};
private static SpruceOption maxAnalogValueOption(LambdaControlsConfig config, String key, int axis) {
return new SpruceDoubleOption(key, .25f, 1.f, 0.05f,
() -> config.getAxisMaxValue(axis),
newValue -> config.setAxisMaxValue(axis, newValue),
option -> option.getDisplayText(new LiteralText(String.format("%.2f", option.get()))),
new TranslatableText(key.replace("menu", "tooltip"))
);
}
private final MutableText controllerMappingsUrlText = new LiteralText("(")
.append(new LiteralText(GAMEPAD_TOOL_URL).formatted(Formatting.GOLD))
.append("),");
private static int searchNextAvailableController(int newId, boolean allowNone) {
if ((allowNone && newId == -1) || newId == 0) return newId;
boolean connected = Controller.byId(newId).isConnected();
if (!connected) {
newId++;
}
if (newId > GLFW.GLFW_JOYSTICK_LAST)
newId = allowNone ? -1 : GLFW.GLFW_JOYSTICK_1;
return connected ? newId : searchNextAvailableController(newId, allowNone);
}
public LambdaControlsSettingsScreen(Screen parent, boolean hideControls) {
super(new TranslatableText("lambdacontrols.title.settings"));
this.parent = parent;
// General options
this.inputModeOption = new SpruceCyclingOption("lambdacontrols.menu.controls_mode",
amount -> {
ControlsMode next = this.config.getControlsMode().next();
this.config.setControlsMode(next);
this.config.save();
if (this.client.player != null) {
ClientPlayNetworking.getSender().sendPacket(LambdaControls.CONTROLS_MODE_CHANNEL, this.mod.makeControlsModeBuffer(next));
}
}, option -> option.getDisplayText(new TranslatableText(this.config.getControlsMode().getTranslationKey())),
new TranslatableText("lambdacontrols.tooltip.controls_mode"));
this.autoSwitchModeOption = new SpruceToggleBooleanOption("lambdacontrols.menu.auto_switch_mode", this.config::hasAutoSwitchMode,
this.config::setAutoSwitchMode, new TranslatableText("lambdacontrols.tooltip.auto_switch_mode"));
this.rotationSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.rotation_speed", 0.0, 100.0, .5f,
this.config::getRotationSpeed,
newValue -> {
synchronized (this.config) {
this.config.setRotationSpeed(newValue);
}
}, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))),
new TranslatableText("lambdacontrols.tooltip.rotation_speed"));
this.mouseSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.mouse_speed", 0.0, 150.0, .5f,
this.config::getMouseSpeed,
newValue -> {
synchronized (this.config) {
this.config.setMouseSpeed(newValue);
}
}, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))),
new TranslatableText("lambdacontrols.tooltip.mouse_speed"));
this.resetOption = SpruceSimpleActionOption.reset(btn -> {
this.config.reset();
MinecraftClient client = MinecraftClient.getInstance();
this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
});
// Gameplay options
this.analogMovementOption = new SpruceToggleBooleanOption("lambdacontrols.menu.analog_movement",
this.config::hasAnalogMovement, this.config::setAnalogMovement,
new TranslatableText("lambdacontrols.tooltip.analog_movement"));
this.autoJumpOption = new SpruceToggleBooleanOption("options.autoJump",
() -> this.client.options.autoJump,
newValue -> this.client.options.autoJump = newValue,
null);
this.fastBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fast_block_placing", this.config::hasFastBlockPlacing,
this.config::setFastBlockPlacing, new TranslatableText("lambdacontrols.tooltip.fast_block_placing"));
this.frontBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.horizontal", this.config::hasFrontBlockPlacing,
this.config::setFrontBlockPlacing, new TranslatableText("lambdacontrols.tooltip.reacharound.horizontal"));
this.verticalReacharoundOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.vertical", this.config::hasVerticalReacharound,
this.config::setVerticalReacharound, new TranslatableText("lambdacontrols.tooltip.reacharound.vertical"));
this.flyDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting", this.config::hasFlyDrifting,
this.config::setFlyDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting"));
this.flyVerticalDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting_vertical", this.config::hasFlyVerticalDrifting,
this.config::setFlyVerticalDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting_vertical"));
// Appearance options
this.controllerTypeOption = new SpruceCyclingOption("lambdacontrols.menu.controller_type",
amount -> this.config.setControllerType(this.config.getControllerType().next()),
option -> option.getDisplayText(this.config.getControllerType().getTranslatedText()),
new TranslatableText("lambdacontrols.tooltip.controller_type"));
this.virtualMouseSkinOption = new SpruceCyclingOption("lambdacontrols.menu.virtual_mouse.skin",
amount -> this.config.setVirtualMouseSkin(this.config.getVirtualMouseSkin().next()),
option -> option.getDisplayText(this.config.getVirtualMouseSkin().getTranslatedText()),
null);
this.hudEnableOption = new SpruceToggleBooleanOption("lambdacontrols.menu.hud_enable", this.config::isHudEnabled,
this.mod::setHudEnabled, new TranslatableText("lambdacontrols.tooltip.hud_enable"));
this.hudSideOption = new SpruceCyclingOption("lambdacontrols.menu.hud_side",
amount -> this.config.setHudSide(this.config.getHudSide().next()),
option -> option.getDisplayText(this.config.getHudSide().getTranslatedText()),
new TranslatableText("lambdacontrols.tooltip.hud_side"));
// Controller options
this.rightDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.right_dead_zone", 0.05, 1.0, .05f,
this.config::getRightDeadZone,
newValue -> {
synchronized (this.config) {
this.config.setRightDeadZone(newValue);
}
}, option -> {
String value = String.valueOf(option.get());
return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5))));
}, new TranslatableText("lambdacontrols.tooltip.right_dead_zone"));
this.leftDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.left_dead_zone", 0.05, 1.0, .05f,
this.config::getLeftDeadZone,
newValue -> {
synchronized (this.config) {
this.config.setLeftDeadZone(newValue);
}
}, option -> {
String value = String.valueOf(option.get());
return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5))));
}, new TranslatableText("lambdacontrols.tooltip.left_dead_zone"));
this.invertsRightXAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_x_axis", this.config::doesInvertRightXAxis,
newValue -> {
synchronized (this.config) {
this.config.setInvertRightXAxis(newValue);
}
}, null);
this.invertsRightYAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_y_axis", this.config::doesInvertRightYAxis,
newValue -> {
synchronized (this.config) {
this.config.setInvertRightYAxis(newValue);
}
}, null);
this.unfocusedInputOption = new SpruceToggleBooleanOption("lambdacontrols.menu.unfocused_input", this.config::hasUnfocusedInput,
this.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input"));
this.virtualMouseOption = new SpruceToggleBooleanOption("lambdacontrols.menu.virtual_mouse", this.config::hasVirtualMouse,
this.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse"));
}
@Override
public void removed() {
this.config.save();
super.removed();
}
@Override
public void onClose() {
this.config.save();
super.onClose();
}
private int getTextHeight() {
return (5 + this.textRenderer.fontHeight) * 3 + 5;
}
@Override
protected void init() {
super.init();
this.buildTabs();
this.addChild(this.resetOption.createWidget(Position.of(this.width / 2 - 155, this.height - 29), 150));
this.addButton(new ButtonWidget(this.width / 2 - 155 + 160, this.height - 29, 150, 20, SpruceTexts.GUI_DONE,
btn -> this.client.openScreen(this.parent)));
}
public void buildTabs() {
SpruceTabbedWidget tabs = new SpruceTabbedWidget(Position.of(0, 24), this.width, this.height - 32 - 24,
null,
Math.max(116, this.width / 8), 0);
this.addChild(tabs);
tabs.addSeparatorEntry(new TranslatableText("lambdacontrols.menu.separator.general"));
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.general"), null,
this::buildGeneralTab);
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.gameplay"), null,
this::buildGameplayTab);
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.visual"), null,
this::buildVisualTab);
tabs.addSeparatorEntry(new TranslatableText("options.controls"));
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.controller_controls"), null,
this::buildControllerControlsTab);
tabs.addSeparatorEntry(new TranslatableText("lambdacontrols.menu.separator.controller"));
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.controller"), null,
this::buildControllerTab);
tabs.addTabEntry(new TranslatableText("lambdacontrols.menu.title.mappings.string"), null,
this::buildMappingsStringEditorTab);
}
public SpruceOptionListWidget buildGeneralTab(int width, int height) {
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, height);
list.addSingleOptionEntry(this.inputModeOption);
list.addSingleOptionEntry(this.autoSwitchModeOption);
list.addSingleOptionEntry(this.rotationSpeedOption);
list.addSingleOptionEntry(this.mouseSpeedOption);
list.addSingleOptionEntry(this.virtualMouseOption);
return list;
}
public SpruceOptionListWidget buildGameplayTab(int width, int height) {
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, height);
list.addSingleOptionEntry(this.analogMovementOption);
list.addSingleOptionEntry(this.fastBlockPlacingOption);
list.addSingleOptionEntry(this.frontBlockPlacingOption);
list.addSingleOptionEntry(this.verticalReacharoundOption);
list.addSingleOptionEntry(this.flyDriftingOption);
list.addSingleOptionEntry(this.flyVerticalDriftingOption);
list.addSingleOptionEntry(this.autoJumpOption);
return list;
}
public SpruceOptionListWidget buildVisualTab(int width, int height) {
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, height);
list.addSingleOptionEntry(this.controllerTypeOption);
list.addSingleOptionEntry(this.virtualMouseSkinOption);
list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.hud", true, null));
list.addSingleOptionEntry(this.hudEnableOption);
list.addSingleOptionEntry(this.hudSideOption);
return list;
}
public ControllerControlsWidget buildControllerControlsTab(int width, int height) {
return new ControllerControlsWidget(Position.origin(), width, height);
}
public AbstractSpruceWidget buildControllerTab(int width, int height) {
SpruceContainerWidget root = new SpruceContainerWidget(Position.origin(), width, height);
SpruceLabelWidget aboutMappings1 = new SpruceLabelWidget(Position.of(0, 2),
new TranslatableText("lambdacontrols.controller.mappings.1", SDL2_GAMEPAD_TOOL),
width, true);
SpruceLabelWidget gamepadToolUrlLabel = new SpruceLabelWidget(Position.of(0, aboutMappings1.getHeight() + 4),
this.controllerMappingsUrlText, width,
label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true);
gamepadToolUrlLabel.setTooltip(new TranslatableText("chat.link.open"));
SpruceLabelWidget aboutMappings3 = new SpruceLabelWidget(Position.of(0,
aboutMappings1.getHeight() + gamepadToolUrlLabel.getHeight() + 6),
new TranslatableText("lambdacontrols.controller.mappings.3", Formatting.GREEN.toString(), Formatting.RESET.toString()),
width, true);
int listHeight = height - 8 - aboutMappings1.getHeight() - aboutMappings3.getHeight() - gamepadToolUrlLabel.getHeight();
SpruceContainerWidget labels = new SpruceContainerWidget(Position.of(0,
listHeight),
width, height - listHeight);
labels.addChild(aboutMappings1);
labels.addChild(gamepadToolUrlLabel);
labels.addChild(aboutMappings3);
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, listHeight);
list.addSingleOptionEntry(this.controllerOption);
list.addSingleOptionEntry(this.secondControllerOption);
list.addSingleOptionEntry(this.unfocusedInputOption);
list.addOptionEntry(this.invertsRightXAxis, this.invertsRightYAxis);
list.addSingleOptionEntry(this.rightDeadZoneOption);
list.addSingleOptionEntry(this.leftDeadZoneOption);
for (SpruceOption option : this.maxAnalogValueOptions) {
list.addSingleOptionEntry(option);
}
root.addChild(list);
root.addChild(labels);
return root;
}
public SpruceContainerWidget buildMappingsStringEditorTab(int width, int height) {
return new MappingsStringInputWidget(Position.origin(), width, height);
}
@Override
public void renderTitle(MatrixStack matrices, int mouseX, int mouseY, float delta) {
drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.menu.title"), this.width / 2, 8, 16777215);
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.option.SpruceOption;
import me.lambdaurora.spruceui.widget.container.SpruceContainerWidget;
import me.lambdaurora.spruceui.widget.text.SpruceTextAreaWidget;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
/**
* Represents the controller mappings file editor screen.
*
* @author LambdAurora
* @version 1.4.3
* @since 1.4.3
*/
public class MappingsStringInputWidget extends SpruceContainerWidget {
private final SpruceOption reloadMappingsOption;
private String mappings;
private SpruceTextAreaWidget textArea;
protected MappingsStringInputWidget(Position position, int width, int height) {
super(position, width, height);
//super(new TranslatableText("lambdacontrols.menu.title.mappings.string"));
this.reloadMappingsOption = ReloadControllerMappingsOption.newOption(btn -> {
this.writeMappings();
});
this.init();
}
public void removed() {
this.writeMappings();
Controller.updateMappings();
}
public void onClose() {
this.removed();
}
public void writeMappings() {
if (this.textArea != null) {
this.mappings = this.textArea.getText();
try {
FileWriter fw = new FileWriter(LambdaControlsClient.MAPPINGS_FILE, false);
fw.write(this.mappings);
fw.close();
} catch (IOException e) {
if (this.client != null)
this.client.getToastManager().add(SystemToast.create(this.client, SystemToast.Type.TUTORIAL_HINT,
new TranslatableText("lambdacontrols.controller.mappings.error.write"), LiteralText.EMPTY));
e.printStackTrace();
}
}
}
protected void init() {
if (this.textArea != null) {
this.mappings = this.textArea.getText();
}
String mappings = "";
if (this.mappings != null)
mappings = this.mappings;
else if (LambdaControlsClient.MAPPINGS_FILE.exists()) {
try {
mappings = String.join("\n", Files.readAllLines(LambdaControlsClient.MAPPINGS_FILE.toPath()));
this.mappings = mappings;
} catch (IOException e) {
/* Ignored */
}
}
int textFieldWidth = (int) (this.width * (5.0 / 6.0));
this.textArea = new SpruceTextAreaWidget(Position.of(this, this.width / 2 - textFieldWidth / 2, 0), textFieldWidth, this.height - 50, new LiteralText(mappings));
this.textArea.setText(mappings);
// Display as many lines as possible
this.textArea.setDisplayedLines(this.textArea.getInnerHeight() / this.client.textRenderer.fontHeight);
this.addChild(this.textArea);
this.addChild(this.reloadMappingsOption.createWidget(Position.of(this.width / 2 - 155, this.height - 29), 310));
}
/*public void renderTitle(MatrixStack matrices, int mouseX, int mouseY, float delta) {
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
}*/
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import me.lambdaurora.spruceui.option.SpruceSimpleActionOption;
import me.lambdaurora.spruceui.widget.SpruceButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
/**
* Represents the option to reload the controller mappings.
*/
public class ReloadControllerMappingsOption {
private static final String KEY = "lambdacontrols.menu.reload_controller_mappings";
public static SpruceSimpleActionOption newOption(@Nullable Consumer<SpruceButtonWidget> before) {
return SpruceSimpleActionOption.of(KEY, btn -> {
MinecraftClient client = MinecraftClient.getInstance();
if (before != null)
before.accept(btn);
Controller.updateMappings();
if (client.currentScreen instanceof LambdaControlsSettingsScreen)
client.currentScreen.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
client.getToastManager().add(SystemToast.create(client, SystemToast.Type.TUTORIAL_HINT,
new TranslatableText("lambdacontrols.controller.mappings.updated"), LiteralText.EMPTY));
}, new TranslatableText("lambdacontrols.tooltip.reload_controller_mappings"));
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.ring.RingPage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
/**
* Represents the controls ring screen.
*
* @author LambdAurora
* @version 1.4.3
* @since 1.4.3
*/
public class RingScreen extends Screen {
protected final LambdaControlsClient mod;
public RingScreen() {
super(new TranslatableText("lambdacontrols.menu.title.ring"));
this.mod = LambdaControlsClient.get();
}
@Override
public boolean isPauseScreen() {
return false;
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
super.render(matrices, mouseX, mouseY, delta);
RingPage page = this.mod.ring.getCurrentPage();
page.render(matrices, this.textRenderer, this.width, this.height, mouseX, mouseY, delta);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
/*if (LambdaControlsClient.BINDING_RING.matchesMouse(button)) {
this.onClose();
return true;
}*/
return false;
}
}

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,36 +7,21 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui;
import me.lambdaurora.lambdacontrols.client.HudSide; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import me.lambdaurora.spruceui.SpruceTexturedButtonWidget;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.util.Arm;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_X;
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_Y;
/** /**
* Represents the touchscreen overlay * Represents the touchscreen overlay
*/ */
public class TouchscreenOverlay extends Screen public class TouchscreenOverlay extends Screen {
{ public TouchscreenOverlay(@NotNull LambdaControlsClient mod) {
public static final Identifier WIDGETS_LOCATION = new Identifier("lambdacontrols", "textures/gui/widgets.png"); super(new LiteralText("Touchscreen overlay"));
}
/*public static final Identifier WIDGETS_LOCATION = new Identifier("lambdacontrols", "textures/gui/widgets.png");
private LambdaControlsClient mod; private LambdaControlsClient mod;
private SpruceTexturedButtonWidget jumpButton; private SpruceTexturedButtonWidget jumpButton;
private SpruceTexturedButtonWidget flyButton; private SpruceTexturedButtonWidget flyButton;
@@ -85,7 +70,7 @@ public class TouchscreenOverlay extends Screen
* Updates the forward button ticks cooldown. * Updates the forward button ticks cooldown.
* *
* @param state The button state. * @param state The button state.
*/ *
private void updateForwardButtonsState(boolean state) private void updateForwardButtonsState(boolean state)
{ {
if (state) if (state)
@@ -96,7 +81,7 @@ public class TouchscreenOverlay extends Screen
/** /**
* Updates the jump buttons. * Updates the jump buttons.
*/ *
private void updateJumpButtons() private void updateJumpButtons()
{ {
if (this.client == null) if (this.client == null)
@@ -125,7 +110,7 @@ public class TouchscreenOverlay extends Screen
* *
* @param btn The pressed button. * @param btn The pressed button.
* @param state The state of the jump button. * @param state The state of the jump button.
*/ *
private void handleJump(ButtonWidget btn, boolean state) private void handleJump(ButtonWidget btn, boolean state)
{ {
((KeyBindingAccessor) this.client.options.keyJump).lambdacontrols_handlePressState(state); ((KeyBindingAccessor) this.client.options.keyJump).lambdacontrols_handlePressState(state);
@@ -293,5 +278,5 @@ public class TouchscreenOverlay extends Screen
this.mod.input.handleLook(this.client, GLFW_GAMEPAD_AXIS_RIGHT_X, (float) Math.abs(deltaX / 5.0), 1); this.mod.input.handleLook(this.client, GLFW_GAMEPAD_AXIS_RIGHT_X, (float) Math.abs(deltaX / 5.0), 1);
} }
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
} }*/
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,11 +7,13 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.gui; package dev.lambdaurora.lambdacontrols.client.gui.widget;
import me.lambdaurora.lambdacontrols.LambdaControls; import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import me.lambdaurora.spruceui.AbstractIconButtonWidget; import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.widget.AbstractSpruceIconButtonWidget;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@@ -22,39 +24,35 @@ import org.jetbrains.annotations.NotNull;
/** /**
* Represents a controller button widget. * Represents a controller button widget.
*/ */
public class ControllerButtonWidget extends AbstractIconButtonWidget public class ControllerButtonWidget extends AbstractSpruceIconButtonWidget {
{
private ButtonBinding binding; private ButtonBinding binding;
private int iconWidth; private int iconWidth;
public ControllerButtonWidget(int x, int y, int width, @NotNull ButtonBinding binding, @NotNull PressAction action) public ControllerButtonWidget(Position position, int width, @NotNull ButtonBinding binding, @NotNull PressAction action) {
{ super(position, width, 20, ButtonBinding.getLocalizedButtonName(binding.getButton()[0]), action);
super(x, y, width, 20, ButtonBinding.getLocalizedButtonName(binding.getButton()[0]), action);
this.binding = binding; this.binding = binding;
} }
public void update() public void update() {
{
int length = binding.getButton().length; int length = binding.getButton().length;
this.setMessage(this.binding.isNotBound() ? LambdaControls.NOT_BOUND_TEXT : this.setMessage(this.binding.isNotBound() ? SpruceTexts.NOT_BOUND.copy() :
(length > 0 ? ButtonBinding.getLocalizedButtonName(binding.getButton()[0]) : new LiteralText("<>"))); (length > 0 ? ButtonBinding.getLocalizedButtonName(binding.getButton()[0]) : new LiteralText("<>")));
} }
@Override @Override
public Text getMessage() public Text getMessage() {
{
if (this.binding.getButton().length > 1) if (this.binding.getButton().length > 1)
return LiteralText.EMPTY; return LiteralText.EMPTY;
return super.getMessage(); return super.getMessage();
} }
@Override @Override
protected int renderIcon(MatrixStack matrices, int mouseX, int mouseY, float delta, int x, int y) protected int renderIcon(MatrixStack matrices, int mouseX, int mouseY, float delta) {
{ int x = this.getX();
if (this.binding.getButton().length > 1) { if (this.binding.getButton().length > 1) {
x += (this.width / 2 - this.iconWidth / 2) - 4; x += (this.width / 2 - this.iconWidth / 2) - 4;
} }
Pair<Integer, Integer> size = LambdaControlsRenderer.drawButton(matrices, x, y, this.binding, MinecraftClient.getInstance()); Pair<Integer, Integer> size = LambdaControlsRenderer.drawButton(matrices, x, this.getY(), this.binding, MinecraftClient.getInstance());
this.iconWidth = size.key; this.iconWidth = size.key;
return size.value; return size.value;
} }

View File

@@ -0,0 +1,64 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui.widget;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.widget.SpruceButtonWidget;
import me.lambdaurora.spruceui.widget.container.SpruceContainerWidget;
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import org.aperlambda.lambdacommon.utils.function.Predicates;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Represents the controls screen.
*/
public class ControllerControlsWidget extends SpruceContainerWidget {
final LambdaControlsClient mod;
private ControlsListWidget bindingsListWidget;
private SpruceButtonWidget resetButton;
public ButtonBinding focusedBinding;
public boolean waiting = false;
public List<Integer> currentButtons = new ArrayList<>();
public ControllerControlsWidget(Position position, int width, int height) {
super(position, width, height);
this.mod = LambdaControlsClient.get();
this.init();
}
protected void init() {
this.addChild(new SpruceButtonWidget(Position.of(this, this.width / 2 - 155, 18), 310, 20,
new TranslatableText("lambdacontrols.menu.keyboard_controls"),
btn -> this.client.openScreen(new ControlsOptionsScreen(null, this.client.options))));
this.bindingsListWidget = new ControlsListWidget(Position.of(this, 0, 43), this.width, this.height - 43 - 35, this);
this.addChild(this.bindingsListWidget);
this.addChild(this.resetButton = new SpruceButtonWidget(Position.of(this, this.width / 2 - 155, this.height - 29), 150, 20,
SpruceTexts.CONTROLS_RESET_ALL,
btn -> InputManager.streamBindings().collect(Collectors.toSet()).forEach(binding -> this.mod.config.setButtonBinding(binding, binding.getDefaultButton()))));
}
@Override
public void renderWidget(MatrixStack matrices, int mouseX, int mouseY, float delta) {
drawCenteredText(matrices, this.client.textRenderer, new TranslatableText("lambdacontrols.menu.title.controller_controls"),
this.getX() + this.width / 2, this.getY() + 4, 16777215);
this.resetButton.setActive(InputManager.streamBindings().anyMatch(Predicates.not(ButtonBinding::isDefault)));
super.renderWidget(matrices, mouseX, mouseY, delta);
}
}

View File

@@ -0,0 +1,320 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.gui.widget;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonCategory;
import dev.lambdaurora.lambdacontrols.client.controller.InputManager;
import me.lambdaurora.spruceui.Position;
import me.lambdaurora.spruceui.SpruceTexts;
import me.lambdaurora.spruceui.navigation.NavigationDirection;
import me.lambdaurora.spruceui.navigation.NavigationUtils;
import me.lambdaurora.spruceui.widget.SpruceButtonWidget;
import me.lambdaurora.spruceui.widget.SpruceSeparatorWidget;
import me.lambdaurora.spruceui.widget.SpruceWidget;
import me.lambdaurora.spruceui.widget.container.SpruceEntryListWidget;
import me.lambdaurora.spruceui.widget.container.SpruceParentWidget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import java.util.*;
/**
* Represents a control list widget.
*/
public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget.Entry> {
private static final int[] UNBOUND = new int[]{-1};
private final ControllerControlsWidget gui;
protected int lastIndex = 0;
private final int maxTextLength;
public ControlsListWidget(Position position, int width, int height, ControllerControlsWidget gui) {
super(position, width, height, 4, ControlsListWidget.Entry.class);
this.gui = gui;
this.maxTextLength = InputManager.streamBindings().mapToInt(binding -> this.client.textRenderer.getWidth(binding.getText())).max().orElse(0);
InputManager.streamCategories()
.sorted(Comparator.comparingInt(ButtonCategory::getPriority))
.forEach(category -> {
this.addEntry(new CategoryEntry(this, category));
category.getBindings().forEach(binding -> {
this.addEntry(new ControlsListWidget.ButtonBindingEntry(this, binding));
});
});
this.setAllowOutsideHorizontalNavigation(true);
}
private int getRowWidth() {
return this.getWidth() - 6 - this.getRowLeft() * 2;
}
public int getRowLeft() {
int baseWidth = 220 + 32;
return this.getWidth() / 2 - baseWidth / 2 + 72 - this.maxTextLength;
}
public class ButtonBindingEntry extends Entry implements SpruceParentWidget<SpruceWidget> {
private final List<SpruceWidget> children = new ArrayList<>();
private @Nullable SpruceWidget focused;
private final ButtonBinding binding;
private final String bindingName;
private final ControllerButtonWidget editButton;
private final SpruceButtonWidget resetButton;
private final SpruceButtonWidget unbindButton;
ButtonBindingEntry(@NotNull ControlsListWidget parent, @NotNull ButtonBinding binding) {
super(parent);
this.binding = binding;
this.bindingName = I18n.translate(this.binding.getTranslationKey());
this.editButton = new ControllerButtonWidget(Position.of(this, parent.getWidth() / 2 - 8, 0), 110, this.binding, btn -> {
gui.focusedBinding = binding;
LambdaControlsClient.get().input.beginControlsInput(gui);
}) {
protected Optional<Text> getNarrationMessage() {
return Optional.of(binding.isNotBound() ? new TranslatableText("narrator.controls.unbound", bindingName) : new TranslatableText("narrator.controls.bound", bindingName, super.getNarrationMessage()));
}
};
this.children.add(editButton);
this.resetButton = new SpruceButtonWidget(Position.of(this,
this.editButton.getPosition().getRelativeX() + this.editButton.getWidth() + 2, 0),
44, 20, new TranslatableText("controls.reset"),
btn -> LambdaControlsClient.get().config.setButtonBinding(binding, binding.getDefaultButton())) {
protected Optional<Text> getNarrationMessage() {
return Optional.of(new TranslatableText("narrator.controls.reset", bindingName));
}
};
this.children.add(this.resetButton);
this.unbindButton = new SpruceButtonWidget(Position.of(this,
this.editButton.getPosition().getRelativeX() + this.editButton.getWidth() + 2, 0),
this.resetButton.getWidth(), this.resetButton.getHeight(), SpruceTexts.GUI_UNBIND,
btn -> {
LambdaControlsClient.get().config.setButtonBinding(binding, UNBOUND);
gui.focusedBinding = null;
LambdaControlsClient.get().input.beginControlsInput(null);
}) {
protected Optional<Text> getNarrationMessage() {
return Optional.of(new TranslatableText("lambdacontrols.narrator.unbound", bindingName));
}
};
this.children.add(this.unbindButton);
this.position.setRelativeX(4);
this.width -= 10;
}
@Override
public List<SpruceWidget> children() {
return this.children;
}
@Override
public @Nullable SpruceWidget getFocused() {
return this.focused;
}
@Override
public void setFocused(@Nullable SpruceWidget focused) {
if (this.focused == focused)
return;
if (this.focused != null)
this.focused.setFocused(false);
this.focused = focused;
}
@Override
public int getHeight() {
return this.children.stream().mapToInt(SpruceWidget::getHeight).reduce(Integer::max).orElse(0) + 4;
}
/* Input */
@Override
protected boolean onMouseClick(double mouseX, double mouseY, int button) {
Iterator<SpruceWidget> it = this.children().iterator();
SpruceWidget element;
do {
if (!it.hasNext()) {
return false;
}
element = it.next();
} while (!element.mouseClicked(mouseX, mouseY, button));
this.setFocused(element);
if (button == GLFW.GLFW_MOUSE_BUTTON_1)
this.dragging = true;
return true;
}
@Override
protected boolean onMouseRelease(double mouseX, double mouseY, int button) {
this.dragging = false;
return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseReleased(mouseX, mouseY, button)).isPresent();
}
@Override
protected boolean onMouseDrag(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
return this.getFocused() != null && this.dragging && button == GLFW.GLFW_MOUSE_BUTTON_1
&& this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
@Override
protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) {
return this.focused != null && this.focused.keyPressed(keyCode, scanCode, modifiers);
}
/* Navigation */
@Override
public void setFocused(boolean focused) {
super.setFocused(focused);
if (!focused) {
this.setFocused(null);
}
}
@Override
public boolean onNavigation(@NotNull NavigationDirection direction, boolean tab) {
if (this.requiresCursor()) return false;
if (!tab && direction.isVertical()) {
if (this.isFocused()) {
this.setFocused(null);
return false;
}
int lastIndex = this.parent.lastIndex;
if (lastIndex >= this.children.size())
lastIndex = this.children.size() - 1;
if (!this.children.get(lastIndex).onNavigation(direction, tab))
return false;
this.setFocused(this.children.get(lastIndex));
return true;
}
boolean result = NavigationUtils.tryNavigate(direction, tab, this.children, this.focused, this::setFocused, true);
if (result) {
this.setFocused(true);
if (direction.isHorizontal() && this.getFocused() != null) {
this.parent.lastIndex = this.children.indexOf(this.getFocused());
}
}
return result;
}
/* Rendering */
@Override
protected void renderWidget(MatrixStack matrices, int mouseX, int mouseY, float delta) {
boolean focused = gui.focusedBinding == this.binding;
TextRenderer textRenderer = ControlsListWidget.this.client.textRenderer;
String bindingName = this.bindingName;
int height = this.getHeight();
//float textX = (float) (this.getX() + 70 - ControlsListWidget.this.maxTextLength);
int textY = this.getY() + height / 2;
textRenderer.draw(matrices, bindingName, this.getX(), (float) (textY - 9 / 2), 16777215);
this.resetButton.setVisible(!focused);
this.unbindButton.setVisible(focused);
this.resetButton.setActive(!this.binding.isDefault());
this.editButton.update();
if (focused) {
MutableText text = new LiteralText("> ").formatted(Formatting.WHITE);
text.append(this.editButton.getMessage().copy().formatted(Formatting.YELLOW));
this.editButton.setMessage(text.append(new LiteralText(" <").formatted(Formatting.WHITE)));
} else if (!this.binding.isNotBound() && InputManager.hasDuplicatedBindings(this.binding)) {
MutableText text = this.editButton.getMessage().copy();
this.editButton.setMessage(text.formatted(Formatting.RED));
} else if (this.binding.isNotBound()) {
MutableText text = this.editButton.getMessage().copy();
this.editButton.setMessage(text.formatted(Formatting.GOLD));
}
this.children.forEach(widget -> widget.render(matrices, mouseX, mouseY, delta));
}
}
public static class CategoryEntry extends Entry {
private final SpruceSeparatorWidget separatorWidget;
protected CategoryEntry(ControlsListWidget parent, ButtonCategory category) {
super(parent);
this.separatorWidget = new SpruceSeparatorWidget(Position.of(this, 2, 0), this.getWidth() - 4,
new LiteralText(category.getTranslatedName())) {
@Override
public int getWidth() {
return CategoryEntry.this.getWidth() - 4;
}
};
}
public SpruceSeparatorWidget getSeparatorWidget() {
return this.separatorWidget;
}
@Override
public int getHeight() {
return this.separatorWidget.getHeight() + 4;
}
/* Navigation */
@Override
public boolean onNavigation(@NotNull NavigationDirection direction, boolean tab) {
return this.separatorWidget.onNavigation(direction, tab);
}
/* Rendering */
@Override
protected void renderWidget(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.separatorWidget.render(matrices, mouseX, mouseY, delta);
}
@Override
public String toString() {
return "SpruceTabbedWidget$SeparatorEntry{" +
"position=" + this.getPosition() +
", width=" + this.getWidth() +
", height=" + this.getHeight() +
'}';
}
}
@Environment(EnvType.CLIENT)
public abstract static class Entry extends SpruceEntryListWidget.Entry {
protected final ControlsListWidget parent;
protected Entry(ControlsListWidget parent) {
this.parent = parent;
}
@Override
public int getWidth() {
return this.parent.getInnerWidth();
}
}
}

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,15 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(AbstractButtonWidget.class) @Mixin(AbstractButtonWidget.class)
public interface AbstractButtonWidgetAccessor public interface AbstractButtonWidgetAccessor {
{
@Accessor("height") @Accessor("height")
int getHeight(); int getHeight();
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.advancement.Advancement; import net.minecraft.advancement.Advancement;
import net.minecraft.client.gui.screen.advancement.AdvancementTab; import net.minecraft.client.gui.screen.advancement.AdvancementTab;
@@ -22,8 +22,7 @@ import java.util.Map;
* Represents an accessor of {@link AdvancementsScreen}. * Represents an accessor of {@link AdvancementsScreen}.
*/ */
@Mixin(AdvancementsScreen.class) @Mixin(AdvancementsScreen.class)
public interface AdvancementsScreenAccessor public interface AdvancementsScreenAccessor {
{
@Accessor("advancementHandler") @Accessor("advancementHandler")
ClientAdvancementManager getAdvancementManager(); ClientAdvancementManager getAdvancementManager();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,11 +7,11 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.controller.MovementHandler; import dev.lambdaurora.lambdacontrols.client.controller.MovementHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.input.Input; import net.minecraft.client.input.Input;
import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.AbstractClientPlayerEntity;
@@ -30,9 +30,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Injects the anti fly drifting feature. * Injects the anti fly drifting feature.
*/ */
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
{ private boolean lambdacontrols$driftingPrevented = false;
private boolean lambdacontrols_driftingPrevented = false;
@Shadow @Shadow
protected abstract boolean hasMovementInput(); protected abstract boolean hasMovementInput();
@@ -47,38 +46,34 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
@Shadow @Shadow
protected abstract boolean isCamera(); protected abstract boolean isCamera();
public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
{
super(world, profile); super(world, profile);
} }
@Inject(method = "move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V")) @Inject(method = "move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V"))
public void onMove(MovementType type, Vec3d movement, CallbackInfo ci) public void onMove(MovementType type, Vec3d movement, CallbackInfo ci) {
{
LambdaControlsClient mod = LambdaControlsClient.get(); LambdaControlsClient mod = LambdaControlsClient.get();
if (type == MovementType.SELF) { if (type == MovementType.SELF) {
if (this.abilities.flying && (!mod.config.hasFlyDrifting() || !mod.config.hasFlyVerticalDrifting())) { if (this.abilities.flying && (!mod.config.hasFlyDrifting() || !mod.config.hasFlyVerticalDrifting())) {
if (!this.hasMovementInput()) { if (!this.hasMovementInput()) {
if (!this.lambdacontrols_driftingPrevented) { if (!this.lambdacontrols$driftingPrevented) {
if (!mod.config.hasFlyDrifting()) if (!mod.config.hasFlyDrifting())
this.setVelocity(this.getVelocity().multiply(0, 1.0, 0)); this.setVelocity(this.getVelocity().multiply(0, 1.0, 0));
} }
this.lambdacontrols_driftingPrevented = true; this.lambdacontrols$driftingPrevented = true;
} else } else
this.lambdacontrols_driftingPrevented = false; this.lambdacontrols$driftingPrevented = false;
} }
} }
} }
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(Z)V", shift = At.Shift.AFTER)) @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(Z)V", shift = At.Shift.AFTER))
public void onInputUpdate(CallbackInfo ci) public void onInputUpdate(CallbackInfo ci) {
{
MovementHandler.HANDLER.applyMovement((ClientPlayerEntity) (Object) this); MovementHandler.HANDLER.applyMovement((ClientPlayerEntity) (Object) this);
} }
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isCamera()Z")) @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isCamera()Z"))
public void onTickMovement(CallbackInfo ci) public void onTickMovement(CallbackInfo ci) {
{
if (this.abilities.flying && this.isCamera()) { if (this.abilities.flying && this.isCamera()) {
if (LambdaControlsClient.get().config.hasFlyVerticalDrifting()) if (LambdaControlsClient.get().config.hasFlyVerticalDrifting())
return; return;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,10 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.client.gui.ControllerControlsScreen; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen; import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
import net.minecraft.client.gui.screen.options.GameOptionsScreen; import net.minecraft.client.gui.screen.options.GameOptionsScreen;
@@ -27,19 +26,16 @@ import org.spongepowered.asm.mixin.injection.Redirect;
* Injects the new controls settings button. * Injects the new controls settings button.
*/ */
@Mixin(ControlsOptionsScreen.class) @Mixin(ControlsOptionsScreen.class)
public class ControlsOptionsScreenMixin extends GameOptionsScreen public class ControlsOptionsScreenMixin extends GameOptionsScreen {
{ public ControlsOptionsScreenMixin(Screen parent, GameOptions gameOptions, Text text) {
public ControlsOptionsScreenMixin(Screen parent, GameOptions gameOptions, Text text)
{
super(parent, gameOptions, text); super(parent, gameOptions, text);
} }
@Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/ControlsOptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 1)) @Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/ControlsOptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 1))
private AbstractButtonWidget onInit(ControlsOptionsScreen screen, AbstractButtonWidget btn) private AbstractButtonWidget onInit(ControlsOptionsScreen screen, AbstractButtonWidget btn) {
{ /*if (this.parent instanceof ControllerControlsWidget)
if (this.parent instanceof ControllerControlsScreen)
return this.addButton(btn); return this.addButton(btn);
else else*/
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), new TranslatableText("menu.options"), return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), new TranslatableText("menu.options"),
b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, true)))); b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, true))));
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@@ -22,8 +22,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
* Represents an accessor to CreativeInventoryScreen. * Represents an accessor to CreativeInventoryScreen.
*/ */
@Mixin(CreativeInventoryScreen.class) @Mixin(CreativeInventoryScreen.class)
public interface CreativeInventoryScreenAccessor public interface CreativeInventoryScreenAccessor {
{
/** /**
* Gets the selected tab. * Gets the selected tab.
* *
@@ -38,7 +37,7 @@ public interface CreativeInventoryScreenAccessor
* @param group The tab's item group. * @param group The tab's item group.
*/ */
@Invoker("setSelectedTab") @Invoker("setSelectedTab")
void lambdacontrols_setSelectedTab(@NotNull ItemGroup group); void lambdacontrols$setSelectedTab(@NotNull ItemGroup group);
/** /**
* Returns whether the slot belongs to the creative inventory or not. * Returns whether the slot belongs to the creative inventory or not.
@@ -47,7 +46,7 @@ public interface CreativeInventoryScreenAccessor
* @return True if the slot is from the creative inventory, else false. * @return True if the slot is from the creative inventory, else false.
*/ */
@Invoker("isCreativeInventorySlot") @Invoker("isCreativeInventorySlot")
boolean lambdacontrols_isCreativeInventorySlot(@Nullable Slot slot); boolean lambdacontrols$isCreativeInventorySlot(@Nullable Slot slot);
/** /**
* Returns whether the current tab has a scrollbar or not. * Returns whether the current tab has a scrollbar or not.
@@ -55,5 +54,5 @@ public interface CreativeInventoryScreenAccessor
* @return True if the current tab has a scrollbar, else false. * @return True if the current tab has a scrollbar, else false.
*/ */
@Invoker("hasScrollbar") @Invoker("hasScrollbar")
boolean lambdacontrols_hasScrollbar(); boolean lambdacontrols$hasScrollbar();
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,15 +7,14 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.client.gui.widget.EntryListWidget; import net.minecraft.client.gui.widget.EntryListWidget;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(EntryListWidget.class) @Mixin(EntryListWidget.class)
public interface EntryListWidgetAccessor public interface EntryListWidgetAccessor {
{
@Invoker("moveSelection") @Invoker("moveSelection")
void lambdacontrols_moveSelection(EntryListWidget.MoveDirection direction); void lambdacontrols$moveSelection(EntryListWidget.MoveDirection direction);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.client.options.GameOptions; import net.minecraft.client.options.GameOptions;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -22,14 +22,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Sets the default of the Auto-Jump option to false. * Sets the default of the Auto-Jump option to false.
*/ */
@Mixin(GameOptions.class) @Mixin(GameOptions.class)
public class GameOptionsMixin public class GameOptionsMixin {
{
@Shadow @Shadow
public boolean autoJump; public boolean autoJump;
@Inject(method = "load", at = @At("HEAD")) @Inject(method = "load", at = @At("HEAD"))
public void onInit(CallbackInfo ci) public void onInit(CallbackInfo ci) {
{
// Set default value of the Auto-Jump option to false. // Set default value of the Auto-Jump option to false.
this.autoJump = false; this.autoJump = false;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,10 +7,10 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@@ -21,15 +21,13 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class) @Mixin(GameRenderer.class)
public class GameRendererMixin public class GameRendererMixin {
{
@Shadow @Shadow
@Final @Final
private MinecraftClient client; private MinecraftClient client;
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;getX()D")) @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;getX()D"))
private void onRender(float tickDelta, long startTime, boolean fullRender, CallbackInfo ci) private void onRender(float tickDelta, long startTime, boolean fullRender, CallbackInfo ci) {
{
if (this.client.currentScreen != null && LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) if (this.client.currentScreen != null && LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER)
LambdaControlsClient.get().input.onPreRenderScreen(this.client, this.client.currentScreen); LambdaControlsClient.get().input.onPreRenderScreen(this.client, this.client.currentScreen);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,13 +7,13 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat; import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import me.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor; import dev.lambdaurora.lambdacontrols.client.util.HandledScreenAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
@@ -32,8 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* Represents the mixin for the class ContainerScreen. * Represents the mixin for the class ContainerScreen.
*/ */
@Mixin(HandledScreen.class) @Mixin(HandledScreen.class)
public abstract class HandledScreenMixin implements HandledScreenAccessor public abstract class HandledScreenMixin implements HandledScreenAccessor {
{
@Accessor("x") @Accessor("x")
public abstract int getX(); public abstract int getX();
@@ -41,17 +40,16 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor
public abstract int getY(); public abstract int getY();
@Invoker("getSlotAt") @Invoker("getSlotAt")
public abstract Slot lambdacontrols_getSlotAt(double posX, double posY); public abstract Slot lambdacontrols$getSlotAt(double posX, double posY);
@Invoker("isClickOutsideBounds") @Invoker("isClickOutsideBounds")
public abstract boolean lambdacontrols_isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button); public abstract boolean lambdacontrols$isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button);
@Invoker("onMouseClick") @Invoker("onMouseClick")
public abstract void lambdacontrols_onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType); public abstract void lambdacontrols$onMouseClick(@Nullable Slot slot, int slotId, int clickData, SlotActionType actionType);
@Inject(method = "render", at = @At("RETURN")) @Inject(method = "render", at = @At("RETURN"))
public void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) public void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
MinecraftClient client = MinecraftClient.getInstance(); MinecraftClient client = MinecraftClient.getInstance();
int x = 2, y = client.getWindow().getScaledHeight() - 2 - LambdaControlsRenderer.ICON_SIZE; int x = 2, y = client.getWindow().getScaledHeight() - 2 - LambdaControlsRenderer.ICON_SIZE;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,16 +7,15 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor; import dev.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(KeyBinding.class) @Mixin(KeyBinding.class)
public class KeyBindingMixin implements KeyBindingAccessor public class KeyBindingMixin implements KeyBindingAccessor {
{
@Shadow @Shadow
private int timesPressed; private int timesPressed;
@@ -24,8 +23,7 @@ public class KeyBindingMixin implements KeyBindingAccessor
private boolean pressed; private boolean pressed;
@Override @Override
public boolean lambdacontrols_press() public boolean lambdacontrols$press() {
{
boolean oldPressed = this.pressed; boolean oldPressed = this.pressed;
if (!this.pressed) if (!this.pressed)
this.pressed = true; this.pressed = true;
@@ -34,8 +32,7 @@ public class KeyBindingMixin implements KeyBindingAccessor
} }
@Override @Override
public boolean lambdacontrols_unpress() public boolean lambdacontrols$unpress() {
{
if (this.pressed) { if (this.pressed) {
this.pressed = false; this.pressed = false;
return true; return true;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,12 +7,11 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.LambdaControlsFeature; import dev.lambdaurora.lambdacontrols.LambdaControlsFeature;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaReacharound; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import me.lambdaurora.lambdacontrols.client.gui.LambdaControlsRenderer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
@@ -39,8 +38,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin public abstract class MinecraftClientMixin {
{
@Shadow @Shadow
@Nullable @Nullable
public HitResult crosshairTarget; public HitResult crosshairTarget;
@@ -64,26 +62,24 @@ public abstract class MinecraftClientMixin
@Shadow @Shadow
private int itemUseCooldown; private int itemUseCooldown;
private BlockPos lambdacontrols_lastTargetPos; private BlockPos lambdacontrols$lastTargetPos;
private Vec3d lambdacontrols_lastPos; private Vec3d lambdacontrols$lastPos;
private Direction lambdacontrols_lastTargetSide; private Direction lambdacontrols$lastTargetSide;
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci) private void onInit(CallbackInfo ci) {
{
LambdaControlsClient.get().onMcInit((MinecraftClient) (Object) this); LambdaControlsClient.get().onMcInit((MinecraftClient) (Object) this);
} }
@Inject(method = "tick", at = @At("HEAD")) @Inject(method = "tick", at = @At("HEAD"))
private void onStartTick(CallbackInfo ci) private void onStartTick(CallbackInfo ci) {
{
if (this.player == null) if (this.player == null)
return; return;
if (!LambdaControlsFeature.FAST_BLOCK_PLACING.isAvailable()) if (!LambdaControlsFeature.FAST_BLOCK_PLACING.isAvailable())
return; return;
if (this.lambdacontrols_lastPos == null) if (this.lambdacontrols$lastPos == null)
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols$lastPos = this.player.getPos();
int cooldown = this.itemUseCooldown; int cooldown = this.itemUseCooldown;
BlockHitResult hitResult; BlockHitResult hitResult;
@@ -92,59 +88,51 @@ public abstract class MinecraftClientMixin
BlockPos targetPos = hitResult.getBlockPos(); BlockPos targetPos = hitResult.getBlockPos();
Direction side = hitResult.getSide(); Direction side = hitResult.getSide();
boolean sidewaysBlockPlacing = this.lambdacontrols_lastTargetPos == null || !targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide)); boolean sidewaysBlockPlacing = this.lambdacontrols$lastTargetPos == null || !targetPos.equals(this.lambdacontrols$lastTargetPos.offset(this.lambdacontrols$lastTargetSide));
boolean backwardsBlockPlacing = this.player.input.movementForward < 0.0f && (this.lambdacontrols_lastTargetPos == null || targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide))); boolean backwardsBlockPlacing = this.player.input.movementForward < 0.0f && (this.lambdacontrols$lastTargetPos == null || targetPos.equals(this.lambdacontrols$lastTargetPos.offset(this.lambdacontrols$lastTargetSide)));
if (cooldown > 1 if (cooldown > 1
&& !targetPos.equals(this.lambdacontrols_lastTargetPos) && !targetPos.equals(this.lambdacontrols$lastTargetPos)
&& (sidewaysBlockPlacing || backwardsBlockPlacing)) { && (sidewaysBlockPlacing || backwardsBlockPlacing)) {
this.itemUseCooldown = 1; this.itemUseCooldown = 1;
} }
this.lambdacontrols_lastTargetPos = targetPos.toImmutable(); this.lambdacontrols$lastTargetPos = targetPos.toImmutable();
this.lambdacontrols_lastTargetSide = side; this.lambdacontrols$lastTargetSide = side;
} }
// Removed front placing sprinting as way too cheaty. // Removed front placing sprinting as way too cheaty.
/*else if (this.player.isSprinting()) { /*else if (this.player.isSprinting()) {
hitResult = this.lambdacontrols_frontBlockPlaceResult; hitResult = LambdaControlsClient.get().reacharound.getLastReacharoundResult();
if (hitResult != null) { if (hitResult != null) {
if (cooldown > 0) if (cooldown > 0)
this.itemUseCooldown = 0; this.itemUseCooldown = 0;
} }
}*/ }*/
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols$lastPos = this.player.getPos();
} }
@Inject(method = "render", at = @At("HEAD")) @Inject(method = "render", at = @At("HEAD"))
private void onRender(boolean fullRender, CallbackInfo ci) private void onRender(boolean fullRender, CallbackInfo ci) {
{
LambdaControlsClient.get().onRender((MinecraftClient) (Object) (this)); LambdaControlsClient.get().onRender((MinecraftClient) (Object) (this));
} }
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;render(FJZ)V", shift = At.Shift.AFTER)) @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;render(FJZ)V", shift = At.Shift.AFTER))
private void renderVirtualCursor(boolean fullRender, CallbackInfo ci) private void renderVirtualCursor(boolean fullRender, CallbackInfo ci) {
{
LambdaControlsRenderer.renderVirtualCursor(new MatrixStack(), (MinecraftClient) (Object) this); LambdaControlsRenderer.renderVirtualCursor(new MatrixStack(), (MinecraftClient) (Object) this);
} }
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At("RETURN"))
private void onLeave(@Nullable Screen screen, CallbackInfo ci)
{
LambdaControlsClient.get().onLeave();
}
@Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true) @Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
private void onItemUse(CallbackInfo ci, Hand[] hands, int handCount, int handIndex, Hand hand, ItemStack stackInHand) private void onItemUse(CallbackInfo ci, Hand[] hands, int handCount, int handIndex, Hand hand, ItemStack stackInHand) {
{ LambdaControlsClient mod = LambdaControlsClient.get();
if (!stackInHand.isEmpty() && this.player.pitch > 35.0F && LambdaControlsClient.get().reacharound.isReacharoundAvailable()) { if (!stackInHand.isEmpty() && this.player.pitch > 35.0F && mod.reacharound.isReacharoundAvailable()) {
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.isOnGround()) { if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.isOnGround()) {
if (!stackInHand.isEmpty() && stackInHand.getItem() instanceof BlockItem) { if (!stackInHand.isEmpty() && stackInHand.getItem() instanceof BlockItem) {
BlockHitResult hitResult = LambdaControlsClient.get().reacharound.getLastReacharoundResult(); BlockHitResult hitResult = mod.reacharound.getLastReacharoundResult();
if (hitResult == null) if (hitResult == null)
return; return;
hitResult = LambdaReacharound.withSideForReacharound(hitResult, stackInHand); hitResult = mod.reacharound.withSideForReacharound(hitResult, stackInHand);
int previousStackCount = stackInHand.getCount(); int previousStackCount = stackInHand.getCount();
ActionResult result = this.interactionManager.interactBlock(this.player, this.world, hand, hitResult); ActionResult result = this.interactionManager.interactBlock(this.player, this.world, hand, hitResult);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,12 +7,12 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaControlsConfig; import dev.lambdaurora.lambdacontrols.client.LambdaControlsConfig;
import me.lambdaurora.lambdacontrols.client.util.MouseAccessor; import dev.lambdaurora.lambdacontrols.client.util.MouseAccessor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse; import net.minecraft.client.Mouse;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@@ -36,7 +36,7 @@ public abstract class MouseMixin implements MouseAccessor
private MinecraftClient client; private MinecraftClient client;
@Invoker("onCursorPos") @Invoker("onCursorPos")
public abstract void lambdacontrols_onCursorPos(long window, double x, double y); public abstract void lambdacontrols$onCursorPos(long window, double x, double y);
@Inject(method = "method_1605", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/Screen;mouseReleased(DDI)Z")) @Inject(method = "method_1605", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/Screen;mouseReleased(DDI)Z"))
private void onMouseBackButton(boolean[] result, double mouseX, double mouseY, int button, CallbackInfo ci) private void onMouseBackButton(boolean[] result, double mouseX, double mouseY, int button, CallbackInfo ci)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,11 +7,11 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.gui.ControllerControlsScreen; import dev.lambdaurora.lambdacontrols.client.gui.LambdaControlsSettingsScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.OptionsScreen; import net.minecraft.client.gui.screen.options.OptionsScreen;
import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
@@ -25,19 +25,16 @@ import org.spongepowered.asm.mixin.injection.Redirect;
* Injects the new controls settings button. * Injects the new controls settings button.
*/ */
@Mixin(OptionsScreen.class) @Mixin(OptionsScreen.class)
public class OptionsScreenMixin extends Screen public class OptionsScreenMixin extends Screen {
{ protected OptionsScreenMixin(Text title) {
protected OptionsScreenMixin(Text title)
{
super(title); super(title);
} }
@Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/OptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 7)) @Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/options/OptionsScreen;addButton(Lnet/minecraft/client/gui/widget/AbstractButtonWidget;)Lnet/minecraft/client/gui/widget/AbstractButtonWidget;", ordinal = 7))
private AbstractButtonWidget lambdacontrols_onInit(OptionsScreen screen, AbstractButtonWidget btn) private AbstractButtonWidget lambdacontrols$onInit(OptionsScreen screen, AbstractButtonWidget btn) {
{
if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) { if (LambdaControlsClient.get().config.getControlsMode() == ControlsMode.CONTROLLER) {
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), btn.getMessage(), return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).getHeight(), btn.getMessage(),
b -> this.client.openScreen(new ControllerControlsScreen(this, false)))); b -> this.client.openScreen(new LambdaControlsSettingsScreen(this, false))));
} else { } else {
return this.addButton(btn); return this.addButton(btn);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,7 +7,7 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget; import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget;
@@ -18,8 +18,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.List; import java.util.List;
@Mixin(RecipeBookWidget.class) @Mixin(RecipeBookWidget.class)
public interface RecipeBookWidgetAccessor public interface RecipeBookWidgetAccessor {
{
@Accessor("tabButtons") @Accessor("tabButtons")
List<RecipeGroupButtonWidget> getTabButtons(); List<RecipeGroupButtonWidget> getTabButtons();
@@ -30,5 +29,5 @@ public interface RecipeBookWidgetAccessor
void setCurrentTab(RecipeGroupButtonWidget currentTab); void setCurrentTab(RecipeGroupButtonWidget currentTab);
@Invoker("refreshResults") @Invoker("refreshResults")
void lambdacontrols_refreshResults(boolean resetCurrentPage); void lambdacontrols$refreshResults(boolean resetCurrentPage);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com> * Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
* *
* This file is part of LambdaControls. * This file is part of LambdaControls.
* *
@@ -7,10 +7,9 @@
* see the LICENSE file. * see the LICENSE file.
*/ */
package me.lambdaurora.lambdacontrols.client.mixin; package dev.lambdaurora.lambdacontrols.client.mixin;
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import me.lambdaurora.lambdacontrols.client.LambdaReacharound;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
@@ -35,16 +34,14 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
/** /**
* Represents a mixin to WorldRenderer. * Represents a mixin to WorldRenderer.
* <p> * <p>
* Handles the rendering of the block outline of the front block placing. * Handles the rendering of the block outline of the reach-around features.
*/ */
@Mixin(WorldRenderer.class) @Mixin(WorldRenderer.class)
public abstract class WorldRendererMixin public abstract class WorldRendererMixin {
{
@Shadow @Shadow
@Final @Final
private MinecraftClient client; private MinecraftClient client;
@@ -57,8 +54,7 @@ public abstract class WorldRendererMixin
private BufferBuilderStorage bufferBuilders; private BufferBuilderStorage bufferBuilders;
@Shadow @Shadow
private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) {
{
} }
@Inject( @Inject(
@@ -71,8 +67,7 @@ public abstract class WorldRendererMixin
) )
) )
private void onOutlineRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, private void onOutlineRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer,
LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
{
if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS || !LambdaControlsClient.get().config.shouldRenderReacharoundOutline()) if (this.client.crosshairTarget == null || this.client.crosshairTarget.getType() != HitResult.Type.MISS || !LambdaControlsClient.get().config.shouldRenderReacharoundOutline())
return; return;
BlockHitResult result = LambdaControlsClient.get().reacharound.getLastReacharoundResult(); BlockHitResult result = LambdaControlsClient.get().reacharound.getLastReacharoundResult();
@@ -84,8 +79,10 @@ public abstract class WorldRendererMixin
if (stack == null || !(stack.getItem() instanceof BlockItem)) if (stack == null || !(stack.getItem() instanceof BlockItem))
return; return;
LambdaControlsClient mod = LambdaControlsClient.get();
Block block = ((BlockItem) stack.getItem()).getBlock(); Block block = ((BlockItem) stack.getItem()).getBlock();
result = LambdaReacharound.withSideForReacharound(result, block); result = mod.reacharound.withSideForReacharound(result, block);
ItemPlacementContext context = new ItemPlacementContext(new ItemUsageContext(this.client.player, Hand.MAIN_HAND, result)); ItemPlacementContext context = new ItemPlacementContext(new ItemUsageContext(this.client.player, Hand.MAIN_HAND, result));
BlockState placementState = block.getPlacementState(context); BlockState placementState = block.getPlacementState(context);
@@ -94,7 +91,7 @@ public abstract class WorldRendererMixin
Vec3d pos = camera.getPos(); Vec3d pos = camera.getPos();
VoxelShape outlineShape = placementState.getOutlineShape(this.client.world, blockPos, ShapeContext.of(camera.getFocusedEntity())); VoxelShape outlineShape = placementState.getOutlineShape(this.client.world, blockPos, ShapeContext.of(camera.getFocusedEntity()));
int[] color = LambdaControlsClient.get().config.getReacharoundOutlineColor(); int[] color = mod.config.getReacharoundOutlineColor();
VertexConsumer vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines()); VertexConsumer vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines());
drawShapeOutline(matrices, vertexConsumer, outlineShape, drawShapeOutline(matrices, vertexConsumer, outlineShape,

View File

@@ -0,0 +1,36 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.ring;
import com.electronwill.nightconfig.core.Config;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.jetbrains.annotations.NotNull;
public class DummyRingAction extends RingAction {
public DummyRingAction(@NotNull Config config) {
super(config);
}
@Override
public @NotNull String getName() {
return "dummy";
}
@Override
public void onAction(@NotNull RingButtonMode mode) {
}
@Override
public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) {
drawCenteredString(matrices, textRenderer, this.getName(), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.ring;
import com.electronwill.nightconfig.core.Config;
import dev.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
public class KeyBindingRingAction extends RingAction {
public static final Factory FACTORY = new Factory();
public final KeyBinding binding;
public KeyBindingRingAction(@NotNull Config config, @NotNull KeyBinding binding) {
super(config);
this.binding = binding;
}
@Override
public @NotNull String getName() {
return this.binding.getTranslationKey();
}
@Override
public void onAction(@NotNull RingButtonMode mode) {
KeyBindingAccessor accessor = (KeyBindingAccessor) this.binding;
switch (mode) {
case PRESS:
case HOLD:
accessor.lambdacontrols_handlePressState(this.activated);
break;
case TOGGLE:
accessor.lambdacontrols_handlePressState(!this.binding.isPressed());
this.activated = !this.binding.isPressed();
break;
}
}
@Override
public void drawIcon(@NotNull MatrixStack matrices, @NotNull TextRenderer textRenderer, int x, int y, boolean hovered) {
drawCenteredText(matrices, textRenderer, new TranslatableText(this.getName()), x + 25, y + 25 - textRenderer.fontHeight / 2, 0xffffff);
}
protected static class Factory implements RingAction.Factory {
@Override
public @NotNull Supplier<RingAction> newFromGui(@NotNull Screen screen) {
return () -> null;
}
@Override
public @Nullable RingAction parse(@NotNull Config config) {
return null;
}
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of LambdaControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package dev.lambdaurora.lambdacontrols.client.ring;
import com.electronwill.nightconfig.core.Config;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Represents a key binding ring.
*
* @author LambdAurora
* @version 1.5.0
* @since 1.4.0
*/
public final class LambdaRing {
public static final int ELEMENT_SIZE = 50;
private final Object2ObjectMap<String, RingAction.Factory> actionFactories = new Object2ObjectOpenHashMap<>();
private final List<RingPage> pages = new ArrayList<>(Collections.singletonList(RingPage.DEFAULT));
private final LambdaControlsClient mod;
private int currentPage = 0;
public LambdaRing(@NotNull LambdaControlsClient mod) {
this.mod = mod;
}
public void registerAction(@NotNull String name, @NotNull RingAction.Factory factory) {
if (this.actionFactories.containsKey(name)) {
this.mod.warn("Tried to register twice a ring action: \"" + name + "\".");
return;
}
this.actionFactories.put(name, factory);
}
/**
* Loads the ring from configuration.
*
* @param config The configuration.
*/
public void load(@NotNull Config config) {
List<Config> configPages = config.get("ring.pages");
if (configPages != null) {
this.pages.clear();
for (Config configPage : configPages) {
RingPage.parseRingPage(configPage).ifPresent(this.pages::add);
}
}
if (this.pages.isEmpty()) {
this.pages.add(RingPage.DEFAULT);
}
}
public @NotNull RingPage getCurrentPage() {
if (this.currentPage >= this.pages.size())
this.currentPage = this.pages.size() - 1;
else if (this.currentPage < 0)
this.currentPage = 0;
return this.pages.get(this.currentPage);
}
}

Some files were not shown because too many files have changed in this diff Show More