From b35ce70b496f53181f9254a45d22594afc57531b Mon Sep 17 00:00:00 2001 From: Onako2 <79749977+Onako2@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:40:55 +0100 Subject: [PATCH 1/4] Fabric: It runs --- gradle.properties | 18 ++++---- .../common/core/ServerSafetyState.java | 25 +++++++---- .../common/gui/AdvancedImageButton.java | 7 +--- .../common/gui/AdvancedTooltip.java | 42 +++++++------------ .../common/gui/EncryptionConfigScreen.java | 17 +++----- .../client/AccessorClientPacketListener.java | 9 ++-- .../mixins/client/MixinOnlineServerEntry.java | 26 ++++++------ .../mixins/client/MixinTitleScreen.java | 25 ++++------- .../mixins/client/MixinToastComponent.java | 14 +++---- src/main/resources/fabric.mod.json | 4 +- 10 files changed, 81 insertions(+), 106 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1da81078..339d4f65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false # Toolchain Properties -minecraft_version=1.21 -yarn_mappings=1.21+build.2 +minecraft_version=1.21.3 +yarn_mappings=1.21.3+build.2 fabric_loader_version=0.15.11 -forge_version=1.21-51.0.8 -neoforge_version=21.0.16-beta +forge_version=1.21.3-53.0.4 +neoforge_version=21.3.4-beta # Mod Properties -mod_version=1.21-v2.8.0 +mod_version=1.21.3-v2.9.0 maven_group=com.aizistral.nochatreports archives_base_name=NoChatReports-FABRIC mod_id=nochatreports @@ -23,12 +23,12 @@ mod_icon=assets/nochatreports/textures/misc/ncr_logo.png mod_license=WTFPL # Dependencies -fabric_version=0.100.3+1.21 -mod_menu_version=11.0.0-rc.4 -cloth_config_version=15.0.127 +fabric_version=0.107.0+1.21.3 +mod_menu_version=12.0.0-beta.1 +cloth_config_version=16.0.141 # Dependencies in mods.toml -dep_forge=[47,) +dep_forge=[53,) dep_neoforge=[21.0.0,) dep_minecraft=[1.21,) diff --git a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java index 366811fb..c81ce9b9 100644 --- a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java +++ b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java @@ -1,18 +1,18 @@ package com.aizistral.nochatreports.common.core; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.jetbrains.annotations.Nullable; - import com.aizistral.nochatreports.common.gui.UnsafeServerScreen; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.resolver.ServerAddress; +import net.minecraft.network.chat.LocalChatSession; +import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicBoolean; /** * All this global state is questionable, but we have to... @@ -47,7 +47,14 @@ public static CompletableFuture setAllowChatSigning(boolean allow) { if (allow && connection.chatSession == null) return Minecraft.getInstance().getProfileKeyPairManager().prepareKeyPair() .thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair -> { - connection.setKeyPair(profileKeyPair); + Minecraft minecraft = Minecraft.getInstance(); + if (minecraft.isLocalPlayer(minecraft.getGameProfile().getId())) { + if (connection.chatSession == null || !connection.chatSession.keyPair().equals(profileKeyPair)) { + connection.chatSession = LocalChatSession.create(profileKeyPair); + connection.signedMessageEncoder = connection.chatSession.createMessageEncoder(minecraft.getGameProfile().getId()); + connection.send(new ServerboundChatSessionUpdatePacket(connection.chatSession.asRemote().asData())); + } + } SIGNING_ACTIONS.forEach(Runnable::run); SIGNING_ACTIONS.clear(); }), Minecraft.getInstance()); diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedImageButton.java b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedImageButton.java index 47f913b0..54714c99 100644 --- a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedImageButton.java +++ b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedImageButton.java @@ -1,15 +1,12 @@ package com.aizistral.nochatreports.common.gui; -import com.mojang.blaze3d.vertex.PoseStack; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.client.gui.components.WidgetSprites; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -40,7 +37,7 @@ public ResourceLocation getCurrentTexture() { @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - graphics.blitSprite(this.getCurrentTexture(), this.getX(), this.getY(), this.width, this.height); + graphics.blitSprite(RenderType::guiTextured, this.getCurrentTexture(), this.getX(), this.getY(), this.width, this.height); if (this.isHovered) if (this.tooltip instanceof AdvancedWidgetTooltipHolder holder && holder.hasCustomRender()) { diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java index 67d26bf9..f8706284 100644 --- a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java +++ b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java @@ -1,38 +1,23 @@ package com.aizistral.nochatreports.common.gui; -import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import org.joml.Vector2ic; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.BufferUploader; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.tooltip.BelowOrAboveWidgetTooltipPositioner; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner; -import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; -import net.minecraft.client.gui.screens.inventory.tooltip.MenuTooltipPositioner; import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; +import org.jetbrains.annotations.Nullable; +import org.joml.Vector2ic; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; @Environment(EnvType.CLIENT) public class AdvancedTooltip extends Tooltip { @@ -111,7 +96,7 @@ protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, L if (m > k) { k = m; } - l += clientTooltipComponent.getHeight(); + l += clientTooltipComponent.getHeight(screen.font); } int n = k; int o = l; @@ -120,19 +105,20 @@ protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, L int q = vector2ic.y(); graphics.pose().pushPose(); int r = 400; - graphics.drawManaged(() -> TooltipRenderUtil.renderTooltipBackground(graphics, p, q, n, o, 400)); + TooltipRenderUtil.renderTooltipBackground(graphics, p, q, n, o, 400, ResourceLocation.withDefaultNamespace("textures/gui/sprites/tooltip/background.png")); graphics.pose().translate(0.0f, 0.0f, 400.0f); int s = q; for (t = 0; t < list.size(); ++t) { clientTooltipComponent2 = list.get(t); - clientTooltipComponent2.renderText(screen.font, p, s, graphics.pose().last().pose(), graphics.bufferSource()); - s += clientTooltipComponent2.getHeight() + /*(t == 0 ? 2 : 0)*/ 0; + // TODO: Fix this +// clientTooltipComponent2.renderText(screen.font, p, s, graphics.pose().last().pose(), graphics.bufferSource()); + s += clientTooltipComponent2.getHeight(screen.font) + /*(t == 0 ? 2 : 0)*/ 0; } s = q; for (t = 0; t < list.size(); ++t) { clientTooltipComponent2 = list.get(t); - clientTooltipComponent2.renderImage(screen.font, p, s, graphics); - s += clientTooltipComponent2.getHeight() + /*(t == 0 ? 2 : 0)*/ 0; + clientTooltipComponent2.renderImage(screen.font, p, s, 0, 0, graphics); + s += clientTooltipComponent2.getHeight(screen.font) + /*(t == 0 ? 2 : 0)*/ 0; } graphics.pose().popPose(); } diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java b/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java index 9e0e3007..3fad5a4d 100644 --- a/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java +++ b/src/main/java/com/aizistral/nochatreports/common/gui/EncryptionConfigScreen.java @@ -1,30 +1,23 @@ package com.aizistral.nochatreports.common.gui; -import java.util.Objects; - import com.aizistral.nochatreports.common.config.NCRConfig; import com.aizistral.nochatreports.common.config.NCRConfigEncryption; import com.aizistral.nochatreports.common.encryption.Encryption; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Checkbox; -import net.minecraft.client.gui.components.CycleButton; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.ImageButton; -import net.minecraft.client.gui.components.MultiLineLabel; -import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.gui.components.*; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.StringUtil; +import java.util.Objects; + @Environment(EnvType.CLIENT) public class EncryptionConfigScreen extends Screen { private static final Component HEADER = Component.translatable("gui.nochatreports.encryption_config.header"); @@ -200,7 +193,7 @@ public void render(GuiGraphics graphics, int i, int j, float f) { graphics.drawString(this.font, PASS_NOT_ALLOWED, this.passField.getX() + 4, this.passField.getY() + 5, 0x999999); RenderSystem.enableDepthTest(); - graphics.blitSprite(CROSSMARK, this.passField.getX() - 20, this.passField.getY() + 3, 14, 13); + graphics.blitSprite(RenderType::guiTextured, CROSSMARK, this.passField.getX() - 20, this.passField.getY() + 3, 14, 13); } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/AccessorClientPacketListener.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/AccessorClientPacketListener.java index caeccd89..ddca5eee 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/AccessorClientPacketListener.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/AccessorClientPacketListener.java @@ -1,12 +1,11 @@ package com.aizistral.nochatreports.common.mixins.client; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - import com.mojang.brigadier.ParseResults; - import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.world.entity.player.ProfileKeyPair; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(ClientPacketListener.class) public interface AccessorClientPacketListener { @@ -14,4 +13,6 @@ public interface AccessorClientPacketListener { @Invoker("parseCommand") public ParseResults invokeParseCommand(String string); + @Invoker("setKeyPair") + public void invokeSetKeyPair(ProfileKeyPair profileKeyPair); } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinOnlineServerEntry.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinOnlineServerEntry.java index 2842cbdc..bbea9fdc 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinOnlineServerEntry.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinOnlineServerEntry.java @@ -1,33 +1,33 @@ package com.aizistral.nochatreports.common.mixins.client; -import java.util.ArrayList; -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.common.config.NCRConfig; import com.aizistral.nochatreports.common.core.ServerDataExtension; import com.aizistral.nochatreports.common.gui.FontHelper; import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; - import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; 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.client.renderer.RenderType; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.stream.Collectors; @Mixin(ServerSelectionList.OnlineServerEntry.class) public abstract class MixinOnlineServerEntry extends ServerSelectionList.Entry { + @Unique private static final ResourceLocation VERIFIED_ICON = ResourceLocation.fromNamespaceAndPath("nochatreports", "verified_server"); @Shadow @Final @@ -47,7 +47,7 @@ private void onRender(GuiGraphics graphics, int i, int j, int k, int l, int m, i yOffset = NCRConfig.getClient().getVerifiedIconOffsetY(); RenderSystem.enableBlend(); - graphics.blitSprite(VERIFIED_ICON, k + l - 35 + xOffset, j - 1 + yOffset, 14, 14); + graphics.blitSprite(RenderType::guiTextured, VERIFIED_ICON, k + l - 35 + xOffset, j - 1 + yOffset, 14, 14); RenderSystem.disableBlend(); int t = n - k; diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java index 538ca3cd..1c6de348 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java @@ -1,17 +1,9 @@ package com.aizistral.nochatreports.common.mixins.client; -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.CallbackInfo; - -import com.aizistral.nochatreports.common.gui.RealmsWarningScreen; -import com.mojang.realmsclient.RealmsMainScreen; - -import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.network.chat.CommonComponents; +import org.spongepowered.asm.mixin.Mixin; @Mixin(TitleScreen.class) public class MixinTitleScreen extends Screen { @@ -21,12 +13,13 @@ protected MixinTitleScreen() { throw new IllegalStateException("Can't touch this"); } - @Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$9" }, at = @At("HEAD"), cancellable = true) - private void onRealmsButtonClicked(Button button, CallbackInfo info) { - if (RealmsWarningScreen.shouldShow()) { - this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this))); - info.cancel(); - } - } + // TODO: Fix this +// @Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$9" }, at = @At("HEAD"), cancellable = true) +// private void onRealmsButtonClicked(Button button, CallbackInfo info) { +// if (RealmsWarningScreen.shouldShow()) { +// this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this))); +// info.cancel(); +// } +// } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinToastComponent.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinToastComponent.java index bdde5a52..e609ac9b 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinToastComponent.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinToastComponent.java @@ -1,18 +1,16 @@ package com.aizistral.nochatreports.common.mixins.client; -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.CallbackInfo; - import com.aizistral.nochatreports.common.config.NCRConfig; - import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.gui.components.toasts.SystemToast.SystemToastId; import net.minecraft.client.gui.components.toasts.Toast; -import net.minecraft.client.gui.components.toasts.ToastComponent; +import net.minecraft.client.gui.components.toasts.ToastManager; +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.CallbackInfo; -@Mixin(ToastComponent.class) +@Mixin(ToastManager.class) public class MixinToastComponent { @Inject(method = "addToast", at = @At("HEAD"), cancellable = true) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 56eb452e..6a316d87 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -40,8 +40,8 @@ "depends": { "fabricloader": ">=0.14.6", "fabric-api": "*", - "minecraft": [ ">=1.20.3" ], - "java": ">=17" + "minecraft": [ ">=1.21.2" ], + "java": ">=21" }, "suggests": {}, "accessWidener" : "nochatreports.accesswidener", From 7e773f0e7c395f86d2577cb722df336ed8993fda Mon Sep 17 00:00:00 2001 From: Onako2 <79749977+Onako2@users.noreply.github.com> Date: Mon, 28 Oct 2024 00:58:33 +0100 Subject: [PATCH 2/4] Fabric: renders now semi correctly --- .../common/gui/AdvancedTooltip.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java index f8706284..0e0794a9 100644 --- a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java +++ b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java @@ -8,9 +8,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner; -import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import org.joml.Vector2ic; @@ -74,17 +72,17 @@ public static List splitTooltip(Minecraft minecraft, Comp public void doCustomRender(Screen screen, GuiGraphics graphics, int x, int y, ClientTooltipPositioner positioner) { if (this.renderWithoutGap) { - this.renderTooltipNoGap(screen, graphics, splitTooltip(screen.minecraft, this.getMessage(), this.maxWidth), x, y, positioner); + this.renderTooltipNoGap(screen, graphics, splitTooltip(screen.minecraft, this.getMessage(), this.maxWidth), this.getMessage(), x, y, positioner); } else throw new UnsupportedOperationException("This tooltip doesn't support custom render!"); } - protected void renderTooltipNoGap(Screen screen, GuiGraphics poseStack, List list, int x, int y, ClientTooltipPositioner positioner) { - this.renderTooltipInternalNoGap(screen, poseStack, list.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), x, y, positioner); + protected void renderTooltipNoGap(Screen screen, GuiGraphics poseStack, List list, Component component, int x, int y, ClientTooltipPositioner positioner) { + this.renderTooltipInternalNoGap(screen, poseStack, list.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), component, x, y, positioner); } // Originates from GuiGraphics - protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, List list, int i, int j, ClientTooltipPositioner clientTooltipPositioner) { + protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, List list, Component component, int i, int j, ClientTooltipPositioner clientTooltipPositioner) { ClientTooltipComponent clientTooltipComponent2; int t; if (list.isEmpty()) @@ -105,21 +103,20 @@ protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, L int q = vector2ic.y(); graphics.pose().pushPose(); int r = 400; - TooltipRenderUtil.renderTooltipBackground(graphics, p, q, n, o, 400, ResourceLocation.withDefaultNamespace("textures/gui/sprites/tooltip/background.png")); graphics.pose().translate(0.0f, 0.0f, 400.0f); - int s = q; - for (t = 0; t < list.size(); ++t) { - clientTooltipComponent2 = list.get(t); - // TODO: Fix this -// clientTooltipComponent2.renderText(screen.font, p, s, graphics.pose().last().pose(), graphics.bufferSource()); - s += clientTooltipComponent2.getHeight(screen.font) + /*(t == 0 ? 2 : 0)*/ 0; - } - s = q; + + int maxWidth = 0; + for (t = 0; t < list.size(); ++t) { clientTooltipComponent2 = list.get(t); - clientTooltipComponent2.renderImage(screen.font, p, s, 0, 0, graphics); - s += clientTooltipComponent2.getHeight(screen.font) + /*(t == 0 ? 2 : 0)*/ 0; + if (clientTooltipComponent2.getWidth(screen.font) > maxWidth) { + maxWidth = clientTooltipComponent2.getWidth(screen.font); + } } + + System.out.println(maxWidth); + graphics.renderTooltip(screen.font, splitTooltip(screen.minecraft, component), p + maxWidth , q, null); + graphics.pose().popPose(); } From 58b2128c7e687bb0c5ef0e0021578368f52cca38 Mon Sep 17 00:00:00 2001 From: Nebojsa Majic <79749977+Onako2@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:48:36 +0100 Subject: [PATCH 3/4] Remove debug stuff Oups, forgot to remove the debug stuff --- .../com/aizistral/nochatreports/common/gui/AdvancedTooltip.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java index 0e0794a9..99e776f7 100644 --- a/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java +++ b/src/main/java/com/aizistral/nochatreports/common/gui/AdvancedTooltip.java @@ -114,7 +114,6 @@ protected void renderTooltipInternalNoGap(Screen screen, GuiGraphics graphics, L } } - System.out.println(maxWidth); graphics.renderTooltip(screen.font, splitTooltip(screen.minecraft, component), p + maxWidth , q, null); graphics.pose().popPose(); From ce49d400251f36308a7c52743d93aca2a3d4360b Mon Sep 17 00:00:00 2001 From: Aizistral Date: Tue, 29 Oct 2024 01:22:06 +0100 Subject: [PATCH 4/4] Transform `setKeyPair` method instead of copying contents --- .../resources/META-INF/accesstransformer.cfg | 4 +++- .../resources/META-INF/accesstransformer.cfg | 4 +++- .../common/core/ServerSafetyState.java | 20 +++++++---------- .../mixins/client/MixinTitleScreen.java | 22 ++++++++++++------- .../resources/nochatreports.accesswidener | 4 +++- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index 273a310e..c923a04f 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -21,4 +21,6 @@ public net.minecraft.client.gui.components.Tooltip (Lnet/minecraft/network #public-f net.minecraft.client.gui.components.CycleButton m_257795_()V #updateTooltip public-f net.minecraft.client.gui.components.AbstractWidget m_88315_(Lnet/minecraft/client/gui/GuiGraphics;IIF)V #render -public net.minecraft.client.gui.components.WidgetTooltipHolder m_323619_(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; #createTooltipPositioner \ No newline at end of file +public net.minecraft.client.gui.components.WidgetTooltipHolder m_323619_(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; #createTooltipPositioner + +public net.minecraft.client.multiplayer.ClientPacketListener m_260951_(Lnet/minecraft/world/entity/player/ProfileKeyPair;)V #setKeyPair \ No newline at end of file diff --git a/neoforge/src/main/resources/META-INF/accesstransformer.cfg b/neoforge/src/main/resources/META-INF/accesstransformer.cfg index a1d6b385..4fd2634d 100644 --- a/neoforge/src/main/resources/META-INF/accesstransformer.cfg +++ b/neoforge/src/main/resources/META-INF/accesstransformer.cfg @@ -21,4 +21,6 @@ public net.minecraft.client.gui.components.Tooltip (Lnet/minecraft/network #public-f net.minecraft.client.gui.components.CycleButton updateTooltip()V public-f net.minecraft.client.gui.components.AbstractWidget render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V -public net.minecraft.client.gui.components.WidgetTooltipHolder createTooltipPositioner(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; \ No newline at end of file +public net.minecraft.client.gui.components.WidgetTooltipHolder createTooltipPositioner(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; + +public net.minecraft.client.multiplayer.ClientPacketListener setKeyPair(Lnet/minecraft/world/entity/player/ProfileKeyPair;)V \ No newline at end of file diff --git a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java index c81ce9b9..37ef7f01 100644 --- a/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java +++ b/src/main/java/com/aizistral/nochatreports/common/core/ServerSafetyState.java @@ -41,23 +41,19 @@ public static boolean allowChatSigning() { public static CompletableFuture setAllowChatSigning(boolean allow) { if (ALLOW_CHAT_SIGNING.compareAndSet(!allow, allow)) { - if (Minecraft.getInstance().player != null) { - var connection = Minecraft.getInstance().player.connection; + Minecraft mc = Minecraft.getInstance(); + + if (mc.player != null) { + var connection = mc.player.connection; if (allow && connection.chatSession == null) - return Minecraft.getInstance().getProfileKeyPairManager().prepareKeyPair() + return mc.getProfileKeyPairManager().prepareKeyPair() .thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair -> { - Minecraft minecraft = Minecraft.getInstance(); - if (minecraft.isLocalPlayer(minecraft.getGameProfile().getId())) { - if (connection.chatSession == null || !connection.chatSession.keyPair().equals(profileKeyPair)) { - connection.chatSession = LocalChatSession.create(profileKeyPair); - connection.signedMessageEncoder = connection.chatSession.createMessageEncoder(minecraft.getGameProfile().getId()); - connection.send(new ServerboundChatSessionUpdatePacket(connection.chatSession.asRemote().asData())); - } - } + connection.setKeyPair(profileKeyPair); + SIGNING_ACTIONS.forEach(Runnable::run); SIGNING_ACTIONS.clear(); - }), Minecraft.getInstance()); + }), mc); } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java index 1c6de348..f010c1ea 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinTitleScreen.java @@ -1,9 +1,16 @@ package com.aizistral.nochatreports.common.mixins.client; +import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.network.chat.CommonComponents; 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.CallbackInfo; + +import com.aizistral.nochatreports.common.gui.RealmsWarningScreen; +import com.mojang.realmsclient.RealmsMainScreen; @Mixin(TitleScreen.class) public class MixinTitleScreen extends Screen { @@ -13,13 +20,12 @@ protected MixinTitleScreen() { throw new IllegalStateException("Can't touch this"); } - // TODO: Fix this -// @Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$9" }, at = @At("HEAD"), cancellable = true) -// private void onRealmsButtonClicked(Button button, CallbackInfo info) { -// if (RealmsWarningScreen.shouldShow()) { -// this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this))); -// info.cancel(); -// } -// } + @Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$10" }, at = @At("HEAD"), cancellable = true) + private void onRealmsButtonClicked(Button button, CallbackInfo info) { + if (RealmsWarningScreen.shouldShow()) { + this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this))); + info.cancel(); + } + } } diff --git a/src/main/resources/nochatreports.accesswidener b/src/main/resources/nochatreports.accesswidener index d3091b65..63889da5 100644 --- a/src/main/resources/nochatreports.accesswidener +++ b/src/main/resources/nochatreports.accesswidener @@ -30,4 +30,6 @@ accessible field net/minecraft/client/gui/components/AbstractWidget tooltip Lnet mutable field net/minecraft/client/gui/components/AbstractWidget tooltip Lnet/minecraft/client/gui/components/WidgetTooltipHolder; accessible method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; -extendable method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; \ No newline at end of file +extendable method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; + +accessible method net/minecraft/client/multiplayer/ClientPacketListener setKeyPair (Lnet/minecraft/world/entity/player/ProfileKeyPair;)V \ No newline at end of file