From 34b3d044e5a3bd7fdaaca8245ea672807e478940 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sun, 15 Sep 2024 02:38:30 +0200 Subject: [PATCH] fix modmenu button overlap --- .../mixin/ModMenuEventHandlerVRMixin.java | 49 +++++++++++++++++++ .../resources/vivecraft.modmenu.mixins.json | 1 + 2 files changed, 50 insertions(+) create mode 100644 common/src/main/java/org/vivecraft/mod_compat_vr/modmenu/mixin/ModMenuEventHandlerVRMixin.java diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/modmenu/mixin/ModMenuEventHandlerVRMixin.java b/common/src/main/java/org/vivecraft/mod_compat_vr/modmenu/mixin/ModMenuEventHandlerVRMixin.java new file mode 100644 index 000000000..890755ce8 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/modmenu/mixin/ModMenuEventHandlerVRMixin.java @@ -0,0 +1,49 @@ +package org.vivecraft.mod_compat_vr.modmenu.mixin; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.contents.TranslatableContents; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.vivecraft.client_vr.VRState; + +@Pseudo +@Mixin(targets = "com.terraformersmc.modmenu.event.ModMenuEventHandler") +public abstract class ModMenuEventHandlerVRMixin { + + @Inject(method = "afterGameMenuScreenInit", at = @At("TAIL")) + private static void vivecraft$modifyButtons(Screen screen, CallbackInfo ci) { + if (VRState.vrInitialized) { + Button modmenuButton = null; + Button commandsButton = null; + Button reportBugsButton = null; + for (GuiEventListener guiEventListener : screen.children()) { + if (guiEventListener instanceof Button button) { + if (button.getMessage().getContents() instanceof TranslatableContents contents + && "modmenu.title".equals(contents.getKey())) { + modmenuButton = button; + } else if (button.getMessage().getContents() instanceof TranslatableContents contents + && "vivecraft.gui.commands".equals(contents.getKey())) { + commandsButton = button; + } else if (button.getMessage().getContents() instanceof TranslatableContents contents + && "menu.reportBugs".equals(contents.getKey())) { + reportBugsButton = button; + } + } + } + + // make sure we found the buttons, and they are actually overlapping + if (reportBugsButton == null && modmenuButton != null && commandsButton != null + && modmenuButton.x == commandsButton.x + && modmenuButton.y == commandsButton.y) { + modmenuButton.setWidth(modmenuButton.getWidth() / 2 - 1); + commandsButton.setWidth(commandsButton.getWidth() / 2); + modmenuButton.x = commandsButton.x + commandsButton.getWidth() + 1; + } + } + } +} diff --git a/common/src/main/resources/vivecraft.modmenu.mixins.json b/common/src/main/resources/vivecraft.modmenu.mixins.json index 6c590ae41..696f1d8c7 100644 --- a/common/src/main/resources/vivecraft.modmenu.mixins.json +++ b/common/src/main/resources/vivecraft.modmenu.mixins.json @@ -4,6 +4,7 @@ "plugin": "org.vivecraft.MixinConfig", "compatibilityLevel": "JAVA_17", "client": [ + "ModMenuEventHandlerVRMixin", "PauseScreenVRModMenuMixin" ], "minVersion": "0.8.4"