From 6cbd9631a01086db4fe70d7fc0cf992b8e580f26 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 11 Sep 2021 12:40:39 +0100 Subject: [PATCH] Improve notes on getting the stored section range/refactor method name --- .../extent/filter/block/ChunkFilterBlock.java | 4 +- .../extent/processor/HeightmapProcessor.java | 4 +- .../processor/lighting/RelightProcessor.java | 4 +- .../history/changeset/AbstractChangeSet.java | 4 +- .../core/queue/IBatchProcessor.java | 4 +- .../core/queue/IBlocks.java | 16 ++++--- .../implementation/blocks/BitSetBlocks.java | 4 +- .../implementation/blocks/CharSetBlocks.java | 4 +- .../implementation/blocks/NullChunkGet.java | 4 +- .../implementation/chunk/ChunkHolder.java | 48 +++++++++---------- .../queue/implementation/chunk/NullChunk.java | 4 +- .../sk89q/worldedit/regions/CuboidRegion.java | 6 +-- .../com/sk89q/worldedit/regions/Region.java | 4 +- 13 files changed, 57 insertions(+), 53 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ChunkFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ChunkFilterBlock.java index 2cd997fc5..bc079814e 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ChunkFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ChunkFilterBlock.java @@ -71,7 +71,7 @@ public abstract class ChunkFilterBlock extends AbstractExtentFilterBlock { */ public final IChunkSet filter(IChunk chunk, IChunkGet get, IChunkSet set, Filter filter) { initChunk(chunk.getX(), chunk.getZ()); - for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) { + for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) { if (set.hasSection(layer)) { initLayer(get, set, layer); filter(filter); @@ -87,7 +87,7 @@ public abstract class ChunkFilterBlock extends AbstractExtentFilterBlock { if (region != null) { region.filter(chunk, filter, this, get, set, full); } else { - for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) { + for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) { if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) { continue; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/HeightmapProcessor.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/HeightmapProcessor.java index 1b33fb2bc..95fecf4ca 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/HeightmapProcessor.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/HeightmapProcessor.java @@ -37,7 +37,7 @@ public class HeightmapProcessor implements IBatchProcessor { int skip = 0; int allSkipped = (1 << TYPES.length) - 1; // lowest types.length bits are set layer: - for (int layer = set.getMaxSectionIndex(); layer >= set.getMinSectionIndex(); layer--) { + for (int layer = set.getMaxSectionPosition(); layer >= set.getMinSectionPosition() >> 4; layer--) { boolean hasSectionSet = set.hasSection(layer); boolean hasSectionGet = get.hasSection(layer); if (!(hasSectionSet || hasSectionGet)) { @@ -94,7 +94,7 @@ public class HeightmapProcessor implements IBatchProcessor { // ignore if that position was already set if (!updated[i][j] && type.includes(block)) { // mc requires + 1, heightmaps are normalized internally - heightmaps[i][j] = ((layer - set.getMinSectionIndex()) << 4) + y + 1; + heightmaps[i][j] = ((layer - get.getMinSectionPosition()) << 4) + y + 1; updated[i][j] = true; // mark as updated } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/RelightProcessor.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/RelightProcessor.java index 2f46d1c90..c9b71beb1 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/RelightProcessor.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/lighting/RelightProcessor.java @@ -30,10 +30,10 @@ public class RelightProcessor implements IBatchProcessor { } else if (Settings.IMP.LIGHTING.MODE == 1) { byte[] fix = new byte[get.getSectionCount()]; boolean relight = false; - for (int i = get.getMaxSectionIndex(); i >= get.getMinSectionIndex(); i--) { + for (int i = get.getMaxSectionPosition(); i >= get.getMinSectionPosition(); i--) { if (!set.hasSection(i)) { // Array index cannot be < 0 so "add" the min - fix[i - get.getMinSectionIndex()] = Relighter.SkipReason.AIR; + fix[i - get.getMinSectionPosition()] = Relighter.SkipReason.AIR; continue; } relight = true; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java index 221001daf..76a9052bc 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java @@ -157,7 +157,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { addEntityCreate(tag); } } - for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) { + for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) { if (!set.hasSection(layer)) { continue; } @@ -197,7 +197,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { BiomeType[] biomes = set.getBiomes(); if (biomes != null) { int index = 0; - for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) { + for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) { if (!set.hasBiomes(layer)) { continue; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBatchProcessor.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBatchProcessor.java index 8345d3bde..218ecc203 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBatchProcessor.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBatchProcessor.java @@ -41,7 +41,7 @@ public interface IBatchProcessor { */ default boolean trimY(IChunkSet set, int minY, int maxY) { int minLayer = (minY - 1) >> 4; - for (int layer = set.getMinSectionIndex(); layer <= minLayer; layer++) { + for (int layer = set.getMinSectionPosition(); layer <= minLayer; layer++) { if (set.hasSection(layer)) { if (layer == minLayer) { char[] arr = set.load(layer); @@ -56,7 +56,7 @@ public interface IBatchProcessor { } } int maxLayer = (maxY + 1) >> 4; - for (int layer = maxLayer; layer < set.getMaxSectionIndex(); layer++) { + for (int layer = maxLayer; layer < set.getMaxSectionPosition(); layer++) { if (set.hasSection(layer)) { if (layer == minLayer) { char[] arr = set.load(layer); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBlocks.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBlocks.java index 437370e71..a482af14f 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBlocks.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IBlocks.java @@ -44,7 +44,7 @@ public interface IBlocks extends Trimable { BiomeType getBiomeType(int x, int y, int z); default int getBitMask() { - return IntStream.range(getMinSectionIndex(), getMaxSectionIndex() + 1).filter(this::hasSection) + return IntStream.range(getMinSectionPosition(), getMaxSectionPosition() + 1).filter(this::hasSection) .map(layer -> (1 << layer)).sum(); } @@ -55,19 +55,23 @@ public interface IBlocks extends Trimable { IBlocks reset(); /** - * Get the number of stores sections + * Get the number of stored sections */ int getSectionCount(); /** - * Max ChunkSection array index + * Get the highest layer position stored in the internal chunk. For 1.16 and below, always returns 15. For 1.17 and above, may + * not return a value correct to the world if this is a {@link IChunkSet} instance, which defaults to 15. For extended + * height worlds, this will only return over 15 if blocks are stored outside the default range. */ - int getMaxSectionIndex(); + int getMaxSectionPosition(); /** - * Min ChunkSection array index + * Get the lowest layer position stored in the internal chunk. For 1.16 and below, always returns 0. For 1.17 and above, may + * not return a value correct to the world if this is a {@link IChunkSet} instance, which defaults to 0. For extended + * height worlds, this will only return under 0 if blocks are stored outside the default range. */ - int getMinSectionIndex(); + int getMinSectionPosition(); default byte[] toByteArray(boolean full, boolean stretched) { return toByteArray(null, getBitMask(), full, stretched); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/BitSetBlocks.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/BitSetBlocks.java index ba3ecbf15..792fc669c 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/BitSetBlocks.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/BitSetBlocks.java @@ -210,12 +210,12 @@ public class BitSetBlocks implements IChunkSet { } @Override - public int getMaxSectionIndex() { + public int getMaxSectionPosition() { return minSectionIndex; } @Override - public int getMinSectionIndex() { + public int getMinSectionPosition() { return maxSectionIndex; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharSetBlocks.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharSetBlocks.java index 2af218488..48e551b20 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharSetBlocks.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharSetBlocks.java @@ -327,12 +327,12 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet { } @Override - public int getMaxSectionIndex() { + public int getMaxSectionPosition() { return maxSectionIndex; } @Override - public int getMinSectionIndex() { + public int getMinSectionPosition() { return minSectionIndex; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/NullChunkGet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/NullChunkGet.java index a0c01384e..00b5dacbc 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/NullChunkGet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/NullChunkGet.java @@ -100,12 +100,12 @@ public final class NullChunkGet implements IChunkGet { } @Override - public int getMaxSectionIndex() { + public int getMaxSectionPosition() { return 0; } @Override - public int getMinSectionIndex() { + public int getMinSectionPosition() { return 0; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java index 7880bfd87..69df41c04 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java @@ -190,13 +190,13 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public int getMaxSectionIndex() { - return getOrCreateGet().getMaxSectionIndex(); + public int getMaxSectionPosition() { + return getOrCreateGet().getMaxSectionPosition(); } @Override - public int getMinSectionIndex() { - return getOrCreateGet().getMinSectionIndex(); + public int getMinSectionPosition() { + return getOrCreateGet().getMinSectionPosition(); } public void flushLightToGet() { @@ -285,7 +285,7 @@ public class ChunkHolder> implements IQueueChunk { public int getSkyLight(ChunkHolder chunk, int x, int y, int z) { if (chunk.chunkSet.getSkyLight() != null) { int layer = y >> 4; - layer -= chunk.chunkSet.getMinSectionIndex(); + layer -= chunk.chunkSet.getMinSectionPosition(); if (layer >= 0 && layer < chunk.chunkSet.getSectionCount()) { if (chunk.chunkSet.getSkyLight()[layer] != null) { int setLightValue = chunk.chunkSet.getSkyLight()[layer][(y & 15) << 8 | (z & 15) << 4 | (x & 15)]; @@ -302,7 +302,7 @@ public class ChunkHolder> implements IQueueChunk { public int getEmittedLight(ChunkHolder chunk, int x, int y, int z) { if (chunk.chunkSet.getLight() != null) { int layer = y >> 4; - layer -= chunk.chunkSet.getMinSectionIndex(); + layer -= chunk.chunkSet.getMinSectionPosition(); if (layer >= 0 && layer < chunk.chunkSet.getSectionCount()) { if (chunk.chunkSet.getLight()[layer] != null) { int setLightValue = chunk.chunkSet.getLight()[layer][(y & 15) << 8 | (z & 15) << 4 | (x & 15)]; @@ -332,11 +332,11 @@ public class ChunkHolder> implements IQueueChunk { @Override public void flushLightToGet(ChunkHolder chunk) { - chunk.chunkExisting.setLightingToGet(chunk.chunkSet.getLight(), chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkExisting.setLightingToGet(chunk.chunkSet.getLight(), chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); - chunk.chunkExisting.setSkyLightingToGet(chunk.chunkSet.getSkyLight(), chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkExisting.setSkyLightingToGet(chunk.chunkSet.getSkyLight(), chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); } @@ -344,8 +344,8 @@ public class ChunkHolder> implements IQueueChunk { public void setLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.chunkExisting.setLightingToGet( lighting, - chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); } @@ -353,8 +353,8 @@ public class ChunkHolder> implements IQueueChunk { public void setSkyLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.chunkExisting.setSkyLightingToGet( lighting, - chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); } @@ -498,8 +498,8 @@ public class ChunkHolder> implements IQueueChunk { public void setLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.chunkExisting.setLightingToGet( lighting, - chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); } @@ -507,8 +507,8 @@ public class ChunkHolder> implements IQueueChunk { public void setSkyLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.chunkExisting.setSkyLightingToGet( lighting, - chunk.chunkSet.getMinSectionIndex(), - chunk.chunkSet.getMaxSectionIndex() + chunk.chunkSet.getMinSectionPosition(), + chunk.chunkSet.getMaxSectionPosition() ); } @@ -615,7 +615,7 @@ public class ChunkHolder> implements IQueueChunk { public int getSkyLight(ChunkHolder chunk, int x, int y, int z) { if (chunk.chunkSet.getSkyLight() != null) { int layer = y >> 4; - layer -= chunk.chunkSet.getMinSectionIndex(); + layer -= chunk.chunkSet.getMinSectionPosition(); if (layer >= 0 && layer < chunk.chunkSet.getSectionCount()) { if (chunk.chunkSet.getSkyLight()[layer] != null) { int setLightValue = chunk.chunkSet.getSkyLight()[layer][(y & 15) << 8 | (z & 15) << 4 | (x & 15)]; @@ -634,7 +634,7 @@ public class ChunkHolder> implements IQueueChunk { public int getEmittedLight(ChunkHolder chunk, int x, int y, int z) { if (chunk.chunkSet.getLight() != null) { int layer = y >> 4; - layer -= chunk.chunkSet.getMinSectionIndex(); + layer -= chunk.chunkSet.getMinSectionPosition(); if (layer >= 0 && layer < chunk.chunkSet.getSectionCount()) { if (chunk.chunkSet.getLight()[layer] != null) { int setLightValue = chunk.chunkSet.getLight()[layer][(y & 15) << 8 | (z & 15) << 4 | (x & 15)]; @@ -681,14 +681,14 @@ public class ChunkHolder> implements IQueueChunk { public void setLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.getOrCreateGet(); chunk.delegate = BOTH; - chunk.setLightingToGet(lighting, chunk.chunkSet.getMinSectionIndex(), chunk.chunkSet.getMaxSectionIndex()); + chunk.setLightingToGet(lighting, chunk.chunkSet.getMinSectionPosition(), chunk.chunkSet.getMaxSectionPosition()); } @Override public void setSkyLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.getOrCreateGet(); chunk.delegate = BOTH; - chunk.setSkyLightingToGet(lighting, chunk.chunkSet.getMinSectionIndex(), chunk.chunkSet.getMaxSectionIndex()); + chunk.setSkyLightingToGet(lighting, chunk.chunkSet.getMinSectionPosition(), chunk.chunkSet.getMaxSectionPosition()); } @Override @@ -846,14 +846,14 @@ public class ChunkHolder> implements IQueueChunk { public void setLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.getOrCreateGet(); chunk.delegate = GET; - chunk.setLightingToGet(lighting, chunk.chunkSet.getMinSectionIndex(), chunk.chunkSet.getMaxSectionIndex()); + chunk.setLightingToGet(lighting, chunk.chunkSet.getMinSectionPosition(), chunk.chunkSet.getMaxSectionPosition()); } @Override public void setSkyLightingToGet(ChunkHolder chunk, char[][] lighting) { chunk.getOrCreateGet(); chunk.delegate = GET; - chunk.setSkyLightingToGet(lighting, chunk.chunkSet.getMinSectionIndex(), chunk.chunkSet.getMaxSectionIndex()); + chunk.setSkyLightingToGet(lighting, chunk.chunkSet.getMinSectionPosition(), chunk.chunkSet.getMaxSectionPosition()); } @Override diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/NullChunk.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/NullChunk.java index 6cfc65fe4..5e976bb1d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/NullChunk.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/NullChunk.java @@ -209,12 +209,12 @@ public final class NullChunk implements IQueueChunk { } @Override - public int getMaxSectionIndex() { + public int getMaxSectionPosition() { return 0; } @Override - public int getMinSectionIndex() { + public int getMinSectionPosition() { return 0; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 801be09dd..28228589f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -744,7 +744,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { if (bx >= minX && tx <= maxX && bz >= minZ && tz <= maxZ) { // contains all X/Z - if (minY <= set.getMinSectionIndex() << 4 && maxY >= (set.getMaxSectionIndex() << 4) + 15) { + if (minY <= set.getMinSectionPosition() << 4 && maxY >= (set.getMaxSectionPosition() << 4) + 15) { return set; } trimY(set, minY, maxY); @@ -752,7 +752,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return set; } if (tx >= minX && bx <= maxX && tz >= minZ && bz <= maxZ) { - if (minY > set.getMinSectionIndex() << 4 || maxY < (set.getMaxSectionIndex() << 4) + 15) { + if (minY > set.getMinSectionPosition() << 4 || maxY < (set.getMaxSectionPosition() << 4) + 15) { trimY(set, minY, maxY); } final int lowerX = Math.max(0, minX - bx); @@ -767,7 +767,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { boolean trimX = lowerX != 0 || upperX != 15; boolean trimZ = lowerZ != 0 || upperZ != 15; - for (int layer = get.getMinSectionIndex(); layer < get.getMaxSectionIndex(); layer++) { + for (int layer = get.getMinSectionPosition(); layer < get.getMaxSectionPosition(); layer++) { if (set.hasSection(layer)) { char[] arr = set.load(layer); if (trimX || trimZ) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index b9d080749..f14b820c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -244,8 +244,8 @@ public interface Region extends Iterable, Cloneable, IBatchProcess final IChunkSet set, boolean full ) { - int minSection = Math.max(get.getMinSectionIndex(), getMinimumY() >> 4); - int maxSection = Math.min(get.getMaxSectionIndex(), getMaximumY() >> 4); + int minSection = Math.max(get.getMinSectionPosition(), getMinimumY() >> 4); + int maxSection = Math.min(get.getMaxSectionPosition(), getMaximumY() >> 4); block = block.initChunk(chunk.getX(), chunk.getZ()); for (int layer = minSection; layer <= maxSection; layer++) { if ((!full && !set.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {