List of usage examples for net.minecraftforge.common DimensionManager unloadWorld
public static void unloadWorld(ServerWorld world)
From source file:org.blockartistry.world.gen.ChunkProviderServer.java
License:MIT License
/** * Unloads chunks that are marked to be unloaded. This is not guaranteed to * unload every such chunk./*from w w w . j a va 2 s . com*/ */ @SuppressWarnings("unused") public boolean unloadQueuedChunks() { if (canSave()) { if (this.newChunksToUnload > 0) { // This loop can get expensive depending on the number of chunk // loaded chunks that are currently active. for (final ChunkCoordIntPair forced : this.worldObj.getPersistentChunks().keySet()) { removeFromChunksToUnload(ChunkCoordIntPair.chunkXZ2Int(forced.chunkXPos, forced.chunkZPos)); } int throttle = 0; while (this.newChunksToUnload > 0 && throttle < UNLOAD_SAVE_LIMIT) { final long key = this.chunksToUnload[--this.newChunksToUnload]; final Chunk chunk = (Chunk) this.loadedChunkHashMap.getValueByKey(key); // Shouldn't get this, but better safe than sorry if (chunk == null) continue; // Let folks know the chunk is about to unload chunk.onChunkUnload(); // TODO: Does it always have to save regardless? onChunkUnload() // - may trigger chunk changes that are not captured in the // modified flag. if (ALWAYS_SAVE || chunk.needsSaving(true)) { throttle++; this.safeSaveChunk(chunk); this.safeSaveExtraChunkData(chunk); } // Cleanup removeFromLoadedChunks(chunk); this.loadedChunkHashMap.remove(key); ForgeChunkManager.putDormantChunk(key, chunk); // If we have no loaded chunks and the dimension is not // pinned in memory, unload the dimension. if (this.newLoadedChunk == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)) { DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); return this.currentChunkProvider.unloadQueuedChunks(); } } } if (this.currentChunkLoader != null) { this.currentChunkLoader.chunkTick(); } } return this.currentChunkProvider.unloadQueuedChunks(); }
From source file:org.spongepowered.mod.mixin.core.common.world.MixinDimensionManager.java
License:MIT License
@Overwrite public static boolean unloadWorldFromDimId(int id) { WorldServer world = DimensionManager.getWorld(id); if (world == null) { return true; }/*from w w w . java 2s.c o m*/ if (!world.playerEntities.isEmpty()) { return false; } if (((World) world).doesKeepSpawnLoaded()) { return false; } DimensionManager.unloadWorld(id); return true; }