mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
Forge 1.19.1
Load natives from classpath Make command argument types a forge registry Add `EntityMobGriefingEvent` to `Allay#wantsToPickUp` Overhaul `ServerChatEvent` to use `ChatDecorator` system Remove `ClientChatEvent#setMessage` for now Gradle 7.5 Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
3c1126a7b4
commit
6845c094ab
98 files changed
+1025
-733
No files matched your search
@@ -26,7 +26,6 @@ import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.chat.NarratorChatListener;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -74,6 +73,8 @@ import net.minecraft.network.chat.ChatType;
|
||||
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.protocol.status.ServerStatus;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
@@ -217,7 +218,7 @@ public class ForgeHooksClient
|
||||
guiLayers.push(minecraft.screen);
|
||||
minecraft.screen = Objects.requireNonNull(screen);
|
||||
screen.init(minecraft, minecraft.getWindow().getGuiScaledWidth(), minecraft.getWindow().getGuiScaledHeight());
|
||||
NarratorChatListener.INSTANCE.sayNow(screen.getNarrationMessage());
|
||||
minecraft.getNarrator().sayNow(screen.getNarrationMessage());
|
||||
}
|
||||
|
||||
public static void popGuiLayer(Minecraft minecraft)
|
||||
@@ -230,7 +231,7 @@ public class ForgeHooksClient
|
||||
|
||||
popGuiLayerInternal(minecraft);
|
||||
if (minecraft.screen != null)
|
||||
NarratorChatListener.INSTANCE.sayNow(minecraft.screen.getNarrationMessage());
|
||||
minecraft.getNarrator().sayNow(minecraft.screen.getNarrationMessage());
|
||||
}
|
||||
|
||||
public static float getGuiFarPlane()
|
||||
@@ -940,9 +941,9 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onClientChat(ChatType type, Component message, ChatSender chatSender)
|
||||
public static Component onClientChat(ChatType.Bound boundChatType, Component message, PlayerChatMessage playerChatMessage, MessageSigner messageSigner)
|
||||
{
|
||||
ClientChatReceivedEvent event = new ClientChatReceivedEvent(type, message, chatSender);
|
||||
ClientChatReceivedEvent event = new ClientChatReceivedEvent(boundChatType, message, playerChatMessage, messageSigner);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* Fired when the client is about to send a chat message to the server.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the chat message or command will not be sent to the server.</p>
|
||||
* If the event is cancelled, the chat message will not be sent to the server.</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>
|
||||
@@ -24,13 +24,13 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
@Cancelable
|
||||
public class ClientChatEvent extends Event
|
||||
{
|
||||
private String message;
|
||||
// private String message;
|
||||
private final String originalMessage;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ClientChatEvent(String message)
|
||||
{
|
||||
this.setMessage(message);
|
||||
// this.setMessage(message);
|
||||
this.originalMessage = Strings.nullToEmpty(message);
|
||||
}
|
||||
|
||||
@@ -39,24 +39,24 @@ public class ClientChatEvent extends Event
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
return this.originalMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new message to be sent to the server, if the event is not cancelled.
|
||||
*
|
||||
* @param message the new message to be sent
|
||||
*/
|
||||
public void setMessage(String message)
|
||||
{
|
||||
this.message = Strings.nullToEmpty(message);
|
||||
}
|
||||
// /**
|
||||
// * Sets the new message to be sent to the server, if the event is not cancelled.
|
||||
// *
|
||||
// * @param message the new message to be sent
|
||||
// */
|
||||
// public void setMessage(String message)
|
||||
// {
|
||||
// this.message = Strings.nullToEmpty(message);
|
||||
// }
|
||||
|
||||
/**
|
||||
* {@return the original message that was to be sent to the server}
|
||||
*/
|
||||
public String getOriginalMessage()
|
||||
{
|
||||
return originalMessage;
|
||||
return this.originalMessage;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,10 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.ChatSender;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MessageSigner;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -31,15 +32,17 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
public class ClientChatReceivedEvent extends Event
|
||||
{
|
||||
private Component message;
|
||||
private final ChatType type;
|
||||
private final ChatSender chatSender;
|
||||
private final ChatType.Bound boundChatType;
|
||||
private final PlayerChatMessage playerChatMessage;
|
||||
private final MessageSigner messageSigner;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ClientChatReceivedEvent(ChatType type, Component message, ChatSender chatSender)
|
||||
public ClientChatReceivedEvent(ChatType.Bound boundChatType, Component message, PlayerChatMessage playerChatMessage, MessageSigner messageSigner)
|
||||
{
|
||||
this.type = type;
|
||||
this.boundChatType = boundChatType;
|
||||
this.message = message;
|
||||
this.chatSender = chatSender;
|
||||
this.playerChatMessage = playerChatMessage;
|
||||
this.messageSigner = messageSigner;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +56,7 @@ public class ClientChatReceivedEvent extends Event
|
||||
/**
|
||||
* 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 sent
|
||||
* @param message the new message to be displayed
|
||||
*/
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
@@ -61,20 +64,38 @@ public class ClientChatReceivedEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type of the chat message}
|
||||
* {@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 getType()
|
||||
public ChatType.Bound getBoundChatType()
|
||||
{
|
||||
return type;
|
||||
return this.boundChatType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sender of this chat message} This contains the UUID, name, and (optionally) the team name of the
|
||||
* entity which sent the chat message. For system messages, {@link ChatSender#uuid()} will be equal to
|
||||
* {@link Util#NIL_UUID}.
|
||||
* {@return the full player chat message}.
|
||||
* This contains the sender UUID, various signing data, and the optional unsigned contents.
|
||||
*/
|
||||
public ChatSender getChatSender()
|
||||
public PlayerChatMessage getPlayerChatMessage()
|
||||
{
|
||||
return chatSender;
|
||||
return this.playerChatMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message signer}.
|
||||
* This contains the sender UUID, timestamp of message creation, and signature salt.
|
||||
* The {@linkplain MessageSigner#profileId() sender UUID} will be {@link Util#NIL_UUID} if the message is a system message.
|
||||
*/
|
||||
public MessageSigner getMessageSigner()
|
||||
{
|
||||
return this.messageSigner;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the message was sent by the system, {@code false} otherwise}
|
||||
*/
|
||||
public boolean isSystem()
|
||||
{
|
||||
return this.messageSigner.isSystem();
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,5 @@ import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
|
||||
@FunctionalInterface
|
||||
public interface IGuiOverlay
|
||||
{
|
||||
void render(ForgeGui gui, PoseStack poseStack, float partialTick, int width, int height);
|
||||
void render(ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.common;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -32,6 +33,7 @@ import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.chat.contents.LiteralContents;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
@@ -395,15 +397,74 @@ public class ForgeHooks
|
||||
return !MinecraftForge.EVENT_BUS.post(new VanillaGameEvent(level, vanillaEvent, pos, context));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatEvent(@Nullable ServerPlayer player, String raw, Component comp)
|
||||
private static String getRawText(Component message)
|
||||
{
|
||||
ServerChatEvent event = new ServerChatEvent(player, raw, comp);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return message.getContents() instanceof LiteralContents literalContents ? literalContents.text() : "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatSubmittedEvent(ServerPlayer player, String plain, Component decorated, boolean canChangeMessage)
|
||||
{
|
||||
ServerChatEvent.Submitted event = new ServerChatEvent.Submitted(player, plain, decorated, canChangeMessage);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
private static final ChatDecorator SERVER_CHAT_SUBMITTED_DECORATOR = new ChatDecorator()
|
||||
{
|
||||
@NotNull
|
||||
@Override
|
||||
public CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message)
|
||||
{
|
||||
return null;
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (sender == null)
|
||||
return message; // Vanilla should never get here with the patches we use, but let's be safe with dumb mods
|
||||
|
||||
return onServerChatSubmittedEvent(sender, getRawText(message), message, true);
|
||||
});
|
||||
}
|
||||
return event.getComponent();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CompletableFuture<PlayerChatMessage> decorate(@Nullable ServerPlayer sender, PlayerChatMessage message)
|
||||
{
|
||||
if (message.signedContent().isDecorated())
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (sender != null)
|
||||
return onServerChatSubmittedEvent(sender, message.signedContent().plain(), message.signedContent().decorated(), false) == null;
|
||||
|
||||
return false;
|
||||
}).thenApply(canceled -> canceled == Boolean.TRUE ? null : message);
|
||||
}
|
||||
|
||||
return this.decorate(sender, message.serverContent()).thenApply(component -> component == null ? null : message.withUnsignedContent(component));
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static ChatDecorator getServerChatSubmittedDecorator()
|
||||
{
|
||||
return SERVER_CHAT_SUBMITTED_DECORATOR;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatPreviewEvent(@NotNull ServerPlayer player, @NotNull Component message)
|
||||
{
|
||||
ServerChatEvent.Preview event = new ServerChatEvent.Preview(player, getRawText(message), message);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChatDecorator getServerChatPreviewDecorator()
|
||||
{
|
||||
return (player, message) -> CompletableFuture.supplyAsync(() -> {
|
||||
if (player == null)
|
||||
return message; // Vanilla should never get here with the patches we use, but let's be safe with dumb mods
|
||||
|
||||
Component preview = onServerChatPreviewEvent(player, message);
|
||||
// Send the input message back to the client if the event was cancelled
|
||||
return preview == null ? message : preview;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import net.minecraftforge.common.world.ForgeBiomeModifiers.RemoveSpawnsBiomeModi
|
||||
import net.minecraftforge.common.world.NoneBiomeModifier;
|
||||
import net.minecraftforge.common.world.NoneStructureModifier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fluids.ForgeFlowingFluid;
|
||||
@@ -351,6 +352,7 @@ public class ForgeMod
|
||||
});
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
private static boolean serverChatPreviewEnabled = false;
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(new ResourceLocation("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(new ResourceLocation("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
@@ -369,6 +371,25 @@ public class ForgeMod
|
||||
enableMilkFluid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this method during mod constructor to enable chat previews for the server.
|
||||
* Recommended for mods which modify the chat message in {@link ServerChatEvent}.
|
||||
*
|
||||
* @see ServerChatEvent
|
||||
*/
|
||||
public static void enableServerChatPreview()
|
||||
{
|
||||
serverChatPreviewEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if server chat previews are enabled
|
||||
*/
|
||||
public static boolean isServerChatPreviewEnabled()
|
||||
{
|
||||
return serverChatPreviewEnabled;
|
||||
}
|
||||
|
||||
public ForgeMod()
|
||||
{
|
||||
LOGGER.info(FORGEMOD,"Forge mod loading, version {}, for MC {} with MCP {}", ForgeVersion.getVersion(), MCPVersion.getMCVersion(), MCPVersion.getMCPVersion());
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import java.util.Set;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
@@ -69,10 +70,9 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
//Preliminary, simple Fake Player class
|
||||
/**
|
||||
* A basic fake server player implementation that can be used to simulate player actions.
|
||||
*/
|
||||
public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer(ServerLevel level, GameProfile name)
|
||||
@@ -81,16 +81,15 @@ public class FakePlayer extends ServerPlayer
|
||||
this.connection = new FakePlayerNetHandler(level.getServer(), this);
|
||||
}
|
||||
|
||||
@Override public Vec3 position(){ return new Vec3(0, 0, 0); }
|
||||
@Override public BlockPos blockPosition(){ return BlockPos.ZERO; }
|
||||
@Override public void displayClientMessage(Component chatComponent, boolean actionBar){}
|
||||
@Override public void awardStat(Stat par1StatBase, int par2){}
|
||||
//@Override public void openGui(Object mod, int modGuiId, World world, int x, int y, int z){}
|
||||
@Override public boolean isInvulnerableTo(DamageSource source){ return true; }
|
||||
@Override public boolean canHarmPlayer(Player player){ return false; }
|
||||
@Override public void die(DamageSource source){ return; }
|
||||
@Override public void tick(){ return; }
|
||||
@Override public void updateOptions(ServerboundClientInformationPacket pkt){ return; }
|
||||
@Override public Vec3 position() { return new Vec3(0, 0, 0); }
|
||||
@Override public BlockPos blockPosition() { return BlockPos.ZERO; }
|
||||
@Override public void displayClientMessage(Component chatComponent, boolean actionBar) { }
|
||||
@Override public void awardStat(Stat stat, int amount) { }
|
||||
@Override public boolean isInvulnerableTo(DamageSource source) { return true; }
|
||||
@Override public boolean canHarmPlayer(Player player) { return false; }
|
||||
@Override public void die(DamageSource source) { }
|
||||
@Override public void tick() { }
|
||||
@Override public void updateOptions(ServerboundClientInformationPacket packet) { }
|
||||
@Override @Nullable public MinecraftServer getServer() { return ServerLifecycleHooks.getCurrentServer(); }
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@@ -134,7 +133,7 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handlePaddleBoat(ServerboundPaddleBoatPacket packet) { }
|
||||
@Override public void onDisconnect(Component message) { }
|
||||
@Override public void send(Packet<?> packet) { }
|
||||
@Override public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener) { }
|
||||
@Override public void send(Packet<?> packet, @Nullable PacketSendListener sendListener) { }
|
||||
@Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { }
|
||||
@Override public void handleChat(ServerboundChatPacket packet) { }
|
||||
@Override public void handleAnimate(ServerboundSwingPacket packet) { }
|
||||
|
||||
@@ -11,25 +11,24 @@ import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* CommandEvent is fired after a command is parsed, but before it is executed.
|
||||
* This event is fired during the invocation of {@link Commands#performCommand(CommandSourceStack, String)}. <br>
|
||||
* <br>
|
||||
* {@link #parse} contains the instance of {@link ParseResults} for the parsed command.<br>
|
||||
* {@link #exception} begins null, but can be populated with an exception to be thrown within the command.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}. <br>
|
||||
* If the event is canceled, the execution of the command does not occur.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* This event is fired during the invocation of {@link Commands#performCommand(ParseResults, String)}.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the command will not be executed.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@Cancelable
|
||||
public class CommandEvent extends Event
|
||||
{
|
||||
private ParseResults<CommandSourceStack> parse;
|
||||
@Nullable
|
||||
private Throwable exception;
|
||||
|
||||
public CommandEvent(ParseResults<CommandSourceStack> parse)
|
||||
@@ -37,8 +36,30 @@ public class CommandEvent extends Event
|
||||
this.parse = parse;
|
||||
}
|
||||
|
||||
public ParseResults<CommandSourceStack> getParseResults() { return parse; }
|
||||
public void setParseResults(ParseResults<CommandSourceStack> parse) { this.parse = parse; }
|
||||
public Throwable getException() { return exception; }
|
||||
public void setException(Throwable exception) { this.exception = exception; }
|
||||
/**
|
||||
* {@return the parsed command results}
|
||||
*/
|
||||
public ParseResults<CommandSourceStack> getParseResults()
|
||||
{
|
||||
return this.parse;
|
||||
}
|
||||
|
||||
public void setParseResults(ParseResults<CommandSourceStack> parse)
|
||||
{
|
||||
this.parse = parse;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an exception to be thrown when performing the command, starts null}
|
||||
*/
|
||||
@Nullable
|
||||
public Throwable getException()
|
||||
{
|
||||
return this.exception;
|
||||
}
|
||||
|
||||
public void setException(@Nullable Throwable exception)
|
||||
{
|
||||
this.exception = exception;
|
||||
}
|
||||
}
|
||||
@@ -5,63 +5,170 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* ServerChatEvent is fired whenever a C01PacketChatMessage is processed. <br>
|
||||
* This event is fired via {@link ForgeHooks#onServerChatEvent(ServerPlayer, String, Component)},
|
||||
* which is executed by the {@link ServerGamePacketListenerImpl#handleChat(ServerboundChatPacket)}<br>
|
||||
* <br>
|
||||
* {@link #username} contains the username of the player sending the chat message, unless fired from the server, where it is null.<br>
|
||||
* {@link #message} contains the message being sent.<br>
|
||||
* {@link #player} the instance of ServerPlayer for the player sending the chat message, or null when fired from the server.<br>
|
||||
* {@link #component} contains the instance of Component for the sent message.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}. <br>
|
||||
* If this event is canceled, the chat message is never distributed to all clients.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* This event is fired whenever a {@link ServerboundChatPreviewPacket} or {@link ServerboundChatPacket} is received.
|
||||
* <p>
|
||||
* Mods that modify chat messages from this event should call {@link ForgeMod#enableServerChatPreview()}
|
||||
* from their mod constructor to enable the chat preview and allow signing by clients.
|
||||
* It is recommended to listen to this event class when modifying chat messages
|
||||
* rather than a subclass to ensure clients with {@link Options#onlyShowSecureChat()}
|
||||
* enabled can see the modified messages.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the message will not be sent to clients.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
*
|
||||
* @see ForgeMod#enableServerChatPreview()
|
||||
**/
|
||||
@Cancelable
|
||||
public class ServerChatEvent extends Event
|
||||
{
|
||||
private final String message;
|
||||
@Nullable
|
||||
private final String username;
|
||||
@Nullable
|
||||
private final ServerPlayer player;
|
||||
private Component component;
|
||||
private final String username;
|
||||
private final String rawText;
|
||||
private final boolean canChangeMessage;
|
||||
private Component message;
|
||||
|
||||
public ServerChatEvent(@Nullable ServerPlayer player, String message, Component component)
|
||||
@ApiStatus.Internal
|
||||
protected ServerChatEvent(ServerPlayer player, String rawText, Component message, boolean canChangeMessage)
|
||||
{
|
||||
super();
|
||||
this.message = message;
|
||||
this.player = player;
|
||||
this.username = player != null ? player.getGameProfile().getName() : null;
|
||||
this.component = component;
|
||||
this.username = player.getGameProfile().getName();
|
||||
this.rawText = rawText;
|
||||
this.canChangeMessage = canChangeMessage;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setComponent(Component e)
|
||||
/**
|
||||
* {@return the player who initiated the chat action}
|
||||
*/
|
||||
public ServerPlayer getPlayer()
|
||||
{
|
||||
this.component = e;
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public Component getComponent()
|
||||
/**
|
||||
* {@return the username of the player who initiated the chat action}
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return this.component;
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getMessage() { return this.message; }
|
||||
public @Nullable String getUsername() { return this.username; }
|
||||
public @Nullable ServerPlayer getPlayer() { return this.player; }
|
||||
/**
|
||||
* {@return the original raw text of the player chat message}
|
||||
*/
|
||||
public String getRawText()
|
||||
{
|
||||
return this.rawText;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether the message can be changed or not}.
|
||||
* In vanilla, this will be false if a {@link ServerboundChatPacket} is received
|
||||
* with signed decorated content already included by the sending player.
|
||||
* Players who submit a chat message with chat previews disabled will cause this to be true.
|
||||
*/
|
||||
public boolean canChangeMessage()
|
||||
{
|
||||
return this.canChangeMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message to be sent to the relevant clients.
|
||||
* <p>
|
||||
* If {@link #canChangeMessage()} is false, this call will be ignored.
|
||||
* <p>
|
||||
* It is recommended to listen to {@link ServerChatEvent} when modifying chat messages
|
||||
* rather than a subclass to ensure clients with {@link Options#onlyShowSecureChat()}
|
||||
* enabled can see the modified messages.
|
||||
*
|
||||
* @see ForgeMod#enableServerChatPreview()
|
||||
*/
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
if (!this.canChangeMessage)
|
||||
return;
|
||||
|
||||
this.message = Objects.requireNonNull(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message that will be sent to the relevant clients, if the event is not cancelled}
|
||||
*/
|
||||
public Component getMessage()
|
||||
{
|
||||
return this.message;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired whenever a {@link ServerboundChatPreviewPacket} is received from a client typing a message.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the chat preview sent back to the client will match the original message.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
public static class Preview extends ServerChatEvent
|
||||
{
|
||||
@ApiStatus.Internal
|
||||
public Preview(ServerPlayer player, String rawText, Component message)
|
||||
{
|
||||
super(player, rawText, message, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the chat preview to be sent back to the client.
|
||||
*/
|
||||
@Override
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
super.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the chat preview that will be sent back to the client, if the event is not cancelled}
|
||||
*/
|
||||
@Override
|
||||
public Component getMessage()
|
||||
{
|
||||
return super.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired whenever a {@link ServerboundChatPacket} is received from a client
|
||||
* who has submitted their chat message.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the message will not be sent to clients.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
public static class Submitted extends ServerChatEvent
|
||||
{
|
||||
@ApiStatus.Internal
|
||||
public Submitted(ServerPlayer player, String rawText, Component message, boolean canChangeMessage)
|
||||
{
|
||||
super(player, rawText, message, canChangeMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,7 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
/**
|
||||
* Fired when tags are updated on either server or client. This event can be used to refresh data that depends on tags.
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.network.filters;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import net.minecraft.network.Connection;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -27,11 +28,15 @@ public class NetworkFilters
|
||||
|
||||
public static void injectIfNecessary(Connection manager)
|
||||
{
|
||||
ChannelPipeline pipeline = manager.channel().pipeline();
|
||||
if (pipeline.get("packet_handler") == null)
|
||||
return; // Realistically this can only ever be null if the connection was prematurely closed due to an error. We return early here to reduce further log spam.
|
||||
|
||||
instances.forEach((key, filterFactory) -> {
|
||||
VanillaPacketFilter filter = filterFactory.apply(manager);
|
||||
if (filter.isNecessary(manager))
|
||||
{
|
||||
manager.channel().pipeline().addBefore("packet_handler", key, filter);
|
||||
pipeline.addBefore("packet_handler", key, filter);
|
||||
LOGGER.debug("Injected {} into {}", filter, manager);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,6 +18,8 @@ import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.gametest.framework.TestClassNameArgument;
|
||||
import net.minecraft.gametest.framework.TestFunctionArgument;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
|
||||
@@ -91,6 +93,9 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
commandBuildContext.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
|
||||
RootCommandNode<SharedSuggestionProvider> root = packet.getRoot(commandBuildContext);
|
||||
RootCommandNode<SharedSuggestionProvider> newRoot = CommandTreeCleaner.cleanArgumentTypes(root, argType -> {
|
||||
if (argType instanceof TestFunctionArgument || argType instanceof TestClassNameArgument)
|
||||
return false; // Vanilla connections should not have gametest on, so we should filter these out always
|
||||
|
||||
ArgumentTypeInfo<?, ?> info = ArgumentTypeInfos.byClass(argType);
|
||||
ResourceLocation id = Registry.COMMAND_ARGUMENT_TYPE.getKey(info);
|
||||
return id != null && (id.getNamespace().equals("minecraft") || id.getNamespace().equals("brigadier"));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@@ -74,6 +75,7 @@ public class ForgeRegistries
|
||||
public static final IForgeRegistry<RecipeSerializer<?>> RECIPE_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(Keys.RECIPE_SERIALIZERS);
|
||||
public static final IForgeRegistry<Attribute> ATTRIBUTES = RegistryManager.ACTIVE.getRegistry(Keys.ATTRIBUTES);
|
||||
public static final IForgeRegistry<StatType<?>> STAT_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.STAT_TYPES);
|
||||
public static final IForgeRegistry<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.COMMAND_ARGUMENT_TYPES);
|
||||
|
||||
// Villages
|
||||
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = RegistryManager.ACTIVE.getRegistry(Keys.VILLAGER_PROFESSIONS);
|
||||
@@ -112,13 +114,13 @@ public class ForgeRegistries
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
* Use {@link Keys#BIOME_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = DEFERRED_BIOME_MODIFIER_SERIALIZERS.makeRegistry(() -> new RegistryBuilder<Codec<? extends BiomeModifier>>().disableSaving().disableSync());
|
||||
public static final Supplier<IForgeRegistry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = DEFERRED_BIOME_MODIFIER_SERIALIZERS.makeRegistry(GameData::getBiomeModifierSerializersRegistryBuilder);
|
||||
static final DeferredRegister<Codec<? extends StructureModifier>> DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.STRUCTURE_MODIFIER_SERIALIZERS, Keys.STRUCTURE_MODIFIER_SERIALIZERS.location().getNamespace());
|
||||
/**
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
* Use {@link Keys#STRUCTURE_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.makeRegistry(() -> new RegistryBuilder<Codec<? extends StructureModifier>>().disableSaving().disableSync());
|
||||
public static final Supplier<IForgeRegistry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.makeRegistry(GameData::getStructureModifierSerializersRegistryBuilder);
|
||||
static final DeferredRegister<FluidType> DEFERRED_FLUID_TYPES = DeferredRegister.create(Keys.FLUID_TYPES, Keys.FLUID_TYPES.location().getNamespace());
|
||||
/**
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
@@ -141,6 +143,7 @@ public class ForgeRegistries
|
||||
public static final ResourceKey<Registry<Potion>> POTIONS = key("potion");
|
||||
public static final ResourceKey<Registry<Attribute>> ATTRIBUTES = key("attribute");
|
||||
public static final ResourceKey<Registry<StatType<?>>> STAT_TYPES = key("stat_type");
|
||||
public static final ResourceKey<Registry<ArgumentTypeInfo<?, ?>>> COMMAND_ARGUMENT_TYPES = key("command_argument_type");
|
||||
public static final ResourceKey<Registry<SoundEvent>> SOUND_EVENTS = key("sound_event");
|
||||
public static final ResourceKey<Registry<Enchantment>> ENCHANTMENTS = key("enchantment");
|
||||
public static final ResourceKey<Registry<EntityType<?>>> ENTITY_TYPES = key("entity_type");
|
||||
@@ -167,8 +170,8 @@ public class ForgeRegistries
|
||||
public static final ResourceKey<Registry<Biome>> BIOMES = key("worldgen/biome");
|
||||
|
||||
// Forge
|
||||
public static final ResourceKey<Registry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = key("forge:data_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = key("forge:loot_modifier_serializers");
|
||||
public static final ResourceKey<Registry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = key("forge:entity_data_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = key("forge:global_loot_modifier_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = key("forge:biome_modifier_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = key("forge:structure_modifier_serializers");
|
||||
public static final ResourceKey<Registry<FluidType>> FLUID_TYPES = key("forge:fluid_type");
|
||||
|
||||
@@ -40,6 +40,8 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.util.LogMessageAdapter;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
@@ -104,7 +106,6 @@ public class GameData
|
||||
makeRegistry(FLUIDS, "empty").vanillaHolder(Fluid::builtInRegistryHolder).create();
|
||||
makeRegistry(ITEMS, "air").addCallback(ItemCallbacks.INSTANCE).legacyName("items").vanillaHolder(Item::builtInRegistryHolder).create();
|
||||
makeRegistry(MOB_EFFECTS).legacyName("potions").create();
|
||||
//makeRegistry(BIOMES, Biome.class).legacyName("biomes").create();
|
||||
makeRegistry(SOUND_EVENTS).legacyName("soundevents").create();
|
||||
makeRegistry(POTIONS, "empty").legacyName("potiontypes").create();
|
||||
makeRegistry(ENCHANTMENTS).legacyName("enchantments").create();
|
||||
@@ -117,6 +118,7 @@ public class GameData
|
||||
makeRegistry(RECIPE_SERIALIZERS).disableSaving().create();
|
||||
makeRegistry(ATTRIBUTES).onValidate(AttributeCallbacks.INSTANCE).disableSaving().disableSync().create();
|
||||
makeRegistry(STAT_TYPES).create();
|
||||
makeRegistry(COMMAND_ARGUMENT_TYPES).disableSaving().create();
|
||||
|
||||
// Villagers
|
||||
makeRegistry(VILLAGER_PROFESSIONS, "none").create();
|
||||
@@ -148,6 +150,16 @@ public class GameData
|
||||
return makeRegistry(GLOBAL_LOOT_MODIFIER_SERIALIZERS).disableSaving().disableSync();
|
||||
}
|
||||
|
||||
static RegistryBuilder<Codec<? extends BiomeModifier>> getBiomeModifierSerializersRegistryBuilder()
|
||||
{
|
||||
return new RegistryBuilder<Codec<? extends BiomeModifier>>().disableSaving().disableSync();
|
||||
}
|
||||
|
||||
static RegistryBuilder<Codec<? extends StructureModifier>> getStructureModifierSerializersRegistryBuilder()
|
||||
{
|
||||
return new RegistryBuilder<Codec<? extends StructureModifier>>().disableSaving().disableSync();
|
||||
}
|
||||
|
||||
static RegistryBuilder<FluidType> getFluidTypeRegistryBuilder()
|
||||
{
|
||||
return makeRegistry(FLUID_TYPES).disableSaving();
|
||||
|
||||
Reference in new issue
Block a user