Skip to content

Instantly share code, notes, and snippets.

@boq
Created October 13, 2013 07:27
Show Gist options
  • Save boq/6959143 to your computer and use it in GitHub Desktop.
Save boq/6959143 to your computer and use it in GitHub Desktop.
public static void sendUpdateToAllTrackers(Entity tag, Packet packet) {
final World w = tag.worldObj;
Preconditions.checkArgument(w instanceof WorldServer, "This method can only be executed on server side");
WorldServer server = (WorldServer)w;
server.getEntityTracker().sendPacketToAllPlayersTrackingEntity(tag, packet);
}
public static void sendPacketToWatchers(WorldServer server, int x, int z, Packet packet) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
try {
// wrongly named, PlayerInstance is in fact chunk watchers list
PlayerInstance playerInstance = server.getPlayerManager().getOrCreateChunkWatcher(chunkX, chunkZ, false);
if (playerInstance != null)
playerInstance.sendToAllPlayersWatchingChunk(packet);
} catch (Exception e) {
Throwables.propagate(throwable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment