mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Regenerate and refresh chunk methods
By: Raphfrk <raphfrk@gmail.com>
This commit is contained in:
parent
0ee94a8a24
commit
3cc43d44f5
1 changed files with 69 additions and 23 deletions
|
@ -149,6 +149,48 @@ public class CraftWorld implements World {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean regenerateChunk(int x, int z) {
|
||||
unloadChunk(x, z, false, false);
|
||||
|
||||
provider.a.remove(x, z);
|
||||
|
||||
net.minecraft.server.Chunk chunk = null;
|
||||
|
||||
if(provider.c == null) {
|
||||
chunk = provider.b;
|
||||
} else {
|
||||
chunk = provider.c.b(x, z);
|
||||
}
|
||||
|
||||
chunkLoadPostProcess(chunk, x, z);
|
||||
|
||||
refreshChunk(x, z);
|
||||
|
||||
return chunk != null;
|
||||
}
|
||||
|
||||
public boolean refreshChunk(int x, int z) {
|
||||
if(!isChunkLoaded(x, z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int px = x<<4;
|
||||
int pz = z<<4;
|
||||
|
||||
// If there are more than 10 updates to a chunk at once, it carries out the update as a cuboid
|
||||
// This flags 16 blocks in a line along the bottom for update and then flags a block at the opposite corner at the top
|
||||
// The cuboid that contains these 17 blocks covers the entire chunk
|
||||
// The server will compress the chunk and send it to all clients
|
||||
|
||||
for(int xx = px; xx < (px + 16); xx++) {
|
||||
world.g(xx, 0, pz);
|
||||
}
|
||||
world.g(px, 127, pz+15);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isChunkInUse(int x, int z) {
|
||||
Player[] players = server.getOnlinePlayers();
|
||||
|
||||
|
@ -180,6 +222,12 @@ public class CraftWorld implements World {
|
|||
if (chunk == null) {
|
||||
chunk = provider.e(x, z);
|
||||
|
||||
chunkLoadPostProcess(chunk, x, z);
|
||||
}
|
||||
return chunk != null;
|
||||
}
|
||||
|
||||
private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int x, int z) {
|
||||
if (chunk != null) {
|
||||
provider.e.put(x, z, chunk);
|
||||
provider.f.add(chunk);
|
||||
|
@ -204,8 +252,6 @@ public class CraftWorld implements World {
|
|||
}
|
||||
}
|
||||
}
|
||||
return chunk != null;
|
||||
}
|
||||
|
||||
public boolean isChunkLoaded(Chunk chunk) {
|
||||
return isChunkLoaded(chunk.getX(), chunk.getZ());
|
||||
|
|
Loading…
Reference in a new issue