@@ -24,6 +24,13 @@ import net.minecraft.network.listener.ServerPacketListener
2424import net.minecraft.network.packet.Packet
2525
2626object PacketUtils {
27+ /* *
28+ * Sends a packet through the regular packet pipeline
29+ *
30+ * @param block Lambda that returns the packet to be sent
31+ */
32+ fun ClientPlayNetworkHandler.sendPacket (block : () -> ClientPacket ) = connection.send(block())
33+
2734 /* *
2835 * Sends a packet to the server without notifying the client.
2936 * It bypasses the mixins that would normally intercept the packet
@@ -32,9 +39,7 @@ object PacketUtils {
3239 * @param packet The packet to send.
3340 */
3441 fun ClientPlayNetworkHandler.sendPacketSilently (packet : ClientPacket ) {
35- if (! connection.isOpen) return
36- if (connection.packetListener?.accepts(packet) == true )
37- return // LOG.debug("Client tried to send client-bound packet {} to server ", packet)
42+ if (! connection.isOpen || connection.packetListener?.accepts(packet) == true ) return
3843
3944 connection.send(packet, null , true )
4045 connection.packetsSentCounter++
@@ -48,9 +53,7 @@ object PacketUtils {
4853 * @param packet The packet to handle.
4954 */
5055 fun ClientPlayNetworkHandler.handlePacketSilently (packet : ServerPacket ) {
51- if (! connection.isOpen) return
52- if (connection.packetListener?.accepts(packet) == false )
53- return // LOG.debug("Client tried to handle server-bound packet {}", packet)
56+ if (! connection.isOpen || connection.packetListener?.accepts(packet) == false ) return
5457
5558 ClientConnection .handlePacket(packet, connection.packetListener)
5659 connection.packetsReceivedCounter++
0 commit comments