you need to run a counter variable in the foreach loop, and check for ‘before position 1,5,9,etc’ and ‘after position 4,8,12,etc,or after last in loop’ – a pure php exercise and nothing particular to WordPress.
example:
<?php /* Time to create a new loop that pulls out image attachments for this post */
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'numberposts' => 999, 'post_status' => null, 'post_parent' => $post->ID, 'orderby' => 'menu_order ID', 'order' => 'ASC', );
$attachments = get_posts( $args );
if ( $attachments ) {
$counter = 0;
echo '<ul>';
foreach ( $attachments as $attachment ) {
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'full' );
if( $counter%4 == 0 ) echo '<li>'; //open <li> before every fourth item
echo '<div class="centerImg">';
echo '<a rel="prettyPhoto-img" href="';
echo $image_attributes[0];
echo '">';
echo '<img src="';
echo $image_attributes[0];
echo '" />';
echo '</a>';
echo '</div>';
if( $counter%4 == 3 || $counter == count( $attachments )-1 ) echo '</li>'; //close </li> after each block of four or after last item
$counter++; ?>
<?php }
echo '</ul>'; ?>
<?php } ?>