Class PlayerLookup

java.lang.Object
net.fabricmc.fabric.api.networking.v1.PlayerLookup

public final class PlayerLookup extends Object
For example, a block entity may use the methods in this class to send a packet to all clients which can see the block entity in order notify clients about a change.

The word "tracking" means that an entity/chunk on the server is known to a player's client (within in view distance) and the (block) entity should notify tracking clients of changes.

These methods should only be called on the server thread and only be used on logical a server.

  • Method Summary

    Modifier and Type
    Method
    Description
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    all​(net.minecraft.server.MinecraftServer server)
    Gets all the players on the minecraft server.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    around​(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.Vec3d pos, double radius)
    Gets all players around a position in a world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    around​(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.Vec3i pos, double radius)
    Gets all players around a position in a world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    tracking​(net.minecraft.block.entity.BlockEntity blockEntity)
    Gets all players tracking a block entity in a server world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    tracking​(net.minecraft.entity.Entity entity)
    Gets all players tracking an entity in a server world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    tracking​(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.BlockPos pos)
    Gets all players tracking a block position in a server world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    tracking​(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.ChunkPos pos)
    Gets all players tracking a chunk in a server world.
    static Collection<net.minecraft.server.network.ServerPlayerEntity>
    world​(net.minecraft.server.world.ServerWorld world)
    Gets all the players in a server world.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • all

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> all(net.minecraft.server.MinecraftServer server)
      Gets all the players on the minecraft server.

      The returned collection is immutable.

      Parameters:
      server - the server
      Returns:
      all players on the server
    • world

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> world(net.minecraft.server.world.ServerWorld world)
      Gets all the players in a server world.

      The returned collection is immutable.

      Parameters:
      world - the server world
      Returns:
      the players in the server world
    • tracking

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> tracking(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.ChunkPos pos)
      Gets all players tracking a chunk in a server world.
      Parameters:
      world - the server world
      pos - the chunk in question
      Returns:
      the players tracking the chunk
    • tracking

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> tracking(net.minecraft.entity.Entity entity)
      Gets all players tracking an entity in a server world.

      The returned collection is immutable.

      Warning: If the provided entity is a player, it is not guaranteed by the contract that said player is included in the resulting stream.

      Parameters:
      entity - the entity being tracked
      Returns:
      the players tracking the entity
      Throws:
      IllegalArgumentException - if the entity is not in a server world
    • tracking

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> tracking(net.minecraft.block.entity.BlockEntity blockEntity)
      Gets all players tracking a block entity in a server world.
      Parameters:
      blockEntity - the block entity
      Returns:
      the players tracking the block position
      Throws:
      IllegalArgumentException - if the block entity is not in a server world
    • tracking

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> tracking(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.BlockPos pos)
      Gets all players tracking a block position in a server world.
      Parameters:
      world - the server world
      pos - the block position
      Returns:
      the players tracking the block position
    • around

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> around(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.Vec3d pos, double radius)
      Gets all players around a position in a world.

      The distance check is done in the three-dimensional space instead of in the horizontal plane.

      Parameters:
      world - the world
      pos - the position
      radius - the maximum distance from the position in blocks
      Returns:
      the players around the position
    • around

      public static Collection<net.minecraft.server.network.ServerPlayerEntity> around(net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.Vec3i pos, double radius)
      Gets all players around a position in a world.

      The distance check is done in the three-dimensional space instead of in the horizontal plane.

      Parameters:
      world - the world
      pos - the position (can be a block pos)
      radius - the maximum distance from the position in blocks
      Returns:
      the players around the position