3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/ChunkRegionLoader.patch

128 Zeilen
5.2 KiB
Diff

2015-05-05 22:43:47 +02:00
--- /home/matt/mc-dev-private//net/minecraft/server/ChunkRegionLoader.java 2015-05-05 21:41:20.236645254 +0100
+++ src/main/java/net/minecraft/server/ChunkRegionLoader.java 2015-05-05 21:41:20.236645254 +0100
@@ -25,7 +25,35 @@
this.d = file;
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ public boolean chunkExists(World world, int i, int j) {
+ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
2014-11-29 21:00:52 +01:00
+
2015-05-05 22:43:47 +02:00
+ if (this.c.contains(chunkcoordintpair)) {
+ if (this.b.containsKey(chunkcoordintpair)) {
+ return true;
+ }
+ }
2015-02-26 23:41:06 +01:00
+
2015-05-05 22:43:47 +02:00
+ return RegionFileCache.a(this.d, i, j).chunkExists(i & 31, j & 31);
+ }
+ // CraftBukkit end
+
+ // CraftBukkit start - Add async variant, provide compatibility
2015-02-26 23:41:06 +01:00
public Chunk a(World world, int i, int j) throws IOException {
+ 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
+
+ return null;
+ }
2015-02-26 23:41:06 +01:00
+
+ public Object[] loadChunk(World world, int i, int j) throws IOException {
+ // CraftBukkit end
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
2015-05-05 22:43:47 +02:00
NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.get(chunkcoordintpair);
@@ -42,7 +70,7 @@
return this.a(world, i, j, nbttagcompound);
}
- 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)) {
ChunkRegionLoader.a.error("Chunk file at " + i + "," + j + " is missing level data, skipping");
return null;
2015-05-05 22:43:47 +02:00
@@ -59,10 +87,28 @@
2015-02-26 23:41:06 +01:00
ChunkRegionLoader.a.error("Chunk file at " + i + "," + j + " is in the wrong location; relocating. (Expected " + i + ", " + j + ", got " + chunk.locX + ", " + chunk.locZ + ")");
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);
+ }
+ }
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;
+ // CraftBukkit end
}
}
}
2015-05-05 22:43:47 +02:00
@@ -290,7 +336,26 @@
int k1 = l >> 4 & 15;
int l1 = nibblearray1 != null ? nibblearray1.a(i1, j1, k1) : 0;
2015-02-26 23:41:06 +01:00
- achar[l] = (char) (l1 << 12 | (abyte[l] & 255) << 4 | nibblearray.a(i1, j1, k1));
+ // CraftBukkit start - fix broken blocks
+ // achar[l] = (char) (l1 << 12 | (abyte[l] & 255) << 4 | nibblearray.a(i1, j1, k1));
2015-02-26 23:41:06 +01:00
+
+ int ex = l1;
+ int id = (abyte[l] & 255);
+ int data = nibblearray.a(i1, j1, k1);
+ int packed = ex << 12 | id << 4 | data;
+ if (Block.d.a(packed) == null) {
+ Block block = Block.getById(ex << 8 | id);
+ if (block != null) {
2014-11-29 21:00:52 +01:00
+ try {
+ data = block.toLegacyData(block.fromLegacyData(data));
+ } catch (Exception ignored) {
2014-11-30 00:25:17 +01:00
+ data = block.toLegacyData(block.getBlockData());
2014-11-29 21:00:52 +01:00
+ }
+ packed = ex << 12 | id << 4 | data;
+ }
+ }
+ achar[l] = (char) packed;
+ // CraftBukkit end
}
chunksection.a(achar);
2015-05-05 22:43:47 +02:00
@@ -308,6 +373,13 @@
chunk.a(nbttagcompound.getByteArray("Biomes"));
}
2015-02-26 23:41:06 +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
+
+ public void loadEntities(Chunk chunk, NBTTagCompound nbttagcompound, World world) {
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
NBTTagList nbttaglist1 = nbttagcompound.getList("Entities", 10);
if (nbttaglist1 != null) {
2015-05-05 22:43:47 +02:00
@@ -366,6 +438,6 @@
}
}
- return chunk;
2015-02-26 23:41:06 +01:00
+ // return chunk; // CraftBukkit
}
2015-05-05 22:43:47 +02:00
}