Skip to content

Commit

Permalink
fix: Add back spamless debug functionality
Browse files Browse the repository at this point in the history
Fixes #786
  • Loading branch information
Kamefrede committed Nov 7, 2023
1 parent 565ef2f commit 2ec5e52
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -40,10 +46,8 @@ public void encode(FriendlyByteBuf buf) {
public boolean receive(Supplier<NetworkEvent.Context> 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;
}
Expand Down

0 comments on commit 2ec5e52

Please sign in to comment.