Implement extended world heights from Y-64 to Y319 #3473 (#3473)

* Begin to implement extended world heights:
 - Implemented in Bukkit module (and where required in Core module)

* Implement extended world heights into core module

* Add min gen height to setup,

* Default gen/build heights based on minecraft version

* Few fixes

* Fix up queues

* Address comments

* Make road schematic stuff slightly more efficient by sharing queues

* Minor fixes, don't overlay error many times for the same y

* Fix incorrect schematic paste height, undo changes to HybridUtils

* Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish

* Process chunks in order when regenerating all roads

* Address comments

* Address comments

* Ground level//bedrock is at min gen height
 - Add comment on == rather than <= being used
 - It's because it's only checking for the bedrock layer being broken if that's disabled

* Fix offset for min build height in SchematicHandler

* Better javadoc

Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>

* Address inclusivity issues for max world height

* Javadocs/comments/deprecation

* Use world min/max heights if present in QueueCoordinator

* Address some deprecations for regions and biome setting

* Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit

* Use minGenHeight + 1 rather than build height in AugmentedUtils

* Create utility method for layer index in GenChunk

* Correct height in HybridUtils, also use minGenHeight + 1

* Don't magically split to 128 height in regeneration

* Add utility methods for world height in QueueCoordinator

* Clean up ClassicPlotManager road creation/removal

* Start generation at min gen height if bedrock is disabled

* min gen height is set in PlotArea

* Add note on schem y normalisation

* Improve plot getVolume method readability

* Don't overly extend height when regenerating road region

* y index utility method in ChunknQueueCoordinator

* Layer index utility method in LocalChunk

* Use version min/max heights if world not present in QueueCoordinator

* Fix min -> max

* Don't allow players to modify outside build height when using plot set  / schematics.
 - Also fixes schematic height issues

* Remove debug

* Address comments

* Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded)

* Fix "security" issue that was already present

* Ensure sign isn't physicsed

Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
Jordan
2022-03-05 19:03:39 +01:00
committed by GitHub
parent d698c6a1e5
commit 9f632af0ae
46 changed files with 805 additions and 472 deletions

View File

