Move Chunk Watch/Unwatch events to fire after sync packets have been sent to the client (#9790)

This makes sure that modders who send extra chunk data will have clients who know about the chunk.
This commit is contained in:
DBotThePony authored and GitHub committed 2023-11-17 08:45:55 -08:00
1 parent 0d820eddd4
commit a5ff932125
3 files changed
+32 -52

No files matched your search

@@ -25,14 +25,12 @@ import net.minecraftforge.fml.LogicalSide;
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public class ChunkWatchEvent extends Event
{
public class ChunkWatchEvent extends Event {
private final ServerLevel level;
private final ServerPlayer player;
private final ChunkPos pos;
public ChunkWatchEvent(ServerPlayer player, ChunkPos pos, ServerLevel level)
{
public ChunkWatchEvent(ServerPlayer player, ChunkPos pos, ServerLevel level) {
this.player = player;
this.pos = pos;
this.level = level;
@@ -41,33 +39,26 @@ public class ChunkWatchEvent extends Event
/**
* {@return the server player involved with the watch action}
*/
public ServerPlayer getPlayer()
{
public ServerPlayer getPlayer() {
return this.player;
}
/**
* {@return the chunk position this watch event is affecting}
*/
public ChunkPos getPos()
{
public ChunkPos getPos() {
return this.pos;
}
/**
* {@return the server level containing the chunk}
*/
public ServerLevel getLevel()
{
public ServerLevel getLevel() {
return this.level;
}
/**
* This event is fired whenever a {@link ServerPlayer} begins watching a chunk.
* <p>
* This event is fired when a chunk is added to the watched chunks of a {@link ServerPlayer}
* and the chunk's data is sent to the client (see
* {@code net.minecraft.server.level.ChunkMap#playerLoadedChunk(ServerPlayer, MutableObject, LevelChunk)}).
* This event is fired when chunk data is sent to the {@link ServerPlayer} (see {@link net.minecraft.server.network.PlayerChunkSender}).
* <p>
* This event may be used to send additional chunk-related data to the client.
* <p>
@@ -76,35 +67,30 @@ public class ChunkWatchEvent extends Event
* 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 Watch extends ChunkWatchEvent
{
public static class Watch extends ChunkWatchEvent {
private final LevelChunk chunk;
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel level)
{
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel level) {
super(player, chunk.getPos(), level);
this.chunk = chunk;
}
public LevelChunk getChunk()
{
public LevelChunk getChunk() {
return this.chunk;
}
}
/**
* This event is fired whenever a {@link ServerPlayer} stops watching a chunk.
* <p>
* This event is fired when a chunk is removed from the watched chunks of an {@link ServerPlayer}
* in {@code net.minecraft.server.level.ChunkMap#updateChunkTracking(ServerPlayer, ChunkPos, Packet[], boolean, boolean)}.
* This event is fired when server sends "forget chunk" packet to the {@link ServerPlayer}.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <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 UnWatch extends ChunkWatchEvent
{
public UnWatch(ServerPlayer player, ChunkPos pos, ServerLevel level) {super(player, pos, level);}
public static class UnWatch extends ChunkWatchEvent {
public UnWatch(ServerPlayer player, ChunkPos pos, ServerLevel level) {
super(player, pos, level);
}
}
}