From 233c6de9b2220ac91f481a82ea029347aee3f2e1 Mon Sep 17 00:00:00 2001 From: Kevinthegreat Date: Sat, 30 Jul 2022 15:52:24 +0800 Subject: Disable Only Show Secure Chat button --- .../mixins/client/MixinChatOptionsScreen.java | 64 ++++++++++++++++++++++ .../nochatreports/mixins/client/MixinOptions.java | 36 ------------ 2 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java delete mode 100644 src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java (limited to 'src/main/java/com/aizistral') 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..3163908 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java @@ -0,0 +1,64 @@ +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 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); + } + + /** + * 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(); + onlyShowSecureChat = list.findOption(Minecraft.getInstance().options.onlyShowSecureChat()); + if (onlyShowSecureChat != null) { + 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 (onlyShowSecureChat != null && onlyShowSecureChat.visible && x >= (double) onlyShowSecureChat.x && y >= (double) onlyShowSecureChat.y && x < (double) (onlyShowSecureChat.x + onlyShowSecureChat.getWidth()) && y < (double) (onlyShowSecureChat.y + onlyShowSecureChat.getHeight())) { + renderTooltip(poseStack, 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 deleted file mode 100644 index 08e94db..0000000 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.aizistral.nochatreports.mixins.client; - -import com.google.common.collect.ImmutableList; -import com.mojang.serialization.Codec; -import net.minecraft.client.OptionInstance; -import net.minecraft.client.Options; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(Options.class) -public class MixinOptions { - private OptionInstance 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. - * @author Aizistral - */ - - @Inject(method = "onlyShowSecureChat", at = @At("RETURN"), cancellable = true) - private void onlyShowSecureChat(CallbackInfoReturnable> cir) { - if (this.alternativeOption == null) { - this.alternativeOption = new OptionInstance<>("options.onlyShowSecureChat", - OptionInstance.cachedConstantTooltip(Component.translatable("gui.nochatreport.secureChat")), - (component, value) -> value ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF, - new OptionInstance.Enum<>(ImmutableList.of(Boolean.FALSE), Codec.BOOL), false, (value) -> {}); - } - - cir.setReturnValue(this.alternativeOption); - } - -} -- cgit v1.2.3 From 05125d6f21b5cce6ab15668ef8c7484e92c2b5b1 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sat, 30 Jul 2022 13:01:40 +0200 Subject: Return `MixinOptions` --- .../nochatreports/mixins/client/MixinOptions.java | 36 ++++++++++++++++++++++ src/main/resources/nochatreports.mixins.json | 1 + 2 files changed, 37 insertions(+) create mode 100644 src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java (limited to 'src/main/java/com/aizistral') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java new file mode 100644 index 0000000..3c26b86 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java @@ -0,0 +1,36 @@ + +package com.aizistral.nochatreports.mixins.client; + +import com.google.common.collect.ImmutableList; +import com.mojang.serialization.Codec; +import net.minecraft.client.OptionInstance; +import net.minecraft.client.Options; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Options.class) +public class MixinOptions { + private OptionInstance alternativeOption; + + /** + * @reason Disable secure chat option, since it will not work anyways. + * @author Aizistral + */ + + @Inject(method = "onlyShowSecureChat", at = @At("RETURN"), cancellable = true) + private void onlyShowSecureChat(CallbackInfoReturnable> cir) { + if (this.alternativeOption == null) { + this.alternativeOption = new OptionInstance<>("options.onlyShowSecureChat", + OptionInstance.cachedConstantTooltip(Component.translatable("gui.nochatreport.secureChat")), + (component, value) -> value ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF, + new OptionInstance.Enum<>(ImmutableList.of(Boolean.FALSE), Codec.BOOL), false, (value) -> {}); + } + + cir.setReturnValue(this.alternativeOption); + } + +} \ No newline at end of file diff --git a/src/main/resources/nochatreports.mixins.json b/src/main/resources/nochatreports.mixins.json index bfe8a52..4e0f080 100644 --- a/src/main/resources/nochatreports.mixins.json +++ b/src/main/resources/nochatreports.mixins.json @@ -13,6 +13,7 @@ ], "client": [ "client.MixinLocalPlayer", + "client.MixinOptions", "client.MixinChatListener", "client.MixinChatOptionsScreen", "client.MixinProfileKeyPairManager", -- cgit v1.2.3 From 11f0c7df85fb2efa7bfd262cc3beb1dd854f60d0 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sat, 30 Jul 2022 13:05:22 +0200 Subject: Style changes --- .../mixins/client/MixinChatOptionsScreen.java | 87 +++++++++++----------- 1 file changed, 43 insertions(+), 44 deletions(-) (limited to 'src/main/java/com/aizistral') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java index 3163908..263abc0 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java @@ -17,48 +17,47 @@ 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 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); - } - - /** - * 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(); - onlyShowSecureChat = list.findOption(Minecraft.getInstance().options.onlyShowSecureChat()); - if (onlyShowSecureChat != null) { - 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 (onlyShowSecureChat != null && onlyShowSecureChat.visible && x >= (double) onlyShowSecureChat.x && y >= (double) onlyShowSecureChat.y && x < (double) (onlyShowSecureChat.x + onlyShowSecureChat.getWidth()) && y < (double) (onlyShowSecureChat.y + onlyShowSecureChat.getHeight())) { - renderTooltip(poseStack, secureChatTooltip, x, y); - } - } + 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 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); + } + } } -- cgit v1.2.3