diff options
| author | Aizistral | 2022-06-25 18:38:39 +0200 |
|---|---|---|
| committer | Aizistral | 2022-06-25 18:39:21 +0200 |
| commit | ef3ef035b4de19d153b82b1a375d6018c86c0f55 (patch) | |
| tree | abd434643db4d9a710ba2fad1ef70fa149340fc9 | |
| parent | 1cd9c62b1701b0a6b71527535b0f1d046d911d04 (diff) | |
Disable report button on client
3 files changed, 69 insertions, 1 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java new file mode 100644 index 0000000..b50ce21 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java @@ -0,0 +1,66 @@ +package com.aizistral.nochatreports.mixins; + +import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.function.Supplier; + +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; + +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.screens.reporting.ChatReportScreen; +import net.minecraft.client.gui.screens.social.PlayerEntry; +import net.minecraft.client.gui.screens.social.SocialInteractionsScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FormattedCharSequence; + +@Mixin(PlayerEntry.class) +public class MixinPlayerEntry { + private static final Component NCR_BUTTON_TOOLTIP = Component.translatable("gui.nochatreport.noReporting"); + @Shadow @Final private static ResourceLocation REPORT_BUTTON_LOCATION; + @Shadow private Button reportButton; + @Shadow float tooltipHoverTime; + + @Shadow + static void postRenderTooltip(SocialInteractionsScreen socialInteractionsScreen, PoseStack poseStack, List<FormattedCharSequence> list, int i, int j) { + throw new IllegalStateException("@Shadow transformation failed. Should never happen."); + } + + /** + * @reason Disable chat report button if we are on client. + * @author Aizistral + */ + + @Inject(method = "<init>", at = @At("RETURN")) + private void onConstructed(Minecraft minecraft, SocialInteractionsScreen socialInteractionsScreen, UUID uUID, String string, Supplier<ResourceLocation> supplier, CallbackInfo info) { + if (this.reportButton != null) { + this.reportButton = new ImageButton(0, 0, 20, 20, 0, 0, 20, REPORT_BUTTON_LOCATION, 64, 64, button -> {}, new Button.OnTooltip() { + @Override + public void onTooltip(Button button, PoseStack poseStack, int i, int j) { + MixinPlayerEntry.this.tooltipHoverTime += minecraft.getDeltaFrameTime(); + if (MixinPlayerEntry.this.tooltipHoverTime >= 10.0f) { + socialInteractionsScreen.setPostRenderRunnable(() -> postRenderTooltip(socialInteractionsScreen, poseStack, minecraft.font.split(NCR_BUTTON_TOOLTIP, 150), i, j)); + } + } + + @Override + public void narrateTooltip(Consumer<Component> consumer) { + consumer.accept(NCR_BUTTON_TOOLTIP); + } + }, Component.translatable("gui.socialInteractions.report")); + this.reportButton.active = false; + } + } + +} diff --git a/src/main/resources/assets/nochatreports/lang/en_us.json b/src/main/resources/assets/nochatreports/lang/en_us.json index d1ff40d..9582dc7 100644 --- a/src/main/resources/assets/nochatreports/lang/en_us.json +++ b/src/main/resources/assets/nochatreports/lang/en_us.json @@ -1,4 +1,5 @@ { "gui.nochatreport.secureChat": "This option cannot work with No Chat Reports, since there are no signatures to verify.", + "gui.nochatreport.noReporting": "Chat reports are disabled on this server, courtesy of No Chat Reports.", "disconnect.nochatreports.client": "This server does not have No Chat Reports, and you have it configured to require itself on server." }
\ No newline at end of file diff --git a/src/main/resources/nochatreports.mixins.json b/src/main/resources/nochatreports.mixins.json index c81b80e..f0fd081 100644 --- a/src/main/resources/nochatreports.mixins.json +++ b/src/main/resources/nochatreports.mixins.json @@ -16,7 +16,8 @@ "MixinProfileKeyPairManager", "MixinClientTelemetryManager", "MixinTitleScreen", - "MixinMinecraft" + "MixinMinecraft", + "MixinPlayerEntry" ], "server": [ "MixinDedicatedServer" |
