Class PlayerLookup
java.lang.Object
net.fabricmc.fabric.api.networking.v1.PlayerLookup
Helper methods to lookup players in a server.
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 TypeMethodDescriptionstatic Collection<net.minecraft.server.level.ServerPlayer> all(net.minecraft.server.MinecraftServer server) Gets all the players on the minecraft server.static Collection<net.minecraft.server.level.ServerPlayer> around(net.minecraft.server.level.ServerLevel level, net.minecraft.core.Vec3i pos, double radius) Gets all players around a position in a level.static Collection<net.minecraft.server.level.ServerPlayer> around(net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos, double radius) Gets all players around a position in a level.static Collection<net.minecraft.server.level.ServerPlayer> level(net.minecraft.server.level.ServerLevel level) Gets all the players in a server level.static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Gets all players tracking a block position in a server level.static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos) Gets all players tracking a chunk in a server level.static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.world.entity.Entity entity) Gets all players tracking an entity in a server level.static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.world.level.block.entity.BlockEntity blockEntity) Gets all players tracking a block entity in a server level.
-
Method Details
-
all
public static Collection<net.minecraft.server.level.ServerPlayer> 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
-
level
public static Collection<net.minecraft.server.level.ServerPlayer> level(net.minecraft.server.level.ServerLevel level) Gets all the players in a server level.The returned collection is immutable.
- Parameters:
level- the server level- Returns:
- the players in the server level
-
tracking
public static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos) Gets all players tracking a chunk in a server level.- Parameters:
level- the server levelpos- the chunk in question- Returns:
- the players tracking the chunk
-
tracking
public static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.world.entity.Entity entity) Gets all players tracking an entity in a server level.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 level
-
tracking
public static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.world.level.block.entity.BlockEntity blockEntity) Gets all players tracking a block entity in a server level.- Parameters:
blockEntity- the block entity- Returns:
- the players tracking the block position
- Throws:
IllegalArgumentException- if the block entity is not in a server level
-
tracking
public static Collection<net.minecraft.server.level.ServerPlayer> tracking(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Gets all players tracking a block position in a server level.- Parameters:
level- the server levelpos- the block position- Returns:
- the players tracking the block position
-
around
public static Collection<net.minecraft.server.level.ServerPlayer> around(net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos, double radius) Gets all players around a position in a level.The distance check is done in the three-dimensional space instead of in the horizontal plane.
- Parameters:
level- the levelpos- the positionradius- the maximum distance from the position in blocks- Returns:
- the players around the position
-
around
public static Collection<net.minecraft.server.level.ServerPlayer> around(net.minecraft.server.level.ServerLevel level, net.minecraft.core.Vec3i pos, double radius) Gets all players around a position in a level.The distance check is done in the three-dimensional space instead of in the horizontal plane.
- Parameters:
level- the levelpos- the position (can be a block pos)radius- the maximum distance from the position in blocks- Returns:
- the players around the position
-