Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan-G committed Jan 13, 2016
1 parent b7c025f commit acc46c3
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 163 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ build
fix_bug_comp
*.rej
clean_patch
symlink.bat
symlink.bat
hs_err_pid7636.log
364 changes: 364 additions & 0 deletions hs_err_pid7636.log

Large diffs are not rendered by default.

104 changes: 37 additions & 67 deletions patches/net/minecraft/world/gen/ChunkProviderServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,58 +1,25 @@
--- ../src-base/minecraft/net/minecraft/world/gen/ChunkProviderServer.java
+++ ../src-work/minecraft/net/minecraft/world/gen/ChunkProviderServer.java
@@ -1,7 +1,13 @@
package net.minecraft.world.gen;

import com.google.common.collect.Lists;
+
import cpw.mods.fml.common.registry.GameRegistry;
+import gnu.trove.impl.sync.TSynchronizedLongObjectMap;
+import gnu.trove.map.TLongObjectMap;
+import gnu.trove.map.hash.TLongObjectHashMap;
+import gnu.trove.procedure.TObjectProcedure;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -9,6 +15,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.EnumCreatureType;
@@ -33,22 +40,52 @@
@@ -32,23 +32,42 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

+
+
+
+
+// CraftBukkit start
+import java.util.Random;
+
+import net.minecraft.block.BlockSand;
+
+import org.bukkit.Server;
+import org.bukkit.craftbukkit.util.LongHash;
+import org.bukkit.craftbukkit.util.LongHashSet;
+import org.bukkit.craftbukkit.util.LongObjectHashMap;
+import org.bukkit.event.world.ChunkUnloadEvent;
+
+
+
+
+
+// CraftBukkit end
+// Cauldron start
+import cpw.mods.fml.common.FMLCommonHandler;
+import net.minecraft.server.MinecraftServer;
+import net.minecraftforge.cauldron.configuration.CauldronConfig;
+import net.minecraftforge.cauldron.CauldronHooks;
+// Cauldron end
+
-
public class ChunkProviderServer implements IChunkProvider
{
private static final Logger logger = LogManager.getLogger();
Expand All @@ -67,20 +34,21 @@
- public List loadedChunks = new ArrayList();
+ public boolean loadChunkOnProvideRequest = MinecraftServer.getServer().cauldronConfig.loadChunkOnRequest.getValue(); // Cauldron - if true, allows mods to force load chunks. to disable, set load-chunk-on-request in cauldron.yml to false
+ public int initialTick; // Cauldron counter to keep track of when this loader was created
+ public TLongObjectMap<Chunk> loadedChunkHashMap_KC = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>());
+ public LongObjectHashMap<Chunk> loadedChunkHashMap_KC = new LongObjectHashMap<Chunk>();
+ public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility
public WorldServer worldObj;
private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet();
+ public LongHashMap loadedChunkHashMap = new kcauldron.wrapper.VanillaChunkHashMap(loadedChunkHashMap_KC); // KCauldron - vanilla/mystcraft compatibility
private static final String __OBFID = "CL_00001436";
+ private boolean mUnloading;

public ChunkProviderServer(WorldServer p_i1520_1_, IChunkLoader p_i1520_2_, IChunkProvider p_i1520_3_)
{
+ this.initialTick = MinecraftServer.currentTick; // Cauldron keep track of when the loader was created
this.defaultEmptyChunk = new EmptyChunk(p_i1520_1_, 0, 0);
this.worldObj = p_i1520_1_;
this.currentChunkLoader = p_i1520_2_;
@@ -57,10 +94,10 @@
@@ -57,10 +76,10 @@

public boolean chunkExists(int p_73149_1_, int p_73149_2_)
{
Expand All @@ -93,7 +61,7 @@
{
return this.loadedChunks;
}
@@ -74,26 +111,45 @@
@@ -74,26 +93,47 @@
int l = p_73241_2_ * 16 + 8 - chunkcoordinates.posZ;
short short1 = 128;

Expand Down Expand Up @@ -132,36 +100,33 @@
public void unloadAllChunks()
{
- Iterator iterator = this.loadedChunks.iterator();
-
- while (iterator.hasNext())
- {
- Chunk chunk = (Chunk)iterator.next();
- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
- }
+ this.loadedChunkHashMap_KC.forEachValue(new TObjectProcedure<Chunk>() {
+ @Override
+ public boolean execute(Chunk chunk) {
+ unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
+ return true;
+ }
+ });
+ mUnloading = true;
+ Iterator iterator = this.loadedChunkHashMap_KC.values().iterator(); // CraftBukkit

while (iterator.hasNext())
{
Chunk chunk = (Chunk)iterator.next();
this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
}
+ mUnloading = false;
}

public Chunk loadChunk(int p_73158_1_, int p_73158_2_)
@@ -103,9 +159,9 @@
@@ -103,9 +143,10 @@

public Chunk loadChunk(int par1, int par2, Runnable runnable)
{
- long k = ChunkCoordIntPair.chunkXZ2Int(par1, par2);
- this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ if (mUnloading) return null;
+ this.chunksToUnload.remove(par1, par2);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(par1, par2));
+ boolean newChunk = false;
AnvilChunkLoader loader = null;

if (this.currentChunkLoader instanceof AnvilChunkLoader)
@@ -113,6 +169,8 @@
@@ -113,6 +154,8 @@
loader = (AnvilChunkLoader) this.currentChunkLoader;
}

Expand All @@ -170,13 +135,14 @@
// We can only use the queue for already generated chunks
if (chunk == null && loader != null && loader.chunkExists(this.worldObj, par1, par2))
{
@@ -142,18 +200,19 @@
@@ -142,18 +185,20 @@

public Chunk originalLoadChunk(int p_73158_1_, int p_73158_2_)
{
- long k = ChunkCoordIntPair.chunkXZ2Int(p_73158_1_, p_73158_2_);
- this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ if (mUnloading) return null;
+ this.chunksToUnload.remove(p_73158_1_, p_73158_2_);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73158_1_, p_73158_2_));
+ boolean newChunk = false; // CraftBukkit
Expand All @@ -195,7 +161,7 @@
if (chunk == null)
{
chunk = this.safeLoadChunk(p_73158_1_, p_73158_2_);
@@ -176,18 +235,39 @@
@@ -176,18 +221,39 @@
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception generating new chunk");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Chunk to be generated");
crashreportcategory.addCrashSection("Location", String.format("%d,%d", new Object[] {Integer.valueOf(p_73158_1_), Integer.valueOf(p_73158_2_)}));
Expand Down Expand Up @@ -240,12 +206,13 @@
}

