2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/ChunkRegionLoader.java
|
|
|
|
+++ b/net/minecraft/server/ChunkRegionLoader.java
|
2017-05-14 04:00:00 +02:00
|
|
|
@@ -29,19 +29,35 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
this.e = dataconvertermanager;
|
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 async variant, provide compatibility
|
2016-05-10 13:47:39 +02:00
|
|
|
@Nullable
|
2015-02-26 23:41:06 +01:00
|
|
|
public Chunk a(World world, int i, int j) throws IOException {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ Object[] data = loadChunk(world, i, j);
|
|
|
|
+ if (data != null) {
|
|
|
|
+ Chunk chunk = (Chunk) data[0];
|
|
|
|
+ NBTTagCompound nbttagcompound = (NBTTagCompound) data[1];
|
|
|
|
+ loadEntities(chunk, nbttagcompound.getCompound("Level"), world);
|
|
|
|
+ return chunk;
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return null;
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
|
|
|
+ public Object[] loadChunk(World world, int i, int j) throws IOException {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
|
2015-05-05 22:43:47 +02:00
|
|
|
NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.get(chunkcoordintpair);
|
|
|
|
|
2016-06-12 11:28:27 +02:00
|
|
|
if (nbttagcompound == null) {
|
2016-11-17 02:41:03 +01:00
|
|
|
- DataInputStream datainputstream = RegionFileCache.d(this.d, i, j);
|
2016-06-12 11:28:27 +02:00
|
|
|
+ // CraftBukkit start
|
2016-11-17 02:41:03 +01:00
|
|
|
+ nbttagcompound = RegionFileCache.d(this.d, i, j);
|
2016-06-12 11:28:27 +02:00
|
|
|
|
|
|
|
- if (datainputstream == null) {
|
|
|
|
+ if (nbttagcompound == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- nbttagcompound = this.e.a((DataConverterType) DataConverterTypes.CHUNK, NBTCompressedStreamTools.a(datainputstream));
|
|
|
|
+ nbttagcompound = this.e.a((DataConverterType) DataConverterTypes.CHUNK, nbttagcompound);
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
return this.a(world, i, j, nbttagcompound);
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -55,7 +71,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
@Nullable
|
2014-11-25 22:32:16 +01:00
|
|
|
- protected Chunk a(World world, int i, int j, NBTTagCompound nbttagcompound) {
|
|
|
|
+ protected Object[] a(World world, int i, int j, NBTTagCompound nbttagcompound) { // CraftBukkit - return Chunk -> Object[]
|
|
|
|
if (!nbttagcompound.hasKeyOfType("Level", 10)) {
|
2017-05-14 04:00:00 +02:00
|
|
|
ChunkRegionLoader.a.error("Chunk file at {},{} is missing level data, skipping", Integer.valueOf(i), Integer.valueOf(j));
|
2014-11-25 22:32:16 +01:00
|
|
|
return null;
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -72,10 +88,28 @@
|
2017-05-14 04:00:00 +02:00
|
|
|
ChunkRegionLoader.a.error("Chunk file at {},{} is in the wrong location; relocating. (Expected {}, {}, got {}, {})", Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(chunk.locX), Integer.valueOf(chunk.locZ));
|
2015-02-26 23:41:06 +01:00
|
|
|
nbttagcompound1.setInt("xPos", i);
|
|
|
|
nbttagcompound1.setInt("zPos", j);
|
|
|
|
+
|
|
|
|
+ // CraftBukkit start - Have to move tile entities since we don't load them at this stage
|
|
|
|
+ NBTTagList tileEntities = nbttagcompound.getCompound("Level").getList("TileEntities", 10);
|
|
|
|
+ if (tileEntities != null) {
|
|
|
|
+ for (int te = 0; te < tileEntities.size(); te++) {
|
|
|
|
+ NBTTagCompound tileEntity = (NBTTagCompound) tileEntities.get(te);
|
|
|
|
+ int x = tileEntity.getInt("x") - chunk.locX * 16;
|
|
|
|
+ int z = tileEntity.getInt("z") - chunk.locZ * 16;
|
|
|
|
+ tileEntity.setInt("x", i * 16 + x);
|
|
|
|
+ tileEntity.setInt("z", j * 16 + z);
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
chunk = this.a(world, nbttagcompound1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- return chunk;
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ Object[] data = new Object[2];
|
|
|
|
+ data[0] = chunk;
|
|
|
|
+ data[1] = nbttagcompound;
|
|
|
|
+ return data;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -106,20 +140,27 @@
|
2016-08-27 07:51:54 +02:00
|
|
|
}
|
|
|
|
|
2017-05-14 04:00:00 +02:00
|
|
|
public boolean a() {
|
2016-08-27 07:51:54 +02:00
|
|
|
- if (this.b.isEmpty()) {
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ Iterator<Map.Entry<ChunkCoordIntPair, NBTTagCompound>> iter = this.b.entrySet().iterator();
|
|
|
|
+ if (!iter.hasNext()) {
|
|
|
|
+ // CraftBukkit end
|
|
|
|
if (this.f) {
|
2017-05-14 04:00:00 +02:00
|
|
|
ChunkRegionLoader.a.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", this.d.getName());
|
2016-08-27 07:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) this.b.keySet().iterator().next();
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ Map.Entry<ChunkCoordIntPair, NBTTagCompound> entry = iter.next();
|
|
|
|
+ iter.remove(); // Pop single entry
|
|
|
|
+ ChunkCoordIntPair chunkcoordintpair = entry.getKey();
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
boolean flag;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.c.add(chunkcoordintpair);
|
|
|
|
- NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.remove(chunkcoordintpair);
|
|
|
|
+ NBTTagCompound nbttagcompound = (NBTTagCompound) entry.getValue(); // CraftBukkit
|
|
|
|
|
|
|
|
if (nbttagcompound != null) {
|
|
|
|
try {
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -139,10 +180,14 @@
|
2016-06-12 11:28:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void b(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
|
2016-11-17 02:41:03 +01:00
|
|
|
- DataOutputStream dataoutputstream = RegionFileCache.e(this.d, chunkcoordintpair.x, chunkcoordintpair.z);
|
2016-06-12 11:28:27 +02:00
|
|
|
+ // CraftBukkit start
|
2016-11-17 02:41:03 +01:00
|
|
|
+ RegionFileCache.e(this.d, chunkcoordintpair.x, chunkcoordintpair.z, nbttagcompound);
|
2016-06-12 11:28:27 +02:00
|
|
|
|
|
|
|
+ /*
|
|
|
|
NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
|
|
|
|
dataoutputstream.close();
|
|
|
|
+ */
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(World world, Chunk chunk) throws IOException {}
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -157,6 +202,7 @@
|
2017-05-14 04:00:00 +02:00
|
|
|
if (this.a()) {
|
2016-06-18 13:25:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
+ break; // CraftBukkit - Fix infinite loop when saving chunks
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
this.f = false;
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -334,6 +380,13 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
chunk.a(nbttagcompound.getByteArray("Biomes"));
|
|
|
|
}
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - End this method here and split off entity loading to another method
|
|
|
|
+ return chunk;
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public void loadEntities(Chunk chunk, NBTTagCompound nbttagcompound, World world) {
|
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
NBTTagList nbttaglist1 = nbttagcompound.getList("Entities", 10);
|
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
for (int l = 0; l < nbttaglist1.size(); ++l) {
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -371,7 +424,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- return chunk;
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // return chunk; // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
|
2016-05-10 13:47:39 +02:00
|
|
|
@Nullable
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -399,14 +452,20 @@
|
2016-06-09 03:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
+ // CraftBukkit start
|
|
|
|
public static Entity a(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag) {
|
|
|
|
+ return spawnEntity(nbttagcompound, world, d0, d1, d2, flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static Entity spawnEntity(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
|
|
+ // CraftBukkit end
|
|
|
|
Entity entity = a(nbttagcompound, world);
|
|
|
|
|
|
|
|
if (entity == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
entity.setPositionRotation(d0, d1, d2, entity.yaw, entity.pitch);
|
|
|
|
- if (flag && !world.addEntity(entity)) {
|
|
|
|
+ if (flag && !world.addEntity(entity, spawnReason)) { // CraftBukkit
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
if (nbttagcompound.hasKeyOfType("Passengers", 9)) {
|
2017-02-01 00:52:21 +01:00
|
|
|
@@ -435,8 +494,14 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
public static void a(Entity entity, World world) {
|
|
|
|
- if (world.addEntity(entity) && entity.isVehicle()) {
|
|
|
|
+ a(entity, world, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void a(Entity entity, World world, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
|
|
|
|
+ if (world.addEntity(entity, reason) && entity.isVehicle()) {
|
|
|
|
+ // CraftBukkit end
|
2017-05-14 04:00:00 +02:00
|
|
|
Iterator iterator = entity.bD().iterator();
|
2016-02-29 22:32:46 +01:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|