mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Fire ChunkWatchEvents after sending packets (#8747)
This commit is contained in:
1 parent
7656b75992
commit
9b962c8ff0
3 files changed
+60
-42
No files matched your search
@@ -22,6 +22,7 @@ import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
@@ -625,18 +626,14 @@ public class ForgeEventFactory
|
||||
return event.getResult() != Result.DENY;
|
||||
}
|
||||
|
||||
public static void fireChunkWatch(boolean watch, ServerPlayer entity, ChunkPos chunkpos, ServerLevel level)
|
||||
public static void fireChunkWatch(ServerPlayer entity, LevelChunk chunk, ServerLevel level)
|
||||
{
|
||||
if (watch)
|
||||
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(entity, chunkpos, level));
|
||||
else
|
||||
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(entity, chunkpos, level));
|
||||
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(entity, chunk, level));
|
||||
}
|
||||
|
||||
public static void fireChunkWatch(boolean wasLoaded, boolean load, ServerPlayer entity, ChunkPos chunkpos, ServerLevel level)
|
||||
public static void fireChunkUnWatch(ServerPlayer entity, ChunkPos chunkpos, ServerLevel level)
|
||||
{
|
||||
if (wasLoaded != load)
|
||||
fireChunkWatch(load, entity, chunkpos, level);
|
||||
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(entity, chunkpos, level));
|
||||
}
|
||||
|
||||
public static boolean onPistonMovePre(Level level, BlockPos pos, Direction direction, boolean extending)
|
||||
|
||||
@@ -8,22 +8,25 @@ package net.minecraftforge.event.world;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
|
||||
/**
|
||||
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.<br>
|
||||
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.
|
||||
* <p>
|
||||
* If a method utilizes this {@link Event} as its parameter, the method will
|
||||
* receive every child event of this class.<br>
|
||||
* <br>
|
||||
* receive every child event of this class.
|
||||
* <p>
|
||||
* {@link #pos} contains the ChunkPos of the Chunk this event is affecting.<br>
|
||||
* {@link #world} contains the World of the Chunk this event is affecting.<br>
|
||||
* {@link #player} contains the EntityPlayer that is involved with this chunk being watched. <br>
|
||||
* <br>
|
||||
* {@link #player} contains the {@link ServerPlayer} that is involved with this chunk being watched.
|
||||
* <p>
|
||||
* The {@link #player}'s world may not be the same as the world of the chunk
|
||||
* when the player is teleporting to another dimension.<br>
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* when the player is teleporting to another dimension.
|
||||
* <p>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class ChunkWatchEvent extends Event
|
||||
{
|
||||
@@ -54,31 +57,41 @@ public class ChunkWatchEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkWatchEvent.Watch is fired when an EntityPlayer begins watching a chunk.<br>
|
||||
* This event is fired when a chunk is added to the watched chunks of an EntityPlayer in
|
||||
* {@code net.minecraft.server.level.ChunkMap#updateChunkTracking(ServerPlayer, ChunkPos, Packet[], boolean, boolean)}. <br>
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult} <br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* ChunkWatchEvent.Watch is fired when 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)}).
|
||||
* <p>
|
||||
* This event may be used to send additional chunk-related data to the client.
|
||||
* <p>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable} and
|
||||
* {@link HasResult does not have a result}.
|
||||
**/
|
||||
public static class Watch extends ChunkWatchEvent
|
||||
{
|
||||
public Watch(ServerPlayer player, ChunkPos pos, ServerLevel world) {super(player, pos, world);}
|
||||
private final LevelChunk chunk;
|
||||
|
||||
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel world)
|
||||
{
|
||||
super(player, chunk.getPos(), world);
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public LevelChunk getChunk()
|
||||
{
|
||||
return this.chunk;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkWatchEvent.UnWatch is fired when an EntityPlayer stops watching a chunk.<br>
|
||||
* This event is fired when a chunk is removed from the watched chunks of an EntityPlayer in
|
||||
* {@code net.minecraft.server.level.ChunkMap#updateChunkTracking(ServerPlayer, ChunkPos, Packet[], boolean, boolean)}. <br>
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult} <br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* ChunkWatchEvent.UnWatch is fired when 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)}.
|
||||
* <p>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable} and
|
||||
* {@link HasResult does not have a result}.
|
||||
**/
|
||||
public static class UnWatch extends ChunkWatchEvent
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user