Adds world unloading and hotloading calls

Adds world unloaded message to MinecraftServer on save.
Adds world unloading calls to chunk provider/manager when all chunks are
unloaded.
Adds call in MinecraftServer getWorld to hotload world if it isn't
loaded.
This commit is contained in:
XCompWiz 2012-10-03 02:37:27 +03:00
parent 32ca2b4fb0
commit bbc5673ad8
2 changed files with 51 additions and 11 deletions

View file

@ -95,7 +95,15 @@
this.setDifficultyForAllWorlds(this.getDifficulty());
this.initialWorldChunkLoad();
}
@@ -622,13 +602,13 @@
@@ -408,6 +388,7 @@
for (int var3 = 0; var3 < var2; ++var3)
{
WorldServer var4 = var1[var3];
+ MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(var4));
var4.flush();
}
@@ -622,13 +603,13 @@
{
this.theProfiler.startSection("levels");
@ -113,26 +121,36 @@
this.theProfiler.startSection(var4.getWorldInfo().getWorldName());
if (this.tickCounter % 20 == 0)
@@ -659,7 +639,7 @@
@@ -659,9 +640,11 @@
}
}
- this.timeOfLastDimensionTick[var1][this.tickCounter % 100] = System.nanoTime() - var2;
- }
-
+ worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - var2;
}
+ }
+
+ this.theProfiler.endStartSection("dim_unloading");
+ DimensionManager.unloadWorlds(worldTickTimes);
this.theProfiler.endStartSection("connection");
@@ -717,7 +697,8 @@
this.getNetworkThread().networkTick();
this.theProfiler.endStartSection("players");
@@ -717,7 +700,12 @@
*/
public WorldServer worldServerForDimension(int par1)
{
- return par1 == -1 ? this.worldServers[1] : (par1 == 1 ? this.worldServers[2] : this.worldServers[0]);
+ WorldServer ret = DimensionManager.getWorld(par1);
+ return (ret != null ? ret : DimensionManager.getWorld(0));
+ if (ret == null) {
+ DimensionManager.initDimension(par1);
+ ret = DimensionManager.getWorld(par1);
+ }
+ return ret;
}
@SideOnly(Side.SERVER)
@@ -830,7 +811,7 @@
@@ -830,7 +818,7 @@
public String getServerModName()
{
@ -141,3 +159,11 @@
}
/**
@@ -1104,6 +1092,7 @@
if (var2 != null)
{
+ MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(var2));
var2.flush();
}
}

View file

@ -1,15 +1,25 @@
--- ../src_base/common/net/minecraft/src/ChunkProviderServer.java
+++ ../src_work/common/net/minecraft/src/ChunkProviderServer.java
@@ -7,6 +7,8 @@
@@ -7,6 +7,9 @@
import java.util.List;
import java.util.Set;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.ForgeChunkManager;
+
import cpw.mods.fml.common.registry.GameRegistry;
public class ChunkProviderServer implements IChunkProvider
@@ -93,7 +95,11 @@
@@ -50,7 +53,7 @@
*/
public void unloadChunksIfNotNearSpawn(int par1, int par2)
{
- if (this.currentServer.provider.canRespawnHere())
+ if (this.currentServer.provider.canRespawnHere() && DimensionManager.shouldLoadSpawn(currentServer.provider.dimensionId))
{
ChunkCoordinates var3 = this.currentServer.getSpawnPoint();
int var4 = par1 * 16 + 8 - var3.posX;
@@ -93,7 +96,11 @@
if (var5 == null)
{
@ -22,7 +32,7 @@
if (var5 == null)
{
@@ -274,6 +280,11 @@
@@ -274,6 +281,11 @@
{
if (!this.currentServer.canNotSave)
{
@ -34,11 +44,15 @@
for (int var1 = 0; var1 < 100; ++var1)
{
if (!this.chunksToUnload.isEmpty())
@@ -286,6 +297,7 @@
@@ -286,6 +298,11 @@
this.chunksToUnload.remove(var2);
this.loadedChunkHashMap.remove(var2.longValue());
this.loadedChunks.remove(var3);
+ ForgeChunkManager.putDormantChunk(ChunkCoordIntPair.chunkXZ2Int(var3.xPosition, var3.zPosition), var3);
+ if(loadedChunks.size() == 0 && ForgeChunkManager.getPersistentChunksFor(currentServer).size() == 0 && !DimensionManager.shouldLoadSpawn(currentServer.provider.dimensionId)) {
+ DimensionManager.unloadWorld(currentServer.provider.dimensionId);
+ return currentChunkProvider.unload100OldestChunks();
+ }
}
}