Exemplo n.º 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>();
  }
Exemplo n.º 2
0
 public EntityChunk forceLoadChunk(ChunkAddress address) {
   this.loadChunk(address);
   if (this.chunks.get(address) == null) {
     EntityChunk chunk =
         OpenCraftServer.instance().getWorldManager().getChunkLoadManager().forceLoad(address);
     this.chunks.put(chunk.address, chunk);
   }
   return (EntityChunk) this.chunks.get(address);
 }
Exemplo n.º 3
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());
 }