@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>(); }
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()); }