From 5c130ea5d7695ce9417be38a017e79dc7e02015d Mon Sep 17 00:00:00 2001 From: CelDaemon Date: Tue, 23 Jun 2026 15:53:49 +0200 Subject: [PATCH 1/2] Update chat tag --- tags/guide/chat.ytag | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tags/guide/chat.ytag b/tags/guide/chat.ytag index a4f39e44..143bc5cd 100644 --- a/tags/guide/chat.ytag +++ b/tags/guide/chat.ytag @@ -2,10 +2,35 @@ type: text --- -To send a message from server to all clients: `MinecraftServer server = ...; server.getPlayerManager().broadcast(...);` (In 1.19+ there are several overloads; check the javadoc for details. If unsure, use `broadcast(Text, boolean)`.) +## Server -To send a message from server to specific client: `ServerPlayerEntity player = ...; player.sendMessage(...);` +To send a system message to all players, we can use a broadcast: -To send a message from client to server: `MinecraftClient.getInstance().player.networkHandler.sendChatMessage(...);` (In 1.19.2 and below, omit `.networkHandler`.) +```java +MinecraftServer server = ...; -To add a message to HUD on client: `MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(...);` +server.getPlayerList().broadcastSystemMessage(Component.literal("Hello Fabric World!"), false); +``` + +To instead send a message to a specific player: + +```java +ServerPlayer player = ...; + +player.sendSystemMessage(Component.literal("This is a direct message")); +``` + +## Client + +To send a chat message from client to server: + +```java +Minecraft.getInstance().player.connection.sendChat("Hello, World!"); +``` + +We can also manually add messages to the chat. These messsages will not be sent +to the server or other players, but will be displayed locally in the hud. + +```java +Minecraft.getInstance().gui.hud.getChat().addRecentChat("This is a virtual message"); +``` From 7822f68d5c514210eb549a361903f2b3db215189 Mon Sep 17 00:00:00 2001 From: CelDaemon Date: Tue, 23 Jun 2026 21:57:25 +0200 Subject: [PATCH 2/2] Fix virtual message snippet --- tags/guide/chat.ytag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tags/guide/chat.ytag b/tags/guide/chat.ytag index 143bc5cd..6199c2b4 100644 --- a/tags/guide/chat.ytag +++ b/tags/guide/chat.ytag @@ -32,5 +32,5 @@ We can also manually add messages to the chat. These messsages will not be sent to the server or other players, but will be displayed locally in the hud. ```java -Minecraft.getInstance().gui.hud.getChat().addRecentChat("This is a virtual message"); +Minecraft.getInstance().getChatListener().handleSystemMessage(Component.literal("This is a virtual message")); ```