From dffdc3b65f3643192cb08cbfa3d05067ebcd9f30 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sat, 27 Aug 2022 20:53:50 +0200 Subject: Implement safe server icon --- .../nochatreports/config/NCRClientConfig.java | 35 ++++++++++- .../mixins/client/MixinOnlineServerEntry.java | 69 +++++++++++++++++++++ .../resources/assets/nochatreports/lang/en_us.json | 1 + .../nochatreports/textures/gui/verified_server.png | Bin 0 -> 237 bytes src/main/resources/nochatreports.mixins.json | 3 +- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/aizistral/nochatreports/mixins/client/MixinOnlineServerEntry.java create mode 100644 src/main/resources/assets/nochatreports/textures/gui/verified_server.png (limited to 'src') diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java b/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java index 004ef83..0ab4db9 100644 --- a/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java +++ b/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java @@ -17,7 +17,8 @@ public final class NCRClientConfig extends JSONConfig { protected boolean demandOnServer = false, showServerSafety = true, hideRedChatIndicators = true, hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true, alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true, - whitelistAllServers = false; + whitelistAllServers = false, verifiedIconEnabled = true; + protected int verifiedIconOffsetX = 0, verifiedIconOffsetY = 0; protected List whitelistedServers = DEFAULT_WHITELISTED_SERVERS; protected NCRClientConfig() { @@ -155,8 +156,8 @@ public final class NCRClientConfig extends JSONConfig { /** * @return True if the full-screen warning should be skipped for servers that require chat signing, - * letting users simply join the server. Because of that, servers will no longer be added to the whitelist. - *

+ * letting users simply join the server. Because of that, servers will no longer be added to the + * whitelist.

* * This is false by default. */ @@ -165,4 +166,32 @@ public final class NCRClientConfig extends JSONConfig { return this.whitelistAllServers; } + /** + * @return True if "Safe Server" icon should be displayed in multiplayer menu for servers that + * declare themselves as preventing chat reports.

+ * + * This is true by default. + */ + + public boolean verifiedIconEnabled() { + return this.verifiedIconEnabled; + } + + + /** + * @return X offset for "Safe Server" icon in multiplayer menu. + */ + + public int getVerifiedIconOffsetX() { + return 16 + this.verifiedIconOffsetX; + } + + /** + * @return Y offset for "Safe Server" icon in multiplayer menu. + */ + + public int getVerifiedIconOffsetY() { + return 12 + this.verifiedIconOffsetY; + } + } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOnlineServerEntry.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOnlineServerEntry.java new file mode 100644 index 0000000..9354e7e --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOnlineServerEntry.java @@ -0,0 +1,69 @@ +package com.aizistral.nochatreports.mixins.client; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +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.aizistral.nochatreports.NoChatReports; +import com.aizistral.nochatreports.NoChatReportsClient; +import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.core.ServerDataExtension; +import com.aizistral.nochatreports.gui.FontHelper; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; +import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Tuple; + +@Mixin(ServerSelectionList.OnlineServerEntry.class) +public abstract class MixinOnlineServerEntry extends ServerSelectionList.Entry { + private static final ResourceLocation VERIFIED_ICON = new ResourceLocation("nochatreports", "textures/gui/verified_server.png"); + + @Shadow @Final + private JoinMultiplayerScreen screen; + @Shadow @Final + private Minecraft minecraft; + @Shadow @Final + private ServerData serverData; + + @Inject(method = "render", at = @At("RETURN")) + private void onRender(PoseStack poseStack, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f, CallbackInfo info) { + if (!NCRConfig.getClient().verifiedIconEnabled()) + return; + + if (this.serverData.ping > 0 && ((ServerDataExtension) this.serverData).preventsChatReports()) { + int xOffset = NCRConfig.getClient().getVerifiedIconOffsetX(), + yOffset = NCRConfig.getClient().getVerifiedIconOffsetY(); + + RenderSystem.setShaderTexture(0, VERIFIED_ICON); + RenderSystem.enableBlend(); + GuiComponent.blit(poseStack, k + l - 35 + xOffset, j - 1 + yOffset, 0.0f, 0.0f, 14, 14, 14, 14); + RenderSystem.disableBlend(); + + int t = n - k; + int u = o - j; + if (t >= l - 35 + xOffset && t <= l - 22 + xOffset && u >= 0 + yOffset && u <= 11 + yOffset) { + this.screen.setToolTip(FontHelper.wrap(this.minecraft.font, Language.getInstance() + .getOrDefault("gui.nochatreports.verified_server"), 250).stream() + .map(Component::literal).collect(Collectors.toCollection(() -> + new ArrayList()))); + } + } + } + +} diff --git a/src/main/resources/assets/nochatreports/lang/en_us.json b/src/main/resources/assets/nochatreports/lang/en_us.json index 2dac977..195e4ed 100644 --- a/src/main/resources/assets/nochatreports/lang/en_us.json +++ b/src/main/resources/assets/nochatreports/lang/en_us.json @@ -12,6 +12,7 @@ "gui.nochatreports.unsafe_server.contents": "This server requires all chat messages to be signed, which means they can be reported to Mojang, which may result in a ban from all multiplayer servers. This likely means that the server owner kept \"enforce-secure-profile\" enabled in the server.properties, which is the default since 1.19.1. You can choose to play anyway, but No Chat Reports will not be able to protect you.", "gui.nochatreports.unsafe_server.check": "Do not show again for this server", "gui.nochatrepords.reload_config_tooltip": "Reload No Chat Reports config. Use carefully.", + "gui.nochatreports.verified_server": "§a§lSafe Server§r\nWe could verify that this server has No Chat Reports installed, or prevents chat reports in some other known way. You can chat there safely.", "configuration.NoChatReports.config": "No Chat Reports", "configuration.NoChatReports.category.visual": "Visual", diff --git a/src/main/resources/assets/nochatreports/textures/gui/verified_server.png b/src/main/resources/assets/nochatreports/textures/gui/verified_server.png new file mode 100644 index 0000000..b8dcf7a Binary files /dev/null and b/src/main/resources/assets/nochatreports/textures/gui/verified_server.png differ diff --git a/src/main/resources/nochatreports.mixins.json b/src/main/resources/nochatreports.mixins.json index c4f4fd0..113959c 100644 --- a/src/main/resources/nochatreports.mixins.json +++ b/src/main/resources/nochatreports.mixins.json @@ -29,7 +29,8 @@ "client.MixinToastComponent", "client.MixinRealmsConnect", "client.MixinServerData", - "client.MixinServerStatusPinger$1" + "client.MixinServerStatusPinger$1", + "client.MixinOnlineServerEntry" ], "server": [ "server.MixinDedicatedServer" -- cgit v1.2.3