2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/net/minecraft/server/PlayerChunkMap.java
|
2016-05-10 13:47:39 +02:00
|
|
|
@@ -15,6 +15,10 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
import java.util.Set;
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import java.util.LinkedList;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
|
|
|
public class PlayerChunkMap {
|
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
private static final Predicate<EntityPlayer> a = new Predicate() {
|
2016-05-10 13:47:39 +02:00
|
|
|
@@ -46,6 +50,7 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
private long k;
|
|
|
|
private boolean l = true;
|
|
|
|
private boolean m = true;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ private boolean wasNotEmpty; // CraftBukkit - add field
|
|
|
|
|
|
|
|
public PlayerChunkMap(WorldServer worldserver) {
|
|
|
|
this.world = worldserver;
|
2016-12-06 12:05:58 +01:00
|
|
|
@@ -169,7 +174,11 @@
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // CraftBukkit start - SPIGOT-2891: remove once chunk has been provided
|
|
|
|
+ } else {
|
|
|
|
+ iterator1.remove();
|
|
|
|
}
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -231,6 +240,16 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
return playerchunk;
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - add method
|
|
|
|
+ public final boolean isChunkInUse(int x, int z) {
|
2016-05-10 13:47:39 +02:00
|
|
|
+ PlayerChunk pi = getChunk(x, z);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (pi != null) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ return (pi.c.size() > 0);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
public void flagDirty(BlockPosition blockposition) {
|
|
|
|
int i = blockposition.getX() >> 4;
|
2015-02-26 23:41:06 +01:00
|
|
|
int j = blockposition.getZ() >> 4;
|
2016-12-06 12:05:58 +01:00
|
|
|
@@ -249,12 +268,22 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
entityplayer.d = entityplayer.locX;
|
|
|
|
entityplayer.e = entityplayer.locZ;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Load nearby chunks first
|
|
|
|
+ List<ChunkCoordIntPair> chunkList = new LinkedList<ChunkCoordIntPair>();
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
for (int k = i - this.j; k <= i + this.j; ++k) {
|
|
|
|
for (int l = j - this.j; l <= j + this.j; ++l) {
|
|
|
|
- this.c(k, l).a(entityplayer);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ chunkList.add(new ChunkCoordIntPair(k, l));
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ Collections.sort(chunkList, new ChunkCoordComparator(entityplayer));
|
2015-02-26 23:41:06 +01:00
|
|
|
+ for (ChunkCoordIntPair pair : chunkList) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ this.c(pair.x, pair.z).a(entityplayer);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
this.managedPlayers.add(entityplayer);
|
2016-02-29 22:32:46 +01:00
|
|
|
this.e();
|
|
|
|
}
|
2016-12-06 12:05:58 +01:00
|
|
|
@@ -298,11 +327,14 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
int j1 = i - k;
|
|
|
|
int k1 = j - l;
|
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
+ List<ChunkCoordIntPair> chunksToLoad = new LinkedList<ChunkCoordIntPair>(); // CraftBukkit
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
if (j1 != 0 || k1 != 0) {
|
|
|
|
for (int l1 = i - i1; l1 <= i + i1; ++l1) {
|
|
|
|
for (int i2 = j - i1; i2 <= j + i1; ++i2) {
|
|
|
|
if (!this.a(l1, i2, k, l, i1)) {
|
2016-02-29 22:32:46 +01:00
|
|
|
- this.c(l1, i2).a(entityplayer);
|
|
|
|
+ // this.c(l1, i2).a(entityplayer);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.a(l1 - j1, i2 - k1, i, j, i1)) {
|
2016-12-06 12:05:58 +01:00
|
|
|
@@ -318,6 +350,13 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
entityplayer.d = entityplayer.locX;
|
|
|
|
entityplayer.e = entityplayer.locZ;
|
2016-02-29 22:32:46 +01:00
|
|
|
this.e();
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
|
|
|
+ // CraftBukkit start - send nearest chunks first
|
2014-11-25 22:32:16 +01:00
|
|
|
+ Collections.sort(chunksToLoad, new ChunkCoordComparator(entityplayer));
|
2015-02-26 23:41:06 +01:00
|
|
|
+ for (ChunkCoordIntPair pair : chunksToLoad) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ this.c(pair.x, pair.z).a(entityplayer);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-06 12:05:58 +01:00
|
|
|
@@ -402,4 +441,47 @@
|
2016-05-10 13:47:39 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Sorter to load nearby chunks first
|
|
|
|
+ private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
|
|
|
|
+ private int x;
|
|
|
|
+ private int z;
|
|
|
|
+
|
|
|
|
+ public ChunkCoordComparator (EntityPlayer entityplayer) {
|
|
|
|
+ x = (int) entityplayer.locX >> 4;
|
|
|
|
+ z = (int) entityplayer.locZ >> 4;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
|
|
|
|
+ if (a.equals(b)) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Subtract current position to set center point
|
|
|
|
+ int ax = a.x - this.x;
|
|
|
|
+ int az = a.z - this.z;
|
|
|
|
+ int bx = b.x - this.x;
|
|
|
|
+ int bz = b.z - this.z;
|
|
|
|
+
|
|
|
|
+ int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
|
|
|
|
+ if (result != 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ax < 0) {
|
|
|
|
+ if (bx < 0) {
|
|
|
|
+ return bz - az;
|
|
|
|
+ } else {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (bx < 0) {
|
|
|
|
+ return 1;
|
|
|
|
+ } else {
|
|
|
|
+ return az - bz;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|