--- a/net/minecraft/network/PacketEncoder.java
+++ b/net/minecraft/network/PacketEncoder.java
@@ -35,28 +35,61 @@
             } else {
                 FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
                 friendlyByteBuf.writeVarInt(i);
+                friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
 
                 try {
                     int j = friendlyByteBuf.writerIndex();
                     packet.write(friendlyByteBuf);
                     int k = friendlyByteBuf.writerIndex() - j;
-                    if (k > 8388608) {
+                    if (false && k > 8388608) { // Paper - disable
                         throw new IllegalArgumentException("Packet too big (is " + k + ", should be less than 8388608): " + packet);
                     }
 
                     JvmProfiler.INSTANCE.onPacketSent(codecData.protocol(), i, channelHandlerContext.channel().remoteAddress(), k);
                 } catch (Throwable var13) {
-                    LOGGER.error("Error receiving packet {}", i, var13);
+                    // Paper start - Give proper error message
+                    String packetName = io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(packet.getClass().getName());
+                    if (packetName.contains(".")) {
+                        packetName = packetName.substring(packetName.lastIndexOf(".") + 1);
+                    }
+
+                    LOGGER.error("Packet encoding of packet {} (ID: {}) threw (skippable? {})", packetName, i, packet.isSkippable(), var13);
+                    // Paper end
                     if (packet.isSkippable()) {
                         throw new SkipPacketException(var13);
                     }
 
                     throw var13;
                 } finally {
+                    // Paper start
+                    int packetLength = friendlyByteBuf.readableBytes();
+                    if (packetLength > MAX_PACKET_SIZE) {
+                        throw new PacketTooLargeException(packet, this.codecKey, packetLength);
+                    }
+                    // Paper end
                     ProtocolSwapHandler.swapProtocolIfNeeded(attribute, packet);
                 }
 
             }
         }
     }
+
+    // Paper start
+    private static int MAX_PACKET_SIZE = 8388608;
+
+    public static class PacketTooLargeException extends RuntimeException {
+        private final Packet<?> packet;
+        public final AttributeKey<ConnectionProtocol.CodecData<?>> codecKey;
+
+        PacketTooLargeException(Packet<?> packet, AttributeKey<ConnectionProtocol.CodecData<?>> codecKey, int packetLength) {
+            super("PacketTooLarge - " + packet.getClass().getSimpleName() + " is " + packetLength + ". Max is " + MAX_PACKET_SIZE);
+            this.packet = packet;
+            this.codecKey = codecKey;
+        }
+
+        public Packet<?> getPacket() {
+            return this.packet;
+        }
+    }
+    // Paper end
 }
