예제 #1
0
  @Override
  public void tick() {
    List<ChunkAddress> loadingChunkAddressesCopy = new LinkedList<ChunkAddress>();
    loadingChunkAddressesCopy.addAll(loadingChunkAddresses);
    Collection<ChunkAddress> oldChunks = this.loadedChunkAddresses;
    Collection<ChunkAddress> newChunks = this.loadingChunkAddresses;
    newChunks.removeAll(this.loadedChunkAddresses);
    oldChunks.removeAll(loadingChunkAddressesCopy);

    File worldDir = new File(OpenCraft.worldDir, world.getName());
    if (!worldDir.exists()) worldDir.mkdirs();

    for (ChunkAddress oldChunk : oldChunks) {
      EntityChunk chunk = (EntityChunk) this.chunks.get(oldChunk);
      chunk.event().emit(new EventUnloadChunk());
      OpenCraftServer.instance().getTickManager().removeTick(chunk);
      OpenCraftServer.instance().getWorldManager().getChunkLoadManager().save(chunk);
      this.chunks.remove(chunk);
      OpenCraft.log.debug("A chunk is unloaded");
    }
    for (ChunkAddress newChunk : newChunks) {
      EntityChunk chunk =
          OpenCraftServer.instance().getWorldManager().getChunkLoadManager().request(newChunk);
      if (chunk != null) receiveChunk(chunk);
    }

    this.loadedChunkAddresses = loadingChunkAddressesCopy;
    this.loadingChunkAddresses = new LinkedList<ChunkAddress>();
  }
예제 #2
0
 void receiveChunk(EntityChunk chunk) {
   this.chunks.put(chunk.address, chunk);
   OpenCraftServer.instance().getTickManager().addTick(chunk);
   OpenCraft.log.debug("A chunk is loaded");
   chunk.event().emit(new EventLoadChunk());
 }