Package net.minecraft.src.buildcraft.additionalpipes.chunkloader

Source Code of net.minecraft.src.buildcraft.additionalpipes.chunkloader.TileChunkLoader

package net.minecraft.src.buildcraft.additionalpipes.chunkloader;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.src.Chunk;
import net.minecraft.src.ChunkCoordIntPair;
import net.minecraft.src.TileEntity;

public class TileChunkLoader extends TileEntity {

    public static List<TileChunkLoader> chunkLoaderList = Collections.synchronizedList(new LinkedList<TileChunkLoader>());
   
    public TileChunkLoader() {
    }
   
    private synchronized void addToList() {
      if (!chunkLoaderList.contains(this)) {
            chunkLoaderList.add(this);
        }
    }
   
    private synchronized void removeFromList() {
      if (chunkLoaderList.contains(this)) {
            chunkLoaderList.remove(this);
        }
    }
   
    /*
    * Returns a list of ChunkCoordPair that are the chunks around the block
    * in a 3x3 area.
    */
    public List getLoadArea() {

        List<ChunkCoordIntPair> loadArea = new LinkedList<ChunkCoordIntPair>();

        Chunk centerChunk = worldObj.getChunkFromBlockCoords(xCoord, zCoord);

        for (int x = -1; x < 2; x++) {
            for (int z = -1; z < 2; z++) {
                ChunkCoordIntPair chunkCoords = new ChunkCoordIntPair(centerChunk.xPosition + x, centerChunk.zPosition + z);
                loadArea.add(chunkCoords);
            }
        }

        return loadArea;
    }
   
    @Override
    public void updateEntity() {
      super.updateEntity();
      addToList();
    }
   
    @Override
    public void invalidate() {
        super.invalidate();
        removeFromList();
    }
}
TOP

Related Classes of net.minecraft.src.buildcraft.additionalpipes.chunkloader.TileChunkLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.