diff options
author | md_5 <git@md-5.net> | 2016-03-01 08:32:46 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-03-01 09:32:45 +1100 |
commit | aa008dff0f9bedbe88e1fe79831776b0a52eb90a (patch) | |
tree | cb520e0f4cc5d683fb9b7fb95de37480a7443dfb /nms-patches/ChunkProviderServer.patch | |
parent | e1ebe524a78e27f6a2829ed4574fded3779094e1 (diff) | |
download | craftbukkit-aa008dff0f9bedbe88e1fe79831776b0a52eb90a.tar craftbukkit-aa008dff0f9bedbe88e1fe79831776b0a52eb90a.tar.gz craftbukkit-aa008dff0f9bedbe88e1fe79831776b0a52eb90a.tar.lz craftbukkit-aa008dff0f9bedbe88e1fe79831776b0a52eb90a.tar.xz craftbukkit-aa008dff0f9bedbe88e1fe79831776b0a52eb90a.zip |
Update to Minecraft 1.9
Diffstat (limited to 'nms-patches/ChunkProviderServer.patch')
-rw-r--r-- | nms-patches/ChunkProviderServer.patch | 219 |
1 files changed, 96 insertions, 123 deletions
diff --git a/nms-patches/ChunkProviderServer.patch b/nms-patches/ChunkProviderServer.patch index 65c21678..6c5d4e25 100644 --- a/nms-patches/ChunkProviderServer.patch +++ b/nms-patches/ChunkProviderServer.patch @@ -1,12 +1,21 @@ --- a/net/minecraft/server/ChunkProviderServer.java +++ b/net/minecraft/server/ChunkProviderServer.java -@@ -11,16 +11,27 @@ +@@ -1,24 +1,31 @@ + package net.minecraft.server; + +-import com.google.common.collect.Lists; + import java.io.IOException; +-import java.util.ArrayList; +-import java.util.Collections; + import java.util.Iterator; + import java.util.List; +-import java.util.Set; +-import java.util.concurrent.ConcurrentHashMap; ++ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// CraftBukkit start -+import java.util.Random; -+import java.util.logging.Level; + +import org.bukkit.Server; +import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor; @@ -18,30 +27,30 @@ + public class ChunkProviderServer implements IChunkProvider { - private static final Logger b = LogManager.getLogger(); -- private Set<Long> unloadQueue = Collections.newSetFromMap(new ConcurrentHashMap()); -+ public LongHashSet unloadQueue = new LongHashSet(); // CraftBukkit - LongHashSet - public Chunk emptyChunk; - public IChunkProvider chunkProvider; - private IChunkLoader chunkLoader; -- public boolean forceChunkLoad = true; -- private LongHashMap<Chunk> chunks = new LongHashMap(); -- private List<Chunk> chunkList = Lists.newArrayList(); -+ public boolean forceChunkLoad = false; // CraftBukkit - true -> false -+ public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>(); - public WorldServer world; - - public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) { -@@ -31,26 +42,43 @@ - } + private static final Logger a = LogManager.getLogger(); +- private final Set<Long> unloadQueue = Collections.newSetFromMap(new ConcurrentHashMap()); +- private final ChunkGenerator chunkGenerator; ++ public final LongHashSet unloadQueue = new LongHashSet(); // CraftBukkit - LongHashSet ++ public final ChunkGenerator chunkGenerator; // CraftBukkit - public + private final IChunkLoader chunkLoader; +- private final LongHashMap<Chunk> chunks = new LongHashMap(); +- private final List<Chunk> chunkList = Lists.newArrayList(); ++ public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>(); // CraftBukkit ++ // private final LongHashMap<Chunk> chunks = new LongHashMap(); ++ // private final List<Chunk> chunkList = Lists.newArrayList(); + public final WorldServer world; - public boolean isChunkLoaded(int i, int j) { -- return this.chunks.contains(ChunkCoordIntPair.a(i, j)); -+ return this.chunks.containsKey(LongHash.toLong(i, j)); // CraftBukkit + public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) { +@@ -27,19 +34,33 @@ + this.chunkGenerator = chunkgenerator; } - public List<Chunk> a() { - return this.chunkList; ++ public boolean isChunkLoaded(int i, int j) { ++ return this.chunks.containsKey(LongHash.toLong(i, j)); // CraftBukkit ++ } ++ + // CraftBukkit start - Change return type to Collection and return the values of our chunk map + public java.util.Collection a() { + // return this.chunkList; @@ -50,19 +59,7 @@ } public void queueUnload(int i, int j) { - if (this.world.worldProvider.e()) { - if (!this.world.c(i, j)) { -- this.unloadQueue.add(Long.valueOf(ChunkCoordIntPair.a(i, j))); -+ // CraftBukkit start -+ this.unloadQueue.add(i, j); -+ -+ Chunk c = chunks.get(LongHash.toLong(i, j)); -+ if (c != null) { -+ c.mustSave = true; -+ } -+ // CraftBukkit end - } - } else { + if (this.world.worldProvider.c(i, j)) { - this.unloadQueue.add(Long.valueOf(ChunkCoordIntPair.a(i, j))); + // CraftBukkit start + this.unloadQueue.add(i, j); @@ -78,11 +75,11 @@ public void b() { - Iterator iterator = this.chunkList.iterator(); -+ Iterator iterator = this.chunks.values().iterator(); ++ Iterator iterator = this.chunks.values().iterator(); // CraftBukkit while (iterator.hasNext()) { Chunk chunk = (Chunk) iterator.next(); -@@ -60,11 +88,48 @@ +@@ -49,11 +70,15 @@ } @@ -91,8 +88,45 @@ + return chunks.get(LongHash.toLong(x, z)); + } + - public Chunk getChunkAt(int i, int j) { + public Chunk getLoadedChunkAt(int i, int j) { - long k = ChunkCoordIntPair.a(i, j); +- Chunk chunk = (Chunk) this.chunks.getEntry(k); ++ Chunk chunk = chunks.get(LongHash.toLong(i, j)); // CraftBukkit + +- this.unloadQueue.remove(Long.valueOf(k)); ++ this.unloadQueue.remove(i, j); // CraftBukkit + return chunk; + } + +@@ -61,20 +86,66 @@ + Chunk chunk = this.getLoadedChunkAt(i, j); + + if (chunk == null) { +- chunk = this.loadChunk(i, j); ++ // CraftBukkit start ++ ChunkRegionLoader loader = null; ++ ++ if (this.chunkLoader instanceof ChunkRegionLoader) { ++ loader = (ChunkRegionLoader) this.chunkLoader; ++ } ++ if (loader != null && loader.chunkExists(world, i, j)) { ++ chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j); ++ } ++ /* chunk = this.loadChunk(i, j); + if (chunk != null) { + this.chunks.put(ChunkCoordIntPair.a(i, j), chunk); + this.chunkList.add(chunk); + chunk.addEntities(); + chunk.loadNearby(this, this.chunkGenerator); + } ++ */ ++ // CraftBukkit end + } + + return chunk; + } + + public Chunk getChunkAt(int i, int j) { + return getChunkAt(i, j, null); + } + @@ -103,9 +137,7 @@ + + if (this.chunkLoader instanceof ChunkRegionLoader) { + loader = (ChunkRegionLoader) this.chunkLoader; - -- this.unloadQueue.remove(Long.valueOf(k)); -- Chunk chunk = (Chunk) this.chunks.getEntry(k); ++ + } + // We can only use the queue for already generated chunks + if (chunk == null && loader != null && loader.chunkExists(world, i, j)) { @@ -126,33 +158,26 @@ + + return chunk; + } ++ + public Chunk originalGetChunkAt(int i, int j) { -+ this.unloadQueue.remove(i, j); -+ Chunk chunk = (Chunk) this.chunks.get(LongHash.toLong(i, j)); + Chunk chunk = this.getOrLoadChunkAt(i, j); + boolean newChunk = false; + // CraftBukkit end if (chunk == null) { - chunk = this.loadChunk(i, j); -@@ -79,16 +144,44 @@ - CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Chunk to be generated"); - - crashreportsystemdetails.a("Location", (Object) String.format("%d,%d", new Object[] { Integer.valueOf(i), Integer.valueOf(j)})); -- crashreportsystemdetails.a("Position hash", (Object) Long.valueOf(k)); -+ crashreportsystemdetails.a("Position hash", (Object) Long.valueOf(LongHash.toLong(i, j))); // CraftBukkit - Use LongHash - crashreportsystemdetails.a("Generator", (Object) this.chunkProvider.getName()); - throw new ReportedException(crashreport); - } + long k = ChunkCoordIntPair.a(i, j); +@@ -92,11 +163,38 @@ + crashreportsystemdetails.a("Generator", (Object) this.chunkGenerator); + throw new ReportedException(crashreport); } + newChunk = true; // CraftBukkit } - this.chunks.put(k, chunk); - this.chunkList.add(chunk); -+ this.chunks.put(LongHash.toLong(i, j), chunk); -+ ++ this.chunks.put(LongHash.toLong(i, j), chunk); // CraftBukkit chunk.addEntities(); -+ ++ + // CraftBukkit start + Server server = world.getServer(); + if (server != null) { @@ -179,68 +204,12 @@ + } + } + // CraftBukkit end - chunk.loadNearby(this, this, i, j); + chunk.loadNearby(this, this.chunkGenerator); } -@@ -96,9 +189,22 @@ - } - - public Chunk getOrCreateChunk(int i, int j) { -- Chunk chunk = (Chunk) this.chunks.getEntry(ChunkCoordIntPair.a(i, j)); -+ // CraftBukkit start -+ Chunk chunk = (Chunk) this.chunks.get(LongHash.toLong(i, j)); -+ -+ chunk = chunk == null ? (!this.world.ad() && !this.forceChunkLoad ? this.emptyChunk : this.getChunkAt(i, j)) : chunk; -+ -+ if (chunk == emptyChunk) return chunk; -+ if (i != chunk.locX || j != chunk.locZ) { -+ b.error("Chunk (" + chunk.locX + ", " + chunk.locZ + ") stored at (" + i + ", " + j + ") in world '" + world.getWorld().getName() + "'"); -+ b.error(chunk.getClass().getName()); -+ Throwable ex = new Throwable(); -+ ex.fillInStackTrace(); -+ ex.printStackTrace(); -+ } +@@ -142,10 +240,12 @@ -- return chunk == null ? (!this.world.ad() && !this.forceChunkLoad ? this.emptyChunk : this.getChunkAt(i, j)) : chunk; -+ return chunk; -+ // CraftBukkit end - } - - public Chunk loadChunk(int i, int j) { -@@ -155,6 +261,30 @@ - chunk.n(); - if (this.chunkProvider != null) { - this.chunkProvider.getChunkAt(ichunkprovider, i, j); -+ -+ // CraftBukkit start -+ BlockSand.instaFall = true; -+ Random random = new Random(); -+ random.setSeed(world.getSeed()); -+ long xRand = random.nextLong() / 2L * 2L + 1L; -+ long zRand = random.nextLong() / 2L * 2L + 1L; -+ random.setSeed((long) i * xRand + (long) j * zRand ^ world.getSeed()); -+ -+ org.bukkit.World world = this.world.getWorld(); -+ if (world != null) { -+ this.world.populating = true; -+ try { -+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) { -+ populator.populate(world, random, chunk.bukkitChunk); -+ } -+ } finally { -+ this.world.populating = false; -+ } -+ } -+ BlockSand.instaFall = false; -+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(chunk.bukkitChunk)); -+ // CraftBukkit end -+ - chunk.e(); - } - } -@@ -174,10 +304,12 @@ - - public boolean saveChunks(boolean flag, IProgressUpdate iprogressupdate) { + public boolean a(boolean flag) { int i = 0; - ArrayList arraylist = Lists.newArrayList(this.chunkList); @@ -254,7 +223,7 @@ if (flag) { this.saveChunkNOP(chunk); -@@ -205,22 +337,43 @@ +@@ -170,22 +270,43 @@ public boolean unloadChunks() { if (!this.world.savingDisabled) { @@ -303,9 +272,9 @@ } + // CraftBukkit end - if (this.chunkLoader != null) { - this.chunkLoader.a(); -@@ -235,7 +388,8 @@ + this.chunkLoader.a(); + } +@@ -198,7 +319,8 @@ } public String getName() { @@ -314,14 +283,18 @@ + return "ServerChunkCache: " + this.chunks.size() + " Drop: " + this.unloadQueue.size(); } - public List<BiomeBase.BiomeMeta> getMobsFor(EnumCreatureType enumcreaturetype, BlockPosition blockposition) { -@@ -247,7 +401,8 @@ + public List<BiomeBase.BiomeMeta> a(EnumCreatureType enumcreaturetype, BlockPosition blockposition) { +@@ -210,10 +332,11 @@ } - public int getLoadedChunks() { + public int g() { - return this.chunks.count(); + // CraftBukkit - this.chunks.count() -> this.chunks.size() + return this.chunks.size(); } - public void recreateStructures(Chunk chunk, int i, int j) {} + public boolean e(int i, int j) { +- return this.chunks.contains(ChunkCoordIntPair.a(i, j)); ++ return this.chunks.containsKey(LongHash.toLong(i, j)); // CraftBukkit + } + } |