--- a/net/minecraft/network/ConnectionProtocol.java
+++ b/net/minecraft/network/ConnectionProtocol.java
@@ -300,6 +300,7 @@
 
         @Nullable
         public Packet<?> createPacket(int id, FriendlyByteBuf buf) {
+            if (id < 0 || id >= this.idToDeserializer.size()) return null; // Paper
             Function<FriendlyByteBuf, ? extends Packet<T>> function = this.idToDeserializer.get(id);
             return function != null ? function.apply(buf) : null;
         }
