mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Add and fire SystemMessageReceivedEvent
Replaces ClientChatReceivedEvent.System which was not fired due to Mojang changing ChatType to a registry.
This commit is contained in:
6 files changed
+80
-48
No files matched your search
@@ -67,7 +67,6 @@ import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
@@ -106,6 +105,7 @@ import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
||||
import net.minecraftforge.client.event.ClientPauseChangeEvent;
|
||||
import net.minecraftforge.client.event.ClientPlayerChangeGameTypeEvent;
|
||||
import net.minecraftforge.client.event.SystemMessageReceivedEvent;
|
||||
import net.minecraftforge.client.event.ComputeFovModifierEvent;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
@@ -759,13 +759,10 @@ public class ForgeHooksClient {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onClientSystemChat(Component message, boolean overlay, RegistryAccess registry) {
|
||||
return message;
|
||||
/*
|
||||
var bound = ChatType.bind(ForgeMod.SYSTEM_CHAT_TYPE.getKey(), registry, Component.literal("System"));
|
||||
var event = new ClientChatReceivedEvent.System(bound, message, overlay);
|
||||
public static Component onClientSystemMessage(Component message, boolean overlay) {
|
||||
var event = new SystemMessageReceivedEvent(message, overlay);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -29,15 +29,13 @@ import java.util.UUID;
|
||||
* @see ChatType
|
||||
*/
|
||||
@Cancelable
|
||||
public class ClientChatReceivedEvent extends Event
|
||||
{
|
||||
public class ClientChatReceivedEvent extends Event {
|
||||
private Component message;
|
||||
private final ChatType.Bound boundChatType;
|
||||
private final UUID sender;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ClientChatReceivedEvent(ChatType.Bound boundChatType, Component message, UUID sender)
|
||||
{
|
||||
public ClientChatReceivedEvent(ChatType.Bound boundChatType, Component message, UUID sender) {
|
||||
this.boundChatType = boundChatType;
|
||||
this.message = message;
|
||||
this.sender = sender;
|
||||
@@ -46,8 +44,7 @@ public class ClientChatReceivedEvent extends Event
|
||||
/**
|
||||
* {@return the message that will be displayed in the chat message window, if the event is not cancelled}
|
||||
*/
|
||||
public Component getMessage()
|
||||
{
|
||||
public Component getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -56,8 +53,7 @@ public class ClientChatReceivedEvent extends Event
|
||||
*
|
||||
* @param message the new message to be displayed
|
||||
*/
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
public void setMessage(Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@@ -65,25 +61,25 @@ public class ClientChatReceivedEvent extends Event
|
||||
* {@return the bound chat type of the chat message}.
|
||||
* This contains the chat type, display name of the sender, and nullable target name depending on the chat type.
|
||||
*/
|
||||
public ChatType.Bound getBoundChatType()
|
||||
{
|
||||
public ChatType.Bound getBoundChatType() {
|
||||
return this.boundChatType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message sender}.
|
||||
* This will be {@link Util#NIL_UUID} if the message is a system message.
|
||||
*/
|
||||
public UUID getSender()
|
||||
{
|
||||
public UUID getSender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the message was sent by the system, {@code false} otherwise}
|
||||
*
|
||||
* @Deprecated Mojang made ChatType a registry, which isn't always accessible when the System messages are sent.
|
||||
* So moved to it's own event. {@link SystemMessageReceivedEvent}
|
||||
*/
|
||||
public boolean isSystem()
|
||||
{
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public boolean isSystem() {
|
||||
return this.sender.equals(Util.NIL_UUID);
|
||||
}
|
||||
|
||||
@@ -98,13 +94,11 @@ public class ClientChatReceivedEvent extends Event
|
||||
*
|
||||
* @see ChatType
|
||||
*/
|
||||
public static class Player extends ClientChatReceivedEvent
|
||||
{
|
||||
public static class Player extends ClientChatReceivedEvent {
|
||||
private final PlayerChatMessage playerChatMessage;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Player(ChatType.Bound boundChatType, Component message, PlayerChatMessage playerChatMessage, UUID sender)
|
||||
{
|
||||
public Player(ChatType.Bound boundChatType, Component message, PlayerChatMessage playerChatMessage, UUID sender) {
|
||||
super(boundChatType, message, sender);
|
||||
this.playerChatMessage = playerChatMessage;
|
||||
}
|
||||
@@ -113,28 +107,23 @@ public class ClientChatReceivedEvent extends Event
|
||||
* {@return the full player chat message}.
|
||||
* This contains the sender UUID, various signing data, and the optional unsigned contents.
|
||||
*/
|
||||
public PlayerChatMessage getPlayerChatMessage()
|
||||
{
|
||||
public PlayerChatMessage getPlayerChatMessage() {
|
||||
return this.playerChatMessage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a system chat message is received on the client.
|
||||
* Fired when a system 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>
|
||||
* @Deprecated Mojang made ChatType a registry, which isn't always accessible when the System messages are sent.
|
||||
* So moved to it's own event. {@link SystemMessageReceivedEvent}
|
||||
*/
|
||||
public static class System extends ClientChatReceivedEvent
|
||||
{
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public static class System extends ClientChatReceivedEvent {
|
||||
private final boolean overlay;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public System(ChatType.Bound boundChatType, Component message, boolean overlay)
|
||||
{
|
||||
public System(ChatType.Bound boundChatType, Component message, boolean overlay) {
|
||||
super(boundChatType, message, Util.NIL_UUID);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
@@ -142,8 +131,7 @@ public class ClientChatReceivedEvent extends Event
|
||||
/**
|
||||
* {@return whether the message goes to the overlay}
|
||||
*/
|
||||
public boolean isOverlay()
|
||||
{
|
||||
public boolean isOverlay() {
|
||||
return this.overlay;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Fired when a system message is received on the client.
|
||||
* This can be used for filtering and detecting messages with specific words or phrases, and suppressing them.
|
||||
*
|
||||
* <p>If the event is cancelled, the message is not displayed in the chat message window.</p>
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public class SystemMessageReceivedEvent extends Event {
|
||||
private Component message;
|
||||
private final boolean overlay;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public SystemMessageReceivedEvent(Component message, boolean overlay) {
|
||||
this.message = message;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether the message goes to the overlay}
|
||||
*/
|
||||
public boolean isOverlay() {
|
||||
return this.overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message that will be displayed in the chat message window, if the event is not cancelled}
|
||||
*/
|
||||
public Component getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new message to be displayed in the chat message window, if the event is not cancelled.
|
||||
*
|
||||
* @param message the new message to be displayed
|
||||
*/
|
||||
public void setMessage(Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -352,12 +352,6 @@ public class ForgeMod {
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
|
||||
/*
|
||||
private static final ChatTypeDecoration SYSTEM_CHAT_TYPE_DECORATION = new ChatTypeDecoration("forge.chatType.system", List.of(ChatTypeDecoration.Parameter.CONTENT), Style.EMPTY);
|
||||
private static final DeferredRegister<ChatType> CHAT_TYPES = deferred(Registries.CHAT_TYPE);
|
||||
public static final RegistryObject<ChatType> SYSTEM_CHAT_TYPE = CHAT_TYPES.register("syste_chat", () -> new ChatType(SYSTEM_CHAT_TYPE_DECORATION, SYSTEM_CHAT_TYPE_DECORATION));
|
||||
*/
|
||||
|
||||
private static ForgeMod INSTANCE;
|
||||
public static ForgeMod getInstance() {
|
||||
return INSTANCE;
|
||||
|
||||
@@ -89,7 +89,7 @@ class EntityCommand
|
||||
if (info == null)
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
sender.sendSuccess(() -> Component.translatable("commands.forge.entity.list.single.header", name, info.getLeft()), false);
|
||||
sender.sendSuccess(() -> Component.translatable("commands.forge.entity.list.single.header", name.toString(), info.getLeft()), false);
|
||||
List<Map.Entry<ChunkPos, Integer>> toSort = new ArrayList<>();
|
||||
toSort.addAll(info.getRight().entrySet());
|
||||
toSort.sort((a, b) -> {
|
||||
|
||||
Reference in new issue
Block a user