diff options
author | isXander <xandersmith2008@gmail.com> | 2023-06-03 23:10:03 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-06-04 16:25:09 +0100 |
commit | 3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb (patch) | |
tree | f9c3395b4da2235681b87a35ac5056a0724a181b /common/src/main/java/dev/isxander/yacl3/mixin | |
parent | d00a486d3bdf6105f8ca8af1034c384058b8c832 (diff) | |
download | YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.tar.gz YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.tar.bz2 YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.zip |
Change package and modid to yacl3 and yet_another_config_lib_3 respectively
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/mixin')
4 files changed, 85 insertions, 0 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/mixin/AbstractSelectionListMixin.java b/common/src/main/java/dev/isxander/yacl3/mixin/AbstractSelectionListMixin.java new file mode 100644 index 0000000..471fa19 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/mixin/AbstractSelectionListMixin.java @@ -0,0 +1,25 @@ +package dev.isxander.yacl3.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/yacl3/mixin/ContainerEventHandlerMixin.java b/common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java new file mode 100644 index 0000000..37f0c33 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java @@ -0,0 +1,31 @@ +package dev.isxander.yacl3.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/java/dev/isxander/yacl3/mixin/MinecraftMixin.java b/common/src/main/java/dev/isxander/yacl3/mixin/MinecraftMixin.java new file mode 100644 index 0000000..5bc22ab --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/mixin/MinecraftMixin.java @@ -0,0 +1,16 @@ +package dev.isxander.yacl3.mixin; + +import dev.isxander.yacl3.gui.ImageRenderer; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class MinecraftMixin { + @Inject(method = "close", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/telemetry/ClientTelemetryManager;close()V")) + private void closeImages(CallbackInfo ci) { + ImageRenderer.closeAll(); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/mixin/OptionInstanceAccessor.java b/common/src/main/java/dev/isxander/yacl3/mixin/OptionInstanceAccessor.java new file mode 100644 index 0000000..429e383 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/mixin/OptionInstanceAccessor.java @@ -0,0 +1,13 @@ +package dev.isxander.yacl3.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(); +} |