aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl/mixin
diff options
context:
space:
mode:
authorXander <xander@isxander.dev>2023-04-25 16:28:41 +0100
committerGitHub <noreply@github.com>2023-04-25 16:28:41 +0100
commit13c7ba45ff201423eb8dba8a40cfb66ebb531439 (patch)
tree1e799aa9da11fbc0833bc6b7c6e6799633c2ec50 /common/src/main/java/dev/isxander/yacl/mixin
parent8ba7196ae990fe9aa98680aba1b387e385fff99c (diff)
downloadYetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.gz
YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.bz2
YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.zip
Architectury! (#61)
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl/mixin')
-rw-r--r--common/src/main/java/dev/isxander/yacl/mixin/AbstractSelectionListMixin.java25
-rw-r--r--common/src/main/java/dev/isxander/yacl/mixin/OptionInstanceAccessor.java13
2 files changed, 38 insertions, 0 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/mixin/AbstractSelectionListMixin.java b/common/src/main/java/dev/isxander/yacl/mixin/AbstractSelectionListMixin.java
new file mode 100644
index 0000000..1b53e96
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl/mixin/AbstractSelectionListMixin.java
@@ -0,0 +1,25 @@
+package dev.isxander.yacl.mixin;
+
+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();
+ }
+}
diff --git a/common/src/main/java/dev/isxander/yacl/mixin/OptionInstanceAccessor.java b/common/src/main/java/dev/isxander/yacl/mixin/OptionInstanceAccessor.java
new file mode 100644
index 0000000..4eea9a9
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl/mixin/OptionInstanceAccessor.java
@@ -0,0 +1,13 @@
+package dev.isxander.yacl.mixin;
+
+import net.minecraft.client.OptionInstance;
+import org.jetbrains.annotations.ApiStatus;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@ApiStatus.Internal
+@Mixin(OptionInstance.class)
+public interface OptionInstanceAccessor<T> {
+ @Accessor
+ T getInitialValue();
+}