diff options
| author | Aizistral | 2022-07-30 13:10:17 +0200 |
|---|---|---|
| committer | GitHub | 2022-07-30 13:10:17 +0200 |
| commit | dda647f43801ccb6b81937bb69df480dc73688b0 (patch) | |
| tree | 2f10d5e7923c1114f33bf308db67bce181d925b6 /src/main/java/com | |
| parent | fc4277593b2ddd1b415c6f5e34d87f9f5c615ed3 (diff) | |
| parent | 11f0c7df85fb2efa7bfd262cc3beb1dd854f60d0 (diff) | |
Merge pull request #117 from kevinthegreat1/1.19.1-Fabric-Port
Disable Only Show Secure Chat button
Diffstat (limited to 'src/main/java/com')
| -rw-r--r-- | src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java | 63 | ||||
| -rw-r--r-- | src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java | 6 |
2 files changed, 66 insertions, 3 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java new file mode 100644 index 0000000..263abc0 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java @@ -0,0 +1,63 @@ +package com.aizistral.nochatreports.mixins.client; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.OptionInstance; +import net.minecraft.client.Options; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.screens.ChatOptionsScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.SimpleOptionsSubScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; + +import java.util.List; + +@Mixin(ChatOptionsScreen.class) +public class MixinChatOptionsScreen extends SimpleOptionsSubScreen { + private AbstractWidget onlyShowSecureChat; + + /** + * @implNote Using {@link net.minecraft.client.gui.Font#split} because + * {@link net.minecraft.client.OptionInstance#splitTooltip(Minecraft, Component)} is protected. + * Field {@link net.minecraft.client.gui.screens.Screen#minecraft} is not used because it can be null. + * @author Kevinthegreat + */ + @SuppressWarnings({"JavaDoc", "JavadocReference"}) + private final List<FormattedCharSequence> secureChatTooltip = Minecraft.getInstance().font.split(Component.translatable("gui.nochatreport.secureChat"), 200); + + public MixinChatOptionsScreen(Screen screen, Options options, Component component, OptionInstance<?>[] optionInstances) { + super(screen, options, component, optionInstances); + throw new IllegalStateException("Can't touch this"); + } + + /** + * Gray out the only show secure chat option by deactivating the button when the screen is initialized. + * @author Kevinthegreat + */ + + @Override + protected void init() { + super.init(); + this.onlyShowSecureChat = this.list.findOption(Minecraft.getInstance().options.onlyShowSecureChat()); + if (this.onlyShowSecureChat != null) { + this.onlyShowSecureChat.active = false; + } + } + + /** + * Render the tooltip on mouseover for only show secure chat option. + * Minecraft only render tooltips when the widget is active. + * @author Kevinthegreat + */ + + @Override + public void render(@NotNull PoseStack poseStack, int x, int y, float f) { + super.render(poseStack, x, y, f); + if (this.onlyShowSecureChat != null && this.onlyShowSecureChat.visible && x >= (double) this.onlyShowSecureChat.x && y >= (double) this.onlyShowSecureChat.y && x < (double) (this.onlyShowSecureChat.x + this.onlyShowSecureChat.getWidth()) && y < (double) (this.onlyShowSecureChat.y + this.onlyShowSecureChat.getHeight())) { + this.renderTooltip(poseStack, this.secureChatTooltip, x, y); + } + } +} diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java index 08e94db..3c26b86 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java @@ -1,3 +1,4 @@ + package com.aizistral.nochatreports.mixins.client; import com.google.common.collect.ImmutableList; @@ -16,8 +17,7 @@ public class MixinOptions { private OptionInstance<Boolean> alternativeOption; /** - * @reason Disable secure chat option, since it will not work anyways. I would prefer to have - * the button greyed out instead, but there is no elegant solution to implement this. + * @reason Disable secure chat option, since it will not work anyways. * @author Aizistral */ @@ -33,4 +33,4 @@ public class MixinOptions { cir.setReturnValue(this.alternativeOption); } -} +}
\ No newline at end of file |
