From 979d8e58993dd53d116d191b9a5d744c9a7d5675 Mon Sep 17 00:00:00 2001 From: TelepathicGrunt <40846040+TelepathicGrunt@users.noreply.github.com> Date: Wed, 27 Nov 2024 03:40:56 -0500 Subject: [PATCH] Throw only when passed clientside level (#1707) --- .../neoforge/network/PacketDistributor.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/network/PacketDistributor.java b/src/main/java/net/neoforged/neoforge/network/PacketDistributor.java index f09dfae0c9..ea23ac4dcc 100644 --- a/src/main/java/net/neoforged/neoforge/network/PacketDistributor.java +++ b/src/main/java/net/neoforged/neoforge/network/PacketDistributor.java @@ -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. } /**