aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-05-25 22:06:20 +0100
committerisXander <xandersmith2008@gmail.com>2023-05-25 22:06:20 +0100
commitc3f1e6836ea0fbbe5944125a121606aad849d9b4 (patch)
tree723d55bcb0bff4477f63ee25acbf74da957becee /common/src
parent2792276924cf5e292211bc0d43dbc4cf3eb9c181 (diff)
downloadYetAnotherConfigLib-c3f1e6836ea0fbbe5944125a121606aad849d9b4.tar.gz
YetAnotherConfigLib-c3f1e6836ea0fbbe5944125a121606aad849d9b4.tar.bz2
YetAnotherConfigLib-c3f1e6836ea0fbbe5944125a121606aad849d9b4.zip
Fix arrow key navigation unable to focus on action buttons
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/dev/isxander/yacl/mixin/ContainerEventHandlerMixin.java31
-rw-r--r--common/src/main/resources/yacl.mixins.json1
2 files changed, 32 insertions, 0 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/mixin/ContainerEventHandlerMixin.java b/common/src/main/java/dev/isxander/yacl/mixin/ContainerEventHandlerMixin.java
new file mode 100644
index 0000000..d864e17
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl/mixin/ContainerEventHandlerMixin.java
@@ -0,0 +1,31 @@
+package dev.isxander.yacl.mixin;
+
+import net.minecraft.client.gui.components.events.ContainerEventHandler;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+import net.minecraft.client.gui.components.tabs.TabNavigationBar;
+import net.minecraft.client.gui.navigation.FocusNavigationEvent;
+import net.minecraft.client.gui.navigation.ScreenAxis;
+import net.minecraft.client.gui.navigation.ScreenDirection;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Redirect;
+
+import java.util.List;
+
+@Mixin(ContainerEventHandler.class)
+public interface ContainerEventHandlerMixin {
+ /**
+ * This mixin is used to prevent the tab bar from being focused when navigating left or right
+ * through the YACL options screen. This can also apply to vanilla as navigating left or right
+ * should never result in focusing the always-at-the-top tab bar.
+ * Without this, navigating right from the option list focuses the tab bar, not the action buttons/description.
+ */
+ @Redirect(method = {"nextFocusPathVaguelyInDirection", "nextFocusPathInDirection"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/events/ContainerEventHandler;children()Ljava/util/List;"))
+ private List<?> modifyFocusCandidates(ContainerEventHandler instance, ScreenRectangle screenArea, ScreenDirection direction, @Nullable GuiEventListener focused, FocusNavigationEvent event) {
+ if (direction.getAxis() == ScreenAxis.HORIZONTAL)
+ return instance.children().stream().filter(child -> !(child instanceof TabNavigationBar)).toList();
+ return instance.children();
+ }
+}
diff --git a/common/src/main/resources/yacl.mixins.json b/common/src/main/resources/yacl.mixins.json
index 521e7d6..71d69ca 100644
--- a/common/src/main/resources/yacl.mixins.json
+++ b/common/src/main/resources/yacl.mixins.json
@@ -7,6 +7,7 @@
},
"client": [
"AbstractSelectionListMixin",
+ "ContainerEventHandlerMixin",
"MinecraftMixin",
"OptionInstanceAccessor"
]