summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/aizistral
diff options
context:
space:
mode:
authorAizistral2022-08-27 20:53:50 +0200
committerAizistral2022-08-27 20:53:50 +0200
commitdffdc3b65f3643192cb08cbfa3d05067ebcd9f30 (patch)
tree30c4f71b17acaf7b78ae1156300f0108521779b0 /src/main/java/com/aizistral
parentb1fc3a9cd23388a7dddcc6f7ebe8736cfbb7ad78 (diff)
Implement safe server icon
Diffstat (limited to 'src/main/java/com/aizistral')
-rw-r--r--src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java35
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinOnlineServerEntry.java69
2 files changed, 101 insertions, 3 deletions
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<String> 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.
- * <br><br>
+ * letting users simply join the server. Because of that, servers will no longer be added to the
+ * whitelist.<br><br>
*
* 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.<br><br>
+ *
+ * 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<Component>())));
+ }
+ }
+ }
+
+}