Skip to content

Commit 4dd3415

Browse files
authored
Fix controls menu crash when keybind categories share a localized name (#943)
1 parent 6ee6577 commit 4dd3415

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public class FixesConfig {
149149
@Config.DefaultBoolean(true)
150150
public static boolean fixImmobileFireballs;
151151

152+
@Config.Comment("Fix crash in the controls menu when two keybind categories share the same localized name")
153+
@Config.DefaultBoolean(true)
154+
public static boolean fixKeybindCategorySorting;
155+
152156
@Config.Comment("Fix Sugar Cane inability to replace replaceable blocks indirectly.")
153157
@Config.DefaultBoolean(true)
154158
public static boolean fixSugarCanePlacement;

src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ public enum Mixins implements IMixins {
604604
.setApplyIf(() -> FixesConfig.triggerAllConflictingKeybindings)
605605
.addExcludedMod(TargetedMod.MODERNKEYBINDING)
606606
.setPhase(Phase.EARLY)),
607+
FIX_KEYBIND_CATEGORY_SORTING(new MixinBuilder("Fix controls menu crash on colliding localized category names")
608+
.addClientMixins("minecraft.MixinKeyBinding_FixComparison")
609+
.setApplyIf(() -> FixesConfig.fixKeybindCategorySorting)
610+
.addExcludedMod(TargetedMod.MODERNKEYBINDING)
611+
.setPhase(Phase.EARLY)),
607612
REMOVE_SPAWN_MINECART_SOUND(new MixinBuilder("Remove sound when spawning a minecart")
608613
.addClientMixins("minecraft.MixinWorldClient")
609614
.setApplyIf(() -> TweaksConfig.removeSpawningMinecartSound)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.mitchej123.hodgepodge.mixins.early.minecraft;
2+
3+
import net.minecraft.client.resources.I18n;
4+
import net.minecraft.client.settings.KeyBinding;
5+
6+
import org.spongepowered.asm.mixin.Final;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Overwrite;
9+
import org.spongepowered.asm.mixin.Shadow;
10+
11+
@Mixin(KeyBinding.class)
12+
public class MixinKeyBinding_FixComparison {
13+
14+
@Shadow
15+
@Final
16+
private String keyDescription;
17+
@Shadow
18+
@Final
19+
private String keyCategory;
20+
21+
/**
22+
* @author Algent
23+
* @reason Fix controls menu crash when keybind categories share a localized name which can crash the game.
24+
*/
25+
@Overwrite(remap = false)
26+
public int compareTo(KeyBinding other) {
27+
final MixinKeyBinding_FixComparison mixinOther = (MixinKeyBinding_FixComparison) (Object) other;
28+
int result = I18n.format(this.keyCategory).compareTo(I18n.format(mixinOther.keyCategory));
29+
if (result == 0) {
30+
result = this.keyCategory.compareTo(mixinOther.keyCategory);
31+
if (result == 0) {
32+
result = I18n.format(this.keyDescription).compareTo(I18n.format(mixinOther.keyDescription));
33+
}
34+
}
35+
return result;
36+
}
37+
}

0 commit comments

Comments
 (0)