-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Keybindings not appearing or crashing in some versions (#158)
* Fix keybinding common module mixin config name * Test custom keybinding categories * Closes #153 * Closes #132 * Add missing fabric.mod.json for keybinding versionned modules * Bump keybindings-api-v1 version * Apply spotless * Fix style
- Loading branch information
1 parent
fbfdc1c
commit 8b01b57
Showing
16 changed files
with
244 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minVersionIncluded=1.12.2 | ||
maxVersionIncluded=1.12.2 |
44 changes: 44 additions & 0 deletions
44
...1.12.2/src/main/java/net/legacyfabric/fabric/mixin/client/keybinding/KeyBindingMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2020 - 2022 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.client.keybinding; | ||
|
||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.client.option.KeyBinding; | ||
|
||
@Mixin(KeyBinding.class) | ||
public class KeyBindingMixin { | ||
@Shadow | ||
@Final | ||
private static Map<String, Integer> field_15867; | ||
private static int lf$category_count = 7; | ||
@Inject(method = "<init>", at = @At("RETURN")) | ||
private void registerCategory(String string, int i, String category, CallbackInfo ci) { | ||
if (!field_15867.containsKey(category)) { | ||
while (field_15867.containsValue(lf$category_count)) lf$category_count++; | ||
field_15867.put(category, lf$category_count); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
legacy-fabric-keybindings-api-v1/1.12.2/src/main/resources/fabric.mod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-keybinding-api-v1", | ||
"name": "Legacy Fabric Keybinding API (V1)", | ||
"version": "${version}", | ||
"environment": "client", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric-api/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy Fabric", | ||
"FabricMC" | ||
], | ||
"depends": { | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-keybinding-api-v1.mixins.json" | ||
], | ||
"description": "Hooks that help adding keybindings", | ||
"custom": { | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric-api/icon.png" | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-keybindings-api-v1/1.12.2/src/main/resources/legacy-fabric-keybinding-api-v1.mixins.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.client.keybinding", | ||
"compatibilityLevel": "JAVA_8", | ||
"client": [ | ||
"KeyBindingMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
....12.2/src/testmod/java/net/legacyfabric/fabric/test/client/keybinding/KeybindingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2020 - 2022 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.test.client.keybinding; | ||
|
||
import org.lwjgl.input.Keyboard; | ||
|
||
import net.minecraft.client.option.KeyBinding; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
|
||
import net.legacyfabric.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.legacyfabric.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
|
||
public class KeybindingTest implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey", Keyboard.KEY_F, "key.categories.lftesting")); | ||
ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
if (keyBinding.wasPressed()) { | ||
System.out.printf("The key %s was pressed%n", Keyboard.getKeyName(keyBinding.getCode())); | ||
} | ||
}); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
legacy-fabric-keybindings-api-v1/1.12.2/src/testmod/resources/fabric.mod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-keybinding-api-v1-testmod", | ||
"description": "Tests for keybindings", | ||
"version": "1.0.0", | ||
"entrypoints": { | ||
"client": [ | ||
"net.legacyfabric.fabric.test.client.keybinding.KeybindingTest" | ||
] | ||
}, | ||
"depends": { | ||
"minecraft": "${minecraft_version}" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
legacy-fabric-keybindings-api-v1/1.7.10/src/main/resources/fabric.mod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-keybinding-api-v1", | ||
"name": "Legacy Fabric Keybinding API (V1)", | ||
"version": "${version}", | ||
"environment": "client", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric-api/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy Fabric", | ||
"FabricMC" | ||
], | ||
"depends": { | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"mixins": [], | ||
"description": "Hooks that help adding keybindings", | ||
"custom": { | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric-api/icon.png" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
minVersionIncluded=1.8 | ||
maxVersionIncluded=1.12.2 | ||
maxVersionIncluded=1.11.2 |
35 changes: 35 additions & 0 deletions
35
legacy-fabric-keybindings-api-v1/1.8.9/src/main/resources/fabric.mod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-keybinding-api-v1", | ||
"name": "Legacy Fabric Keybinding API (V1)", | ||
"version": "${version}", | ||
"environment": "client", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric-api/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy Fabric", | ||
"FabricMC" | ||
], | ||
"depends": { | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"mixins": [], | ||
"description": "Hooks that help adding keybindings", | ||
"custom": { | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric-api/icon.png" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.