pub fn optimize(&mut self) -> bool {
        // Only optimize the chunk if it has been modified.
        if !self.dirty {
            return false;
        }

        self.dirty = false;

        // Replace palette with new one.
        let mut new_palette = vec![];
        for x in 0..16 {
            for y in 0..16 {
                for z in 0..16 {
                    let block = self.block_at(x, y, z).native_state_id();
                    match new_palette.binary_search(&block) {
                        Ok(_) => (),
                        Err(insert_index) => {
                            new_palette.insert(insert_index, block);
                        }
                    }
                }
            }
        }

        // Recalculate all block IDs to match with the new palette.
        for x in 0..16 {
            for y in 0..16 {
                for z in 0..16 {
                    let block = self.block_at(x, y, z).native_state_id();
                    self.data.set(
                        block_index(x, y, z),
                        new_palette.binary_search(&block).unwrap() as u64,
                    );
                }
            }
        }

        self.palette = Some(new_palette);

        // Recalculate bits per block value.
        let mut new_bits_per_block = needed_bits(self.palette.as_ref().unwrap().len() as u64);
        if new_bits_per_block > MAX_BITS_PER_BLOCK {
            self.palette = None;
        } else {
            if new_bits_per_block < MIN_BITS_PER_BLOCK {
                new_bits_per_block = MIN_BITS_PER_BLOCK;
            }
            self.data = self.data.resize_to(new_bits_per_block).unwrap();
        }

        true // Chunk was optimized
    }
/// Optimizes this chunk section, reducing the bits
/// per block value as much as possible and removing unused
/// entries from the palette.
///
/// This function only optimizes the chunk if it is dirt,
/// i.e. if it has been modified since the last time
/// it was optimized. The returned value is `true` when
/// the chunk was optimized and `false` when it wasn't.
Optimizes this chunk section, reducing the bits
per block value as much as possible and removing unused
entries from the palette.

This function only optimizes the chunk if it is dirt,
i.e. if it has been modified since the last time
it was optimized. The returned value is `true` when
the chunk was optimized and `false` when it wasn't.
Optimizes this chunk section reducing the bits per block value as much as possible and removing unused entries from the palette . This function only optimizes the chunk if it is dirt i . e . if it has been modified since the last time it was optimized . The returned value is ` true ` when the chunk was optimized and ` false ` when it wasn ' t .
pub fn optimize(&mut self) -> bool {
        // Only optimize the chunk if it has been modified.
        if !self.dirty {
            return false;
        }
        self.dirty = false;
        // Replace palette with new one.
        let mut new_palette = vec![];
        for x in 0..16 {
            for y in 0..16 {
                for z in 0..16 {
                    let block = self.block_at(x, y, z).native_state_id();
                    match new_palette.binary_search(&block) {
                        Ok(_) => (),
                        Err(insert_index) => {
                            new_palette.insert(insert_index, block);
                        }
                    }
                }
            }
        }
        // Recalculate all block IDs to match with the new palette.
        for x in 0..16 {
            for y in 0..16 {
                for z in 0..16 {
                    let block = self.block_at(x, y, z).native_state_id();
                    self.data.set(
                        block_index(x, y, z),
                        new_palette.binary_search(&block).unwrap() as u64,
                    );
                }
            }
        }
        self.palette = Some(new_palette);
        // Recalculate bits per block value.
        let mut new_bits_per_block = needed_bits(self.palette.as_ref().unwrap().len() as u64);
        if new_bits_per_block > MAX_BITS_PER_BLOCK {
            self.palette = None;
        } else {
            if new_bits_per_block < MIN_BITS_PER_BLOCK {
                new_bits_per_block = MIN_BITS_PER_BLOCK;
            }
            self.data = self.data.resize_to(new_bits_per_block).unwrap();
        }
        true // Chunk was optimized
    }
pub fn optimize ( & mut self ) -> bool { // Only optimize the chunk if it has been modified. if ! self . dirty { return false ; } self . dirty = false ; // Replace palette with new one. let mut new_palette = vec ! [ ] ; for x in 0 .. 16 { for y in 0 .. 16 { for z in 0 .. 16 { let block = self . block_at ( x , y , z ) . native_state_id ( ) ; match new_palette . binary_search ( & block ) { Ok ( _ ) => ( ) , Err ( insert_index ) => { new_palette . insert ( insert_index , block ) ; } } } } } // Recalculate all block IDs to match with the new palette. for x in 0 .. 16 { for y in 0 .. 16 { for z in 0 .. 16 { let block = self . block_at ( x , y , z ) . native_state_id ( ) ; self . data . set ( block_index ( x , y , z ) , new_palette . binary_search ( & block ) . unwrap ( ) as u64 , ) ; } } } self . palette = Some ( new_palette ) ; // Recalculate bits per block value. let mut new_bits_per_block = needed_bits ( self . palette . as_ref ( ) . unwrap ( ) . len ( ) as u64 ) ; if new_bits_per_block > MAX_BITS_PER_BLOCK { self . palette = None ; } else { if new_bits_per_block < MIN_BITS_PER_BLOCK { new_bits_per_block = MIN_BITS_PER_BLOCK ; } self . data = self . data . resize_to ( new_bits_per_block ) . unwrap ( ) ; } true // Chunk was optimized }
Optimizes this chunk section, reducing the bits
per block value as much as possible and removing unused
entries from the palette.
Optimizes this chunk section reducing the bits per block value as much as possible and removing unused entries from the palette .
&mut self
&mut self