Skip to content

Commit

Permalink
Throw only when passed clientside level (#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
TelepathicGrunt authored Nov 27, 2024
1 parent cf6cc71 commit 979d8e5
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ public static void sendToAllPlayers(CustomPacketPayload payload, CustomPacketPay
* Send the given payload(s) to all players tracking the given entity
*/
public static void sendToPlayersTrackingEntity(Entity entity, CustomPacketPayload payload, CustomPacketPayload... payloads) {
if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcast(entity, makeClientboundPacket(payload, payloads));
} else {
if (entity.level().isClientSide()) {
throw new IllegalStateException("Cannot send clientbound payloads on the client");
} else if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcast(entity, makeClientboundPacket(payload, payloads));
}
// Silently ignore custom Level implementations which may not return ServerChunkCache.
}

/**
* Send the given payload(s) to all players tracking the given entity and the entity itself if it is a player
*/
public static void sendToPlayersTrackingEntityAndSelf(Entity entity, CustomPacketPayload payload, CustomPacketPayload... payloads) {
if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcastAndSend(entity, makeClientboundPacket(payload, payloads));
} else {
if (entity.level().isClientSide()) {
throw new IllegalStateException("Cannot send clientbound payloads on the client");
} else if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcastAndSend(entity, makeClientboundPacket(payload, payloads));
}
// Silently ignore custom Level implementations which may not return ServerChunkCache.
}

/**
Expand Down

0 comments on commit 979d8e5

Please sign in to comment.