@ -74,8 +74,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
private final Consumer<Throwable> throwableConsumer;
private final boolean unloadAfter;
private final int totalSize;
private final AtomicInteger expectedSize;
private final AtomicInteger loadingChunks = new AtomicInteger();
private int batchSize;
private PlotSquaredTask task;
private boolean shouldCancel;
@ -150,6 +151,13 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
Chunk chunk = this.availableChunks.poll();
if (chunk == null) {
if (this.availableChunks.isEmpty()) {
if (this.requestedChunks.isEmpty() && loadingChunks.get() == 0) {
finish();
} else {
requestBatch();
}
}
return;
}
long[] iterationTime = new long[2];
@ -197,9 +205,11 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
BlockVector2 chunk;
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
// This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent
loadingChunks.incrementAndGet();
PaperLib
.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true)
.whenComplete((chunkObject, throwable) -> {
loadingChunks.decrementAndGet();
if (throwable != null) {
throwable.printStackTrace();
// We want one less because this couldn't be processed

View File

@ -111,8 +111,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
public boolean enqueue() {
final Clipboard regenClipboard;
if (isRegen()) {
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15);
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, getMinY(), getRegenStart()[1] << 4);
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, getMaxY(), (getRegenEnd()[1] << 4) + 15);
Region region = new CuboidRegion(start, end);
regenClipboard = new BlockArrayClipboard(region);
regenClipboard.setOrigin(start);
@ -134,7 +134,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
int sx = blockVector2.getX() << 4;
int sz = blockVector2.getZ() << 4;
if (isRegenChunk) {
for (int layer = 0; layer < 16; layer++) {
for (int layer = getMinLayer(); layer <= getMaxLayer(); layer++) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
@ -170,7 +170,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
int lx = ChunkUtil.getX(j);
int lz = ChunkUtil.getZ(j);
int x = sx + lx;
int y = ChunkUtil.getY(layer, j);
int y = ChunkUtil.getY(layer + localChunk.getMinSection(), j);
int z = sz + lz;
boolean edge = Settings.QUEUE.UPDATE_EDGES && isEdge(y >> 4, lx, y & 15, lz, blockVector2,
localChunk
@ -179,7 +179,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
}
}
}
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
for (int layer = 0; layer < localChunk.getBiomes().length; layer++) {
BiomeType[] biomesLayer = localChunk.getBiomes()[layer];
if (biomesLayer == null) {
continue;
@ -295,47 +295,48 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
}
private boolean isEdge(int layer, int x, int y, int z, BlockVector2 blockVector2, LocalChunk localChunk) {
if (layer == 0 || layer == localChunk.getBaseblocks().length - 1) {
int layerIndex = (layer - localChunk.getMinSection());
if (layer == localChunk.getMinSection() || layerIndex == localChunk.getBaseblocks().length - 1) {
return false;
}
if (x == 0) {
LocalChunk localChunkX = getBlockChunks().get(blockVector2.withX(blockVector2.getX() - 1));
if (localChunkX == null || localChunkX.getBaseblocks()[layer] == null ||
localChunkX.getBaseblocks()[layer][ChunkUtil.getJ(15, y, z)] != null) {
if (localChunkX == null || localChunkX.getBaseblocks()[layerIndex] == null ||
localChunkX.getBaseblocks()[layerIndex][ChunkUtil.getJ(15, y, z)] != null) {
return true;
}
} else if (x == 15) {
LocalChunk localChunkX = getBlockChunks().get(blockVector2.withX(blockVector2.getX() + 1));
if (localChunkX == null || localChunkX.getBaseblocks()[layer] == null ||
localChunkX.getBaseblocks()[layer][ChunkUtil.getJ(0, y, z)] != null) {
if (localChunkX == null || localChunkX.getBaseblocks()[layerIndex] == null ||
localChunkX.getBaseblocks()[layerIndex][ChunkUtil.getJ(0, y, z)] != null) {
return true;
}
}
if (z == 0) {
LocalChunk localChunkZ = getBlockChunks().get(blockVector2.withZ(blockVector2.getZ() - 1));
if (localChunkZ == null || localChunkZ.getBaseblocks()[layer] == null ||
localChunkZ.getBaseblocks()[layer][ChunkUtil.getJ(x, y, 15)] != null) {
if (localChunkZ == null || localChunkZ.getBaseblocks()[layerIndex] == null ||
localChunkZ.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, y, 15)] != null) {
return true;
}
} else if (z == 15) {
LocalChunk localChunkZ = getBlockChunks().get(blockVector2.withZ(blockVector2.getZ() + 1));
if (localChunkZ == null || localChunkZ.getBaseblocks()[layer] == null ||
localChunkZ.getBaseblocks()[layer][ChunkUtil.getJ(x, y, 0)] != null) {
if (localChunkZ == null || localChunkZ.getBaseblocks()[layerIndex] == null ||
localChunkZ.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, y, 0)] != null) {
return true;
}
}
if (y == 0) {
if (localChunk.getBaseblocks()[layer - 1] == null ||
localChunk.getBaseblocks()[layer][ChunkUtil.getJ(x, 15, z)] != null) {
if (localChunk.getBaseblocks()[layerIndex - 1] == null ||
localChunk.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, 15, z)] != null) {
return true;
}
} else if (y == 15) {
if (localChunk.getBaseblocks()[layer + 1] == null ||
localChunk.getBaseblocks()[layer][ChunkUtil.getJ(x, 0, z)] != null) {
if (localChunk.getBaseblocks()[layerIndex + 1] == null ||
localChunk.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, 0, z)] != null) {
return true;
}
}
BaseBlock[] baseBlocks = localChunk.getBaseblocks()[layer];
BaseBlock[] baseBlocks = localChunk.getBaseblocks()[layerIndex];
if (x > 0 && baseBlocks[ChunkUtil.getJ(x - 1, y, z)] == null) {
return true;
}

View File

@ -31,6 +31,7 @@ import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.AnnotationHelper;
import com.plotsquared.core.util.ChunkUtil;
import com.plotsquared.core.util.PatternUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
@ -50,6 +51,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays;
@AnnotationHelper.ApiDescription(info = "Internal use only. Subject to changes at any time.")
public class GenChunk extends ScopedQueueCoordinator {
public final Biome[] biomes;
@ -61,8 +63,14 @@ public class GenChunk extends ScopedQueueCoordinator {
public int chunkZ;
private ChunkData chunkData = null;
public GenChunk() {
super(null, Location.at("", 0, 0, 0), Location.at("", 15, 255, 15));
/**
* @param minY minimum world Y, inclusive
* @param maxY maximum world Y, inclusive
*
* @since TODO
*/
public GenChunk(int minY, int maxY) {
super(null, Location.at("", 0, minY, 0), Location.at("", 15, maxY, 15));
this.biomes = Biome.values();
}
@ -117,7 +125,7 @@ public class GenChunk extends ScopedQueueCoordinator {
return;
}
Biome biome = BukkitAdapter.adapt(biomeType);
for (int y = 0; y < 256; y++) {
for (int y = getMin().getY(); y <= getMax().getY(); y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
this.biomeGrid.setBiome(x, y, z, biome);
@ -130,7 +138,7 @@ public class GenChunk extends ScopedQueueCoordinator {
public void setCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull BlockState block) {
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
int layer = y >> 4;
int layer = getLayerIndex(y);
BlockState[] data = result[layer];
if (data == null) {
result[layer] = data = new BlockState[4096];
@ -164,7 +172,7 @@ public class GenChunk extends ScopedQueueCoordinator {
*/
public boolean setBiome(int x, int z, @NonNull Biome biome) {
if (this.biomeGrid != null) {
for (int y = 0; y < 256; y++) {
for (int y = getMin().getY(); y <= getMax().getY(); y++) {
this.setBiome(x, y, z, biome);
}
return true;
@ -197,7 +205,7 @@ public class GenChunk extends ScopedQueueCoordinator {
}
private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) {
int i = y >> 4;
int i = getLayerIndex(y);
BlockState[] v = this.result[i];
if (v == null) {
this.result[i] = v = new BlockState[4096];
@ -219,7 +227,7 @@ public class GenChunk extends ScopedQueueCoordinator {
@Override
public @Nullable BlockState getBlock(int x, int y, int z) {
int i = y >> 4;
int i = getLayerIndex(y);
if (result == null) {
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
}
@ -246,16 +254,16 @@ public class GenChunk extends ScopedQueueCoordinator {
@Override
public @NonNull Location getMax() {
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
return Location.at(getWorld().getName(), 15 + (getX() << 4), super.getMax().getY(), 15 + (getZ() << 4));
}
@Override
public @NonNull Location getMin() {
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
return Location.at(getWorld().getName(), getX() << 4, super.getMin().getY(), getZ() << 4);
}
public @NonNull GenChunk clone() {
GenChunk toReturn = new GenChunk();
GenChunk toReturn = new GenChunk(getMin().getY(), getMax().getY());
if (this.result != null) {
for (int i = 0; i < this.result.length; i++) {
BlockState[] matrix = this.result[i];
@ -269,4 +277,8 @@ public class GenChunk extends ScopedQueueCoordinator {
return toReturn;
}
private int getLayerIndex(int y) {
return (y - getMin().getY()) >> 4;
}
}