Browse Source

Patch files aren't my thing

I didn't understand exactly how to use patch files, I think I'm getting closer though with this commit...!
(Sorry for the frequent commits).
master
Sam 9 years ago
parent
commit
e986b7b9ff
  1. 49
      patches/net/minecraft/world/gen/ChunkProviderServer.java.patch

49
patches/net/minecraft/world/gen/ChunkProviderServer.java.patch

@ -67,8 +67,7 @@
- public List loadedChunks = new ArrayList(); - 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 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 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 TLongObjectMap<Chunk> loadedChunkHashMap_KC = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>()); public ConcurrentHashMap<Integer,Chunk> chunkt_KC = new ConcurrentHashMap<Integer,Chunk>();
+ public ConcurrentHashMap<Integer,Chunk> chunkt_KC = new ConcurrentHashMap<Integer,Chunk>();
+ public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility + public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility
public WorldServer worldObj; public WorldServer worldObj;
private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet(); private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet();
@ -86,8 +85,7 @@
public boolean chunkExists(int p_73149_1_, int p_73149_2_) public boolean chunkExists(int p_73149_1_, int p_73149_2_)
{ {
- return this.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(p_73149_1_, p_73149_2_)); - return this.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(p_73149_1_, p_73149_2_));
+ //return this.loadedChunkHashMap_KC.containsKey(LongHash.toLong(p_73149_1_, p_73149_2_)); // CraftBukkit + return this.chunkt_KC.containsKey(chunk_hash(p_73149_1_, p_73149_2_)); //KCauldron Replacement
+ return this.chunkt_KC.containsKey(chunk_hash(p_73149_1_, p_73149_2_)); //KCauldron Replacement for line above
} }
- public List func_152380_a() - public List func_152380_a()
@ -95,17 +93,12 @@
{ {
return this.loadedChunks; return this.loadedChunks;
} }
+
+ public static int chunk_hash(int x, int y)
+ {
+ return ((x & 0xFFFF) << 16) | (y & 0xFFFF);
+ }
public void unloadChunksIfNotNearSpawn(int p_73241_1_, int p_73241_2_) public void unloadChunksIfNotNearSpawn(int p_73241_1_, int p_73241_2_)
{ {
+ // PaperSpigot start - Asynchronous lighting updates + // PaperSpigot start - Asynchronous lighting updates
+ //Chunk chunk = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + Chunk chunk = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement
+ Chunk chunk = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ if (chunk != null && chunk.worldObj.spigotConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.worldObj.getTotalWorldTime() - chunk.lightUpdateTime < 20)) { + if (chunk != null && chunk.worldObj.spigotConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.worldObj.getTotalWorldTime() - chunk.lightUpdateTime < 20)) {
+ return; + return;
+ } + }
@ -122,8 +115,7 @@
{ {
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_))); - this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_); + this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ //Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement
+ Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ +
+ if (c != null) + if (c != null)
+ { + {
@ -139,8 +131,7 @@
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_))); - this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ // CraftBukkit start + // CraftBukkit start
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_); + this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ //Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement
+ Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ +
+ if (c != null) + if (c != null)
+ { + {
@ -169,8 +160,7 @@
- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); - this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
- } - }
+ public Chunk getChunkIfLoaded(int x, int z) { + public Chunk getChunkIfLoaded(int x, int z) {
+ //return this.loadedChunkHashMap_KC.get(LongHash.toLong(x, z)); + return this.chunkt_KC.get(chunk_hash(x,z)); //KCauldron replacement
+ return this.chunkt_KC.get(chunk_hash(x,z)); //KCauldron replacement for line above
} }
public Chunk loadChunk(int p_73158_1_, int p_73158_2_) public Chunk loadChunk(int p_73158_1_, int p_73158_2_)
@ -182,8 +172,7 @@
- this.chunksToUnload.remove(Long.valueOf(k)); - this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k); - Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(par1, par2); + this.chunksToUnload.remove(par1, par2);
+ //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(par1, par2)); + Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(par1,par2)); //KCauldron replacement
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(par1,par2)); //KCauldron replacement for line above
+ boolean newChunk = false; + boolean newChunk = false;
AnvilChunkLoader loader = null; AnvilChunkLoader loader = null;
@ -205,8 +194,7 @@
- this.chunksToUnload.remove(Long.valueOf(k)); - this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k); - Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(p_73158_1_, p_73158_2_); + this.chunksToUnload.remove(p_73158_1_, p_73158_2_);
+ //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ boolean newChunk = false; // CraftBukkit + boolean newChunk = false; // CraftBukkit
if (chunk == null) if (chunk == null)
@ -290,8 +278,7 @@
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(p_73154_1_, 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; - return chunk == null ? (!this.worldObj.findingSpawnPoint && !this.loadChunkOnProvideRequest ? this.defaultEmptyChunk : this.loadChunk(p_73154_1_, p_73154_2_)) : chunk;
+ // CraftBukkit start + // CraftBukkit start
+ //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73154_1_, p_73154_2_)); + Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73154_1_, p_73154_2_)); //KCauldron replacement
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73154_1_, p_73154_2_)); //KCauldron replacement for line above
+ 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) + 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)
+ +
+ if (chunk == this.defaultEmptyChunk) + if (chunk == this.defaultEmptyChunk)
@ -507,8 +494,7 @@
- this.chunksToUnload.remove(olong); - this.chunksToUnload.remove(olong);
- this.loadedChunkHashMap.remove(olong.longValue()); - this.loadedChunkHashMap.remove(olong.longValue());
+ this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit + this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit
+ this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility + this.loadedChunks.remove(chunk); this.chunkt_KC.remove(chunk_hash(chunk.xPosition,chunk.zPosition)); //KCauldron - IntHashMap
+ this.chunkt_KC.remove(chunk_hash(chunk.xPosition,chunk.zPosition)); //KCauldron - IntHashMap
+ ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk); + ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk);
+ if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ + if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
+ DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); + DimensionManager.unloadWorld(this.worldObj.provider.dimensionId);
@ -552,11 +538,9 @@
+ +
+ public long lastAccessed(int x, int z) + public long lastAccessed(int x, int z)
+ { + {
+ //long chunkHash = LongHash.toLong(x, z); + int chunkHash = chunk_hash(x,z);
+ //if (!loadedChunkHashMap_KC.containsKey(chunkHash)) return 0; + if (!chunkt_KC.containsKey(chunkHash)) return 0;
+ //return loadedChunkHashMap_KC.get(chunkHash).lastAccessedTick; + return chunkt_KC.get(chunkHash).lastAccessedTick;
+ if (!chunkt_KC.containsKey(chunk_hash(x,z))) return 0;
+ return chunkt_KC.get(chunk_hash(x,z)).lastAccessedTick;
+ } + }
+ +
+ private boolean shouldUnloadChunk(Chunk chunk) + private boolean shouldUnloadChunk(Chunk chunk)
@ -564,5 +548,10 @@
+ if (chunk == null) return false; + if (chunk == null) return false;
+ return MinecraftServer.getServer().getTickCounter() - chunk.lastAccessedTick > MinecraftServer.getServer().cauldronConfig.chunkGCGracePeriod.getValue(); + return MinecraftServer.getServer().getTickCounter() - chunk.lastAccessedTick > MinecraftServer.getServer().cauldronConfig.chunkGCGracePeriod.getValue();
+ } + }
+
+ public static int chunk_hash(int x, int y)
+ {
+ return ((x & 0xFFFF) << 16) | (y & 0xFFFF);
+ }
+ // Cauldron end + // Cauldron end
} }

Loading…
Cancel
Save