Skip to content

Commit

Permalink
Fix bug with networking not enqueuing to main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Jan 25, 2024
1 parent 5633fe2 commit 58820f1
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static <T extends Packet<T>> FriendlyByteBuf.Reader<NeoForgeCustomPayload
}

public static <T extends Packet<T>> IPayloadHandler<NeoForgeCustomPayload<T>> handleClient(ClientboundPacketType<T> type) {
return (packet, context) -> type.handle(packet.packet()).run();
return (packet, context) -> context.workHandler().submitAsync(() -> type.handle(packet.packet()).run());
}

public static <T extends Packet<T>> IPayloadHandler<NeoForgeCustomPayload<T>> handleServer(ServerboundPacketType<T> type) {
return (packet, context) -> context.player()
.ifPresentOrElse(
player -> type.handle(packet.packet()).accept(player),
player -> context.workHandler().submitAsync(() -> type.handle(packet.packet()).accept(player)),
() -> {
throw new IllegalStateException("Server packets should not be sent from the client!");
throw new IllegalStateException("Received a serverbound packet without a player context.");
}
);
}
Expand Down

0 comments on commit 58820f1

Please sign in to comment.