fix: correctly trim the max chunk section (#2753)

- fixes #2727
- fixes IntellectualSites/Plotsquared#4436
This commit is contained in:
Jordan 2024-06-05 21:23:12 +02:00 committed by GitHub
parent a7e4d19605
commit 5714a52675
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 18 deletions

View File

@ -1,6 +1,5 @@
package com.fastasyncworldedit.bukkit.regions.plotsquared;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.regions.FaweMask;
import com.fastasyncworldedit.core.regions.FaweMaskManager;
@ -174,22 +173,21 @@ public class PlotSquaredFeature extends FaweMaskManager {
return null;
}
final World world = player.getWorld();
int min = area != null ? area.getMinBuildHeight() : world.getMinY();
// PlotSquared uses exclusive max height, WorldEdit uses inclusive max height -> subtract 1
int max = area != null ? Math.min(world.getMaxY(), area.getMaxBuildHeight() - 1) : world.getMaxY();
Region maskedRegion;
if (regions.size() == 1) {
final World world = player.getWorld();
int min = area != null ? area.getMinBuildHeight() : world.getMinY();
// PlotSquared uses exclusive max height, WorldEdit uses inclusive max height -> subtract 1
int max = area != null ? Math.min(world.getMaxY(), area.getMaxBuildHeight() - 1) : world.getMaxY();
final CuboidRegion region = regions.iterator().next();
final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
maskedRegion = new CuboidRegion(pos1, pos2);
} else {
World world = FaweAPI.getWorld(area.getWorldName());
List<Region> weRegions = regions.stream().map(
r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()),
BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ())
r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), min, r.getMinimumZ()),
BlockVector3.at(r.getMaximumX(), max, r.getMaximumZ())
)).collect(Collectors.toList());
maskedRegion = new RegionIntersection(world, weRegions);
}

View File

@ -58,7 +58,7 @@ public interface IBatchProcessor {
/**
* Utility method to trim a chunk based on min and max Y (inclusive).
*
* @param keepInsideRange if all blocks inside the range (inclusive) should be kept (default)
* @param keepInsideRange if all blocks inside the range (inclusive) should be kept (default), or removed
* @return false if chunk is empty of blocks
*/
default boolean trimY(IChunkSet set, int minY, int maxY, final boolean keepInsideRange) {
@ -74,16 +74,14 @@ public interface IBatchProcessor {
for (int i = 0; i < index; i++) {
arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
}
} else {
arr = new char[4096];
set.setBlocks(layer, arr);
}
set.setBlocks(layer, arr);
} else {
set.setBlocks(layer, null);
}
}
}
for (int layer = maxLayer; layer < set.getMaxSectionPosition(); layer++) {
for (int layer = maxLayer; layer <= set.getMaxSectionPosition(); layer++) {
if (set.hasSection(layer)) {
if (layer == maxLayer) {
char[] arr = set.loadIfPresent(layer);
@ -92,10 +90,8 @@ public interface IBatchProcessor {
for (int i = index; i < arr.length; i++) {
arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
}
} else {
arr = new char[4096];
set.setBlocks(layer, arr);
}
set.setBlocks(layer, arr);
} else {
set.setBlocks(layer, null);
}

View File

@ -828,7 +828,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return set;
}
for (int layer = get.getMinSectionPosition(); layer < get.getMaxSectionPosition(); layer++) {
for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
if (!set.hasSection(layer)) {
continue;
}
@ -912,7 +912,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
boolean trimX = lowerX != 0 || upperX != 15;
boolean trimZ = lowerZ != 0 || upperZ != 15;
for (int layer = get.getMinSectionPosition(); layer < get.getMaxSectionPosition(); layer++) {
for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
if (!set.hasSection(layer)) {
continue;
}