Skip to content

Commit

Permalink
fix modmenu button overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed Sep 15, 2024
1 parent af7f96f commit 34b3d04
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/vivecraft.modmenu.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"plugin": "org.vivecraft.MixinConfig",
"compatibilityLevel": "JAVA_17",
"client": [
"ModMenuEventHandlerVRMixin",
"PauseScreenVRModMenuMixin"
],
"minVersion": "0.8.4"
Expand Down

0 comments on commit 34b3d04

Please sign in to comment.