From 4998991ebe602d88823fc9b0e215aa86fc983118 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 21 May 2024 07:12:04 -0500 Subject: [PATCH] Fix option button in 1.20.6 being on the wrong side --- .../fabric/mixins/client/MixinOptionsScreen.java | 10 ++++++++-- .../neoforge/mixins/client/MixinOptionsScreen.java | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java index ed2274cf6..7c4116b6d 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java @@ -39,6 +39,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; #if MC_VER == MC_1_20_6 import net.minecraft.client.gui.layouts.LinearLayout; @@ -92,9 +93,14 @@ public class MixinOptionsScreen extends Screen // add the button to the correct location in the UI // TODO is there a better way to do this instead of using access transformers to inject into the exact UI elements? - // TODO is there a way we can put the button on the left side of the FOV bar like before? LinearLayout layout = (LinearLayout) this.layout.headerFrame.children.get(0).child; - layout.wrapped.addChild(this.getOptionsButton(), 1, 2); + + // determine how wide the other option buttons are so we can put our botton to the left of them all + AtomicInteger width = new AtomicInteger(0); + layout.visitChildren(x -> { width.addAndGet(x.getWidth()); }); + width.addAndGet(-10); // padding between the DH button and the FOV slider + + layout.wrapped.addChild(this.getOptionsButton(), 1, 2, (settings) -> { settings.paddingLeft(width.get() * -1); }); layout.arrangeElements(); #endif diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java index 1270fc0f8..983b446dd 100644 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java @@ -39,6 +39,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; #if MC_VER == MC_1_20_6 import net.minecraft.client.gui.layouts.LinearLayout; @@ -94,7 +95,13 @@ public class MixinOptionsScreen extends Screen // TODO is there a better way to do this instead of using access transformers to inject into the exact UI elements? // TODO is there a way we can put the button on the left side of the FOV bar like before? LinearLayout layout = (LinearLayout) this.layout.headerFrame.children.get(0).child; - layout.wrapped.addChild(this.getOptionsButton(), 1, 2); + + // determine how wide the other option buttons are so we can put our botton to the left of them all + AtomicInteger width = new AtomicInteger(0); + layout.visitChildren(x -> { width.addAndGet(x.getWidth()); }); + width.addAndGet(-10); // padding between the DH button and the FOV slider + + layout.wrapped.addChild(this.getOptionsButton(), 1, 2, (settings) -> { settings.paddingLeft(width.get() * -1); }); layout.arrangeElements(); #endif