Backport ClientChatReceivedEvent.System for 1.19.2. Fixes #9352 (#9355)

This commit is contained in:
SizableShrimp authored and GitHub committed 2023-02-24 10:47:07 -08:00
1 parent d25a5466db
commit 184392e02e
4 files changed
+59 -1

No files matched your search

@@ -30,3 +30,12 @@
this.m_241119_(p_241518_, p_241542_.m_237220_());
this.m_240498_(p_241510_, p_241542_.m_241109_());
this.f_240659_ = Util.m_137550_();
@@ -263,6 +_,8 @@
public void m_240494_(Component p_240522_, boolean p_240642_) {
if (!this.f_240348_.f_91066_.m_231833_().m_231551_() || !this.f_240348_.m_91246_(this.m_240473_(p_240522_))) {
+ p_240522_ = net.minecraftforge.client.ForgeHooksClient.onClientSystemChat(p_240522_, p_240642_);
+ if (p_240522_ == null) return;
if (p_240642_) {
this.f_240348_.f_91065_.m_93063_(p_240522_, false);
} else {
@@ -71,13 +71,14 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.locale.Language;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.ChatSender;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.ChatTypeDecoration;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.MessageSigner;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.chat.Style;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
@@ -963,6 +964,17 @@ public class ForgeHooksClient
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
}
private static final ChatTypeDecoration SYSTEM_CHAT_TYPE_DECORATION = new ChatTypeDecoration("forge.chatType.system", List.of(ChatTypeDecoration.Parameter.CONTENT), Style.EMPTY);
private static final ChatType SYSTEM_CHAT_TYPE = new ChatType(SYSTEM_CHAT_TYPE_DECORATION, SYSTEM_CHAT_TYPE_DECORATION);
private static final ChatType.Bound SYSTEM_CHAT_TYPE_BOUND = SYSTEM_CHAT_TYPE.bind(Component.literal("System"));
@Nullable
public static Component onClientSystemChat(Component message, boolean overlay)
{
ClientChatReceivedEvent.System event = new ClientChatReceivedEvent.System(SYSTEM_CHAT_TYPE_BOUND, message, overlay);
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
}
@NotNull
public static String onClientSendMessage(String message)
{
@@ -6,6 +6,7 @@
package net.minecraftforge.client.event;
import net.minecraft.Util;
import net.minecraft.network.chat.ChatMessageContent;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSigner;
@@ -45,6 +46,11 @@ public class ClientChatReceivedEvent extends Event
this.messageSigner = messageSigner;
}
private ClientChatReceivedEvent(ChatType.Bound boundChatType, Component message, PlayerChatMessage playerChatMessage)
{
this(boundChatType, message, playerChatMessage, playerChatMessage.signer());
}
/**
* {@return the message that will be displayed in the chat message window, if the event is not cancelled}
*/
@@ -98,4 +104,33 @@ public class ClientChatReceivedEvent extends Event
{
return this.messageSigner.isSystem();
}
/**
* Fired when a system chat message is received on the client.
*
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* If the event is cancelled, the message is not displayed in the chat message window or in the overlay.</p>
*
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
*/
public static class System extends ClientChatReceivedEvent
{
private final boolean overlay;
@ApiStatus.Internal
public System(ChatType.Bound boundChatType, Component message, boolean overlay)
{
super(boundChatType, message, PlayerChatMessage.system(new ChatMessageContent(message.getString(), message)));
this.overlay = overlay;
}
/**
* {@return whether the message goes to the overlay}
*/
public boolean isOverlay()
{
return this.overlay;
}
}
}
@@ -217,6 +217,8 @@
"fluid_type.minecraft.milk": "Milk",
"fluid_type.minecraft.flowing_milk": "Milk",
"forge.chatType.system": "{0}",
"forge.experimentalsettings.tooltip": "This world uses experimental settings, which could stop working at any time.",
"forge.selectWorld.backupWarning.experimental.additional" : "This message will not show again for this world."
}