SPIGOT-2297: Reintroduce getChunkIfLoaded

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2016-05-22 11:36:38 +10:00
parent e5cc347b6e
commit ecb71842df

View file

@ -18,7 +18,7 @@
public final ChunkGenerator chunkGenerator; public final ChunkGenerator chunkGenerator;
private final IChunkLoader chunkLoader; private final IChunkLoader chunkLoader;
public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192); public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
@@ -69,19 +75,68 @@ @@ -69,19 +75,74 @@
Chunk chunk = this.getLoadedChunkAt(i, j); Chunk chunk = this.getLoadedChunkAt(i, j);
if (chunk == null) { if (chunk == null) {
@ -45,6 +45,12 @@
return chunk; return chunk;
} }
+ // CraftBukkit start
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return chunks.get(ChunkCoordIntPair.a(x, z));
+ }
+ // CraftBukkit end
+
public Chunk getChunkAt(int i, int j) { public Chunk getChunkAt(int i, int j) {
- Chunk chunk = this.getOrLoadChunkAt(i, j); - Chunk chunk = this.getOrLoadChunkAt(i, j);
+ return getChunkAt(i, j, null); + return getChunkAt(i, j, null);
@ -55,7 +61,7 @@
+ } + }
+ +
+ public Chunk getChunkAt(int i, int j, Runnable runnable, boolean generate) { + public Chunk getChunkAt(int i, int j, Runnable runnable, boolean generate) {
+ Chunk chunk = chunks.get(ChunkCoordIntPair.a(i, j)); + Chunk chunk = getChunkIfLoaded(i, j);
+ ChunkRegionLoader loader = null; + ChunkRegionLoader loader = null;
+ +
+ if (this.chunkLoader instanceof ChunkRegionLoader) { + if (this.chunkLoader instanceof ChunkRegionLoader) {
@ -89,7 +95,7 @@
if (chunk == null) { if (chunk == null) {
long k = ChunkCoordIntPair.a(i, j); long k = ChunkCoordIntPair.a(i, j);
@@ -97,9 +152,37 @@ @@ -97,9 +158,37 @@
crashreportsystemdetails.a("Generator", (Object) this.chunkGenerator); crashreportsystemdetails.a("Generator", (Object) this.chunkGenerator);
throw new ReportedException(crashreport); throw new ReportedException(crashreport);
} }
@ -116,7 +122,7 @@
+ continue; + continue;
+ } + }
+ +
+ Chunk neighbor = this.getLoadedChunkAt(chunk.locX + x, chunk.locZ + z); + Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
+ if (neighbor != null) { + if (neighbor != null) {
+ neighbor.setNeighborLoaded(-x, -z); + neighbor.setNeighborLoaded(-x, -z);
+ chunk.setNeighborLoaded(x, z); + chunk.setNeighborLoaded(x, z);
@ -127,7 +133,7 @@
chunk.loadNearby(this, this.chunkGenerator); chunk.loadNearby(this, this.chunkGenerator);
} }
@@ -146,10 +229,12 @@ @@ -146,10 +235,12 @@
public boolean a(boolean flag) { public boolean a(boolean flag) {
int i = 0; int i = 0;
@ -143,7 +149,7 @@
if (flag) { if (flag) {
this.saveChunkNOP(chunk); this.saveChunkNOP(chunk);
@@ -182,6 +267,29 @@ @@ -182,6 +273,29 @@
Chunk chunk = (Chunk) this.chunks.get(olong); Chunk chunk = (Chunk) this.chunks.get(olong);
if (chunk != null && chunk.d) { if (chunk != null && chunk.d) {
@ -161,7 +167,7 @@
+ continue; + continue;
+ } + }
+ +
+ Chunk neighbor = this.chunks.get(ChunkCoordIntPair.a(chunk.locX + x, chunk.locZ + z)); + Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
+ if (neighbor != null) { + if (neighbor != null) {
+ neighbor.setNeighborUnloaded(-x, -z); + neighbor.setNeighborUnloaded(-x, -z);
+ chunk.setNeighborUnloaded(x, z); + chunk.setNeighborUnloaded(x, z);