From d40d94a565dc7c9ed34972c877c6b90a75eda5dd Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 20 May 2024 07:52:38 -0500 Subject: [PATCH] Add probably broken AT OptionsScreen code Will probably break 1.20.2 and 1.20.4 --- .../1_20_2.distanthorizons.accesswidener | 3 + .../mixins/client/MixinOptionsScreen.java | 80 ++++++++++++++----- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/common/src/main/resources/1_20_2.distanthorizons.accesswidener b/common/src/main/resources/1_20_2.distanthorizons.accesswidener index c793fab68..a267d98a3 100644 --- a/common/src/main/resources/1_20_2.distanthorizons.accesswidener +++ b/common/src/main/resources/1_20_2.distanthorizons.accesswidener @@ -37,3 +37,6 @@ accessible field net/minecraft/client/gui/components/AbstractButton SPRITES Lnet accessible field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; mutable field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; accessible field net/minecraft/client/gui/components/AbstractSelectionList scrollAmount D # Hack to bypass vanilla's setScrollAmount's clamp + +# TODO add a separate 1.20.6 Access widner file, this is only present in 1.20.6 +accessible field net/minecraft/client/gui/screens/OptionsScreen layout Lnet/minecraft/client/gui/layouts/HeaderAndFooterLayout; 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 61b805be5..fc0bbdd70 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 @@ -23,6 +23,8 @@ import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen; import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget; import com.seibel.distanthorizons.coreapi.ModInfo; import com.seibel.distanthorizons.core.config.Config; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; import net.minecraft.client.gui.screens.OptionsScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -30,7 +32,9 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; #endif import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Final; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -46,36 +50,70 @@ import java.util.Objects; @Mixin(OptionsScreen.class) public class MixinOptionsScreen extends Screen { - // Get the texture for the button + /** Get the texture for the button */ private static final ResourceLocation ICON_TEXTURE = new ResourceLocation(ModInfo.ID, "textures/gui/button.png"); - protected MixinOptionsScreen(Component title) - { + + public final TexturedButtonWidget optionsButton; + + @Shadow + @Final + protected HeaderAndFooterLayout layout; + + + + protected MixinOptionsScreen(Component title) + { super(title); + + this.optionsButton = new TexturedButtonWidget( + // Where the button is on the screen + this.width / 2 - 180, this.height / 6 - 12, + // Width and height of the button + 20, 20, + // texture UV Offset + 0, 0, + // Some textuary stuff + 20, ICON_TEXTURE, 20, 40, + // Create the button and tell it where to go + // For now it goes to the client option by default + (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(GetConfigScreen.getScreen(this)), + // Add a title to the utton + #if MC_VER < MC_1_19_2 + new TranslatableComponent(ModInfo.ID + ".title"))); + #else + Component.translatable(ModInfo.ID + ".title")); + #endif } + + @Inject(at = @At("HEAD"), method = "init") private void lodconfig$init(CallbackInfo ci) { if (Config.Client.optionsButton.get()) + { this. #if MC_VER < MC_1_17_1 addButton #else addRenderableWidget #endif - (new TexturedButtonWidget( - // Where the button is on the screen - this.width / 2 - 180, this.height / 6 - 12, - // Width and height of the button - 20, 20, - // Offset - 0, 0, - // Some textuary stuff - 20, ICON_TEXTURE, 20, 40, - // Create the button and tell it where to go - // For now it goes to the client option by default - (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(GetConfigScreen.getScreen(this)), - // Add a title to the utton - #if MC_VER < MC_1_19_2 - new TranslatableComponent(ModInfo.ID + ".title"))); - #else - Component.translatable(ModInfo.ID + ".title"))); - #endif + (this.optionsButton); + + // TODO we need to add optionsButton to the UI via the layout instead so it centers correctly + // This wasn't working on James' machine + this.layout.visitChildren((x) -> + { + System.out.println(x); + }); + + } } + + //@Inject(method = "Lnet/minecraft/client/gui/screens/Screen;render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V", at = @At(value = "INVOKE")) + //public void renderStuff(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) + //{ + // int newWidth = this.width / 2 - 180; + // if (this.optionsButton.getX() != newWidth) + // { + // this.optionsButton.setX(newWidth); + // } + //} + }