diff --git a/patches/net/minecraft/world/WorldServer.java.patch b/patches/net/minecraft/world/WorldServer.java.patch index 95cdf36..c414883 100644 --- a/patches/net/minecraft/world/WorldServer.java.patch +++ b/patches/net/minecraft/world/WorldServer.java.patch @@ -1,5 +1,5 @@ ---- ../src-base/minecraft/net/minecraft/world/WorldServer.java -+++ ../src-work/minecraft/net/minecraft/world/WorldServer.java +--- a/../src-base/minecraft/net/minecraft/world/WorldServer.java ++++ b/../src-work/minecraft/net/minecraft/world/WorldServer.java @@ -1,8 +1,10 @@ package net.minecraft.world; @@ -278,10 +278,10 @@ + if (entityplayer.isPlayerFullyAsleep()) + { + foundActualSleepers = true; - } ++ } + } - while (entityplayer.isPlayerFullyAsleep()); - -+ } + while (entityplayer.isPlayerFullyAsleep() || entityplayer.fauxSleeping); + // CraftBukkit end return false; @@ -297,17 +297,17 @@ - while (iterator.hasNext()) + // Spigot start + for (gnu.trove.iterator.TLongShortIterator iter = activeChunkSet_CB.iterator(); iter.hasNext();) -+ { + { +- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next(); +- int k = chunkcoordintpair.chunkXPos * 16; +- int l = chunkcoordintpair.chunkZPos * 16; + iter.advance(); + long chunkCoord = iter.key(); + int chunkX = World.keyToX(chunkCoord); + int chunkZ = World.keyToZ(chunkCoord); + // If unloaded, or in process of being unloaded, drop it + if ((!this.chunkExists(chunkX, chunkZ)) || (this.theChunkProviderServer.chunksToUnload.contains(chunkX, chunkZ))) - { -- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next(); -- int k = chunkcoordintpair.chunkXPos * 16; -- int l = chunkcoordintpair.chunkZPos * 16; ++ { + activeChunkSet.remove(new ChunkCoordIntPair(chunkX, chunkZ)); // Cauldron - vanilla compatibility + iter.remove(); + continue; @@ -406,10 +406,11 @@ { throw new IllegalStateException("TickNextTick list out of synch"); } -@@ -506,8 +687,17 @@ +@@ -506,7 +687,16 @@ { if (i > 1000) { +- i = 1000; + // CraftBukkit start - If the server has too much to process over time, try to alleviate that + if (i > 20 * 1000) + { @@ -417,17 +418,17 @@ + } + else + { - i = 1000; - } ++ i = 1000; ++ } + // CraftBukkit end -+ } + } this.theProfiler.startSection("cleaning"); - NextTickListEntry nextticklistentry; @@ -651,7 +841,37 @@ protected IChunkProvider createChunkProvider() { IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider); +- this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); + // Cauldron start - if provider is vanilla, proceed to create a bukkit compatible chunk generator + if (this.provider.getClass().toString().length() <= 3 || this.provider.getClass().toString().contains("net.minecraft")) + { @@ -456,7 +457,7 @@ + else + // custom provider, load normally for forge compatibility + { - this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); ++ this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); + } + // Cauldron end return this.theChunkProviderServer; @@ -475,34 +476,35 @@ { - Chunk chunk = getChunkFromChunkCoords(x, z); - if (chunk != null) -- { -- for(Object obj : chunk.chunkTileEntityMap.values()) + Chunk chunk = getChunkFromChunkCoords(chunkX, chunkZ); + + if (chunk == null) { -- TileEntity entity = (TileEntity)obj; -- if (!entity.isInvalid()) +- for(Object obj : chunk.chunkTileEntityMap.values()) + continue; + } + + for (Object te : chunk.chunkTileEntityMap.values()) - { -- if (entity.xCoord >= p_147486_1_ && entity.yCoord >= p_147486_2_ && entity.zCoord >= p_147486_3_ && -- entity.xCoord <= p_147486_4_ && entity.yCoord <= p_147486_5_ && entity.zCoord <= p_147486_6_) ++ { + TileEntity tileentity = (TileEntity) te; + + if ((tileentity.xCoord >= p_147486_1_) && (tileentity.yCoord >= p_147486_2_) && (tileentity.zCoord >= p_147486_3_) + && (tileentity.xCoord < p_147486_4_) && (tileentity.yCoord < p_147486_5_) && (tileentity.zCoord < p_147486_6_)) { +- TileEntity entity = (TileEntity)obj; +- if (!entity.isInvalid()) +- { +- if (entity.xCoord >= p_147486_1_ && entity.yCoord >= p_147486_2_ && entity.zCoord >= p_147486_3_ && +- entity.xCoord <= p_147486_4_ && entity.yCoord <= p_147486_5_ && entity.zCoord <= p_147486_6_) +- { - arraylist.add(entity); +- } +- } + arraylist.add(tileentity); } } } } -- } -- } - + // CraftBukkit end return arraylist; @@ -641,6 +643,7 @@ this(); } } +-} + + // CraftBukkit start - Compatibility methods for BlockChangeDelegate + public boolean setRawTypeId(int x, int y, int z, int typeId) @@ -688,4 +691,4 @@ + return this.getBlock(x, y, z); + } + // CraftBukkit end - } ++} diff --git a/patches/net/minecraft/world/gen/ChunkProviderServer.java.patch b/patches/net/minecraft/world/gen/ChunkProviderServer.java.patch index 6680f7b..ce57ec1 100644 --- a/patches/net/minecraft/world/gen/ChunkProviderServer.java.patch +++ b/patches/net/minecraft/world/gen/ChunkProviderServer.java.patch @@ -1,5 +1,5 @@ ---- ../src-base/minecraft/net/minecraft/world/gen/ChunkProviderServer.java -+++ ../src-work/minecraft/net/minecraft/world/gen/ChunkProviderServer.java +--- a/../src-base/minecraft/net/minecraft/world/gen/ChunkProviderServer.java ++++ b/../src-work/minecraft/net/minecraft/world/gen/ChunkProviderServer.java @@ -1,7 +1,13 @@ package net.minecraft.world.gen; @@ -121,9 +121,9 @@ + if (c != null) + { + c.mustSave = true; - } ++ } + CauldronHooks.logChunkUnload(this, p_73241_1_, p_73241_2_, "Chunk added to unload queue"); -+ } + } + + // CraftBukkit end } @@ -163,11 +163,9 @@ + if(chunk == null || !chunk.isChunkLoaded) + { + if(chunk != null) - { -- Chunk chunk = (Chunk)iterator.next(); -- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); ++ { + cachet_KC.remove(hash); - } ++ } + chunk = (Chunk) chunk_get(x, z); + if(chunk != null) + { @@ -175,9 +173,11 @@ + } + } + if(cachet_KC.size() > 500) -+ { + { +- Chunk chunk = (Chunk)iterator.next(); +- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); + cachet_KC.clear(); -+ } + } + return chunk; } @@ -246,6 +246,7 @@ - this.loadedChunkHashMap.add(k, chunk); - this.loadedChunks.add(chunk); - loadingChunks.remove(k); +- chunk.onChunkLoad(); + this.loadedChunkHashMap_KC.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); + Chunk[][] temp_chunk_bunch = chunk_array_get(p_73158_1_, p_73158_2_); + if(temp_chunk_bunch != null) @@ -263,7 +264,7 @@ + + if (chunk != null) + { - chunk.onChunkLoad(); ++ chunk.onChunkLoad(); + } + // CraftBukkit start + Server server = this.worldObj.getServer(); @@ -330,9 +331,8 @@ + if (chunk == this.defaultEmptyChunk) + { + return chunk; - } - -- private Chunk safeLoadChunk(int p_73239_1_, int p_73239_2_) ++ } ++ + if ((p_73154_1_ != chunk.xPosition || p_73154_2_ != chunk.zPosition) && !worldObj.isProfilingWorld()) + { + logger.error("Chunk (" + chunk.xPosition + ", " + chunk.zPosition + ") stored at (" + p_73154_1_ + ", " + p_73154_2_ + ") in world '" + worldObj.getWorld().getName() + "'"); @@ -344,8 +344,9 @@ + chunk.lastAccessedTick = MinecraftServer.getServer().getTickCounter(); // Cauldron + return chunk; + // CraftBukkit end -+ } -+ + } + +- private Chunk safeLoadChunk(int p_73239_1_, int p_73239_2_) + public Chunk safeLoadChunk(int p_73239_1_, int p_73239_2_) // CraftBukkit - private -> public { if (this.currentChunkLoader == null) @@ -468,10 +469,10 @@ - for (ChunkCoordIntPair forced : this.worldObj.getPersistentChunks().keySet()) + // Cauldron start - remove any chunk that has a ticket associated with it + if (!this.chunksToUnload.isEmpty()) -+ { -+ for (ChunkCoordIntPair forcedChunk : this.worldObj.getPersistentChunks().keys()) - { + { - this.chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(forced.chunkXPos, forced.chunkZPos)); ++ for (ChunkCoordIntPair forcedChunk : this.worldObj.getPersistentChunks().keys()) ++ { + this.chunksToUnload.remove(forcedChunk.chunkXPos, forcedChunk.chunkZPos); + } } @@ -487,21 +488,30 @@ + Chunk chunk = this.loadedChunkHashMap_KC.get(chunkcoordinates); //Not using the IntMap for this + + if (chunk == null) - { -- Long olong = (Long)this.chunksToUnload.iterator().next(); -- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(olong.longValue()); ++ { + continue; + } - -- if (chunk != null) ++ + // Cauldron static - check if the chunk was accessed recently and keep it loaded if there are players in world + if (!shouldUnloadChunk(chunk) && this.worldObj.playerEntities.size() > 0) { +- Long olong = (Long)this.chunksToUnload.iterator().next(); +- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(olong.longValue()); + CauldronHooks.logChunkUnload(this, chunk.xPosition, chunk.zPosition, "** Chunk kept from unloading due to recent activity"); + continue; + } + // Cauldron end -+ + +- if (chunk != null) +- { +- chunk.onChunkUnload(); +- this.safeSaveChunk(chunk); +- this.safeSaveExtraChunkData(chunk); +- this.loadedChunks.remove(chunk); +- ForgeChunkManager.putDormantChunk(ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition), chunk); +- if(loadedChunks.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ +- DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); +- return currentChunkProvider.unloadQueuedChunks(); + + ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk); + server.getPluginManager().callEvent(event); @@ -510,9 +520,9 @@ + { + CauldronHooks.logChunkUnload(this, chunk.xPosition, chunk.zPosition, "Unloading Chunk at"); + - chunk.onChunkUnload(); - this.safeSaveChunk(chunk); - this.safeSaveExtraChunkData(chunk); ++ chunk.onChunkUnload(); ++ this.safeSaveChunk(chunk); ++ this.safeSaveExtraChunkData(chunk); + // Update neighbor counts + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { @@ -525,12 +535,13 @@ + neighbor.setNeighborUnloaded(-x, -z); + chunk.setNeighborUnloaded(x, z); + } -+ } -+ } + } + } +- +- this.chunksToUnload.remove(olong); +- this.loadedChunkHashMap.remove(olong.longValue()); + this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit - this.loadedChunks.remove(chunk); -- ForgeChunkManager.putDormantChunk(ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition), chunk); -- if(loadedChunks.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ ++ this.loadedChunks.remove(chunk); + Chunk[][] temp_bunch_array = chunk_array_get(chunk.xPosition, chunk.zPosition); + if(temp_bunch_array != null) + { @@ -542,14 +553,10 @@ + } + ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk); + if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ - DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); - return currentChunkProvider.unloadQueuedChunks(); - } ++ DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); ++ return currentChunkProvider.unloadQueuedChunks(); ++ } } -- -- this.chunksToUnload.remove(olong); -- this.loadedChunkHashMap.remove(olong.longValue()); -- } } + // CraftBukkit end @@ -575,6 +582,7 @@ } public void recreateStructures(int p_82695_1_, int p_82695_2_) {} +-} + + // Cauldron start + private boolean shouldLoadChunk() @@ -641,4 +649,4 @@ + } + } + // Cauldron end - } ++} diff --git a/patches/net/minecraftforge/common/chunkio/ChunkIOProvider.java.patch b/patches/net/minecraftforge/common/chunkio/ChunkIOProvider.java.patch index 55989a1..f99baf4 100644 --- a/patches/net/minecraftforge/common/chunkio/ChunkIOProvider.java.patch +++ b/patches/net/minecraftforge/common/chunkio/ChunkIOProvider.java.patch @@ -47,3 +47,9 @@ } chunk.populateChunk(queuedChunk.provider, queuedChunk.provider, queuedChunk.x, queuedChunk.z); +@@ -61,4 +87,4 @@ + thread.setDaemon(true); + return thread; + } +-} ++}