aboutsummaryrefslogtreecommitdiff
path: root/src/client/java
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-02-08 21:29:52 +0000
committerisXander <xandersmith2008@gmail.com>2023-02-08 21:29:52 +0000
commita59cbd37a431d36ce077e78d402d51a2cb6fa7cb (patch)
treec1f3004872785ad90ff80fa5164e125b940594f3 /src/client/java
parent21380619fc01bde505cb0d468413120652ec3c51 (diff)
downloadYetAnotherConfigLib-a59cbd37a431d36ce077e78d402d51a2cb6fa7cb.tar.gz
YetAnotherConfigLib-a59cbd37a431d36ce077e78d402d51a2cb6fa7cb.tar.bz2
YetAnotherConfigLib-a59cbd37a431d36ce077e78d402d51a2cb6fa7cb.zip
fix ArrayIndexOutOfBoundsException when navigating to end of option list with keyboard/mouse navigation
Diffstat (limited to 'src/client/java')
-rw-r--r--src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java b/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java
new file mode 100644
index 0000000..978fd16
--- /dev/null
+++ b/src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java
@@ -0,0 +1,26 @@
+package dev.isxander.yacl.mixin.client;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.components.AbstractSelectionList;
+import org.objectweb.asm.Opcodes;
+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.Redirect;
+
+import java.util.List;
+
+@Mixin(AbstractSelectionList.class)
+public abstract class AbstractSelectionListMixin<E extends AbstractSelectionList.Entry<E>> {
+ @Shadow public abstract List<E> children();
+
+ /**
+ * Mojang use the field access of children to get max index to loop through keyboard navigation to find the next entry.
+ * YACL modifies these children() method to filter out hidden entries, so we need to redirect the field access to the
+ * method, so we don't get ArrayIndexOutOfBoundsException.
+ */
+ @Redirect(method = "nextEntry(Lnet/minecraft/client/gui/navigation/ScreenDirection;Ljava/util/function/Predicate;Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/components/AbstractSelectionList;children:Ljava/util/List;", opcode = Opcodes.GETFIELD))
+ private List<E> modifyChildrenCall(AbstractSelectionList<E> instance) {
+ return children();
+ }
+}