From 2ec5e52f24843c365c2149d7c9677825f264ef8e Mon Sep 17 00:00:00 2001 From: Emanuel Ferraz Date: Tue, 7 Nov 2023 15:25:01 +0000 Subject: [PATCH] fix: Add back spamless debug functionality Fixes #786 --- .../common/network/message/MessageSpamlessChat.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/vazkii/psi/common/network/message/MessageSpamlessChat.java b/src/main/java/vazkii/psi/common/network/message/MessageSpamlessChat.java index 2ba6dc6d..545d16ad 100644 --- a/src/main/java/vazkii/psi/common/network/message/MessageSpamlessChat.java +++ b/src/main/java/vazkii/psi/common/network/message/MessageSpamlessChat.java @@ -8,28 +8,34 @@ */ package vazkii.psi.common.network.message; +import net.minecraft.client.GuiMessageTag; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.ChatComponent; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MessageSignature; import net.minecraftforge.network.NetworkEvent; +import java.nio.ByteBuffer; import java.util.function.Supplier; public class MessageSpamlessChat { private final Component message; private static final int BASE_MAGIC = 696969; + private final MessageSignature signature; private final int magic; public MessageSpamlessChat(Component message, int magic) { this.message = message; this.magic = BASE_MAGIC + magic; + this.signature = new MessageSignature(ByteBuffer.allocate(4).putInt(this.magic).array()); } public MessageSpamlessChat(FriendlyByteBuf buf) { this.message = buf.readComponent(); this.magic = buf.readInt(); + this.signature = new MessageSignature(ByteBuffer.allocate(4).putInt(this.magic).array()); } public void encode(FriendlyByteBuf buf) { @@ -40,10 +46,8 @@ public void encode(FriendlyByteBuf buf) { public boolean receive(Supplier context) { context.get().enqueueWork(() -> { ChatComponent chatGui = Minecraft.getInstance().gui.getChat(); - // TODO: Currently unable to do this way, because of limitations of the new chat system - // chatGui.deleteMessage(magic); - // chatGui.addMessage(message, magic); - chatGui.addMessage(message); + chatGui.deleteMessage(signature); + chatGui.addMessage(message, signature, GuiMessageTag.system()); }); return true; }