return chunk;
@@ -195,11 +275,29 @@
@@ -195,13 +262,32 @@

public Chunk provideChunk(int p_73154_1_, int p_73154_2_)
{
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(p_73154_1_, p_73154_2_));
- return chunk == null ? (!this.worldObj.findingSpawnPoint && !this.loadChunkOnProvideRequest ? this.defaultEmptyChunk : this.loadChunk(p_73154_1_, p_73154_2_)) : chunk;
+ if (mUnloading) return null;
+ // CraftBukkit start
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73154_1_, p_73154_2_));
+ chunk = chunk == null ? (shouldLoadChunk() ? this.loadChunk(p_73154_1_, p_73154_2_) : this.defaultEmptyChunk) : chunk; // Cauldron handle forge server tick events and load the chunk within 5 seconds of the world being loaded (for chunk loaders)
Expand All @@ -271,17 +238,20 @@
- 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)
- if (this.currentChunkLoader == null)
+ if (mUnloading || this.currentChunkLoader == null)
{
@@ -209,6 +307,7 @@
- return null;
- }
@@ -209,6 +296,7 @@
{
try
{
+ CauldronHooks.logChunkLoad(this, "Safe Load", p_73239_1_, p_73239_2_, false); // Cauldron
Chunk chunk = this.currentChunkLoader.loadChunk(this.worldObj, p_73239_1_, p_73239_2_);

if (chunk != null)
@@ -217,8 +316,11 @@
@@ -217,8 +305,11 @@

if (this.currentChunkProvider != null)
{
Expand All @@ -293,7 +263,7 @@
}

return chunk;
@@ -231,7 +333,7 @@
@@ -231,7 +322,7 @@
}
}

Expand All @@ -302,7 +272,7 @@
{
if (this.currentChunkLoader != null)
{
@@ -246,7 +348,7 @@
@@ -246,7 +337,7 @@
}
}

Expand All @@ -311,7 +281,7 @@
{
if (this.currentChunkLoader != null)
{
@@ -254,15 +356,18 @@
@@ -254,15 +343,18 @@
{
p_73242_1_.lastSaveTime = this.worldObj.getTotalWorldTime();
this.currentChunkLoader.saveChunk(this.worldObj, p_73242_1_);
Expand All @@ -331,7 +301,7 @@
}
}

@@ -277,6 +382,35 @@
@@ -277,6 +369,35 @@
if (this.currentChunkProvider != null)
{
this.currentChunkProvider.populate(p_73153_1_, p_73153_2_, p_73153_3_);
Expand Down Expand Up @@ -367,7 +337,7 @@
GameRegistry.generateWorld(p_73153_2_, p_73153_3_, worldObj, currentChunkProvider, p_73153_1_);
chunk.setChunkModified();
}
@@ -286,11 +420,13 @@
@@ -286,11 +407,13 @@
public boolean saveChunks(boolean p_73151_1_, IProgressUpdate p_73151_2_)
{
int i = 0;
Expand All @@ -384,7 +354,7 @@

if (p_73151_1_)
{
@@ -325,36 +461,60 @@
@@ -325,36 +448,60 @@
{
if (!this.worldObj.levelSaving)
{
Expand Down Expand Up @@ -465,7 +435,7 @@
if (this.currentChunkLoader != null)
{
this.currentChunkLoader.chunkTick();
@@ -371,7 +531,7 @@
@@ -371,7 +518,7 @@

public String makeString()
{
Expand All @@ -474,7 +444,7 @@
}

public List getPossibleCreatures(EnumCreatureType p_73155_1_, int p_73155_2_, int p_73155_3_, int p_73155_4_)
@@ -386,8 +546,31 @@
@@ -386,8 +533,31 @@

public int getLoadedChunkCount()
{
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/kcauldron/wrapper/LongHashMapTrove.java

This file was deleted.

36 changes: 0 additions & 36 deletions src/main/java/kcauldron/wrapper/VanillaChunkHashMap.java

This file was deleted.

Loading

0 comments on commit acc46c3

Please sign in to comment.