Don't do the unbelievable bad use of a MutableBlockVector2 in the creation of a set (#1825)

* Don't do the unbelievable bad use of a MutableBlockVector2 in the creation of a set
 - Fixes IntellectualSites/PlotSquared#3683

* Clean up remnants of the use of MutableBlockVector2
This commit is contained in:
Jordan 2022-06-17 22:41:25 +01:00 committed by GitHub
parent d2b4154cc0
commit 907ad8528e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View File

@ -440,7 +440,6 @@ public abstract class Regenerator<IChunkAccess, ProtoChunk extends IChunkAccess,
);
Region adjustedRegion = new CuboidRegion(newMin, newMax);
return adjustedRegion.getChunks().stream()
.map(c -> BlockVector2.at(c.getX(), c.getZ()))
.sorted(Comparator
.comparingInt(BlockVector2::getZ)
.thenComparingInt(BlockVector2::getX)) //needed for RegionLimitedWorldAccess

View File

@ -93,7 +93,6 @@ public final class MemBlockSet extends BlockSet {
@Override
public Iterator<BlockVector2> iterator() {
return new Iterator<>() {
private final MutableBlockVector2 mutable = new MutableBlockVector2();
private boolean hasNext;
private int X;
private int Z;
@ -131,9 +130,10 @@ public final class MemBlockSet extends BlockSet {
@Override
public BlockVector2 next() {
mutable.setComponents(setX + getBlockOffsetX(), setZ + getBlockOffsetZ());
// Maintain correct order of method call/variable use
BlockVector2 result = BlockVector2.at(setX + getBlockOffsetX(), setZ + getBlockOffsetZ());
init();
return mutable;
return result;
}
@Override

View File

@ -377,12 +377,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
final int size = (maxX - minX + 1) * (maxZ - minZ + 1);
//FAWE start
return new AbstractSet<BlockVector2>() {
return new AbstractSet<>() {
@Nonnull
@Override
public Iterator<BlockVector2> iterator() {
return new Iterator<BlockVector2>() {
final MutableBlockVector2 mutable = new MutableBlockVector2(0, 0);
return new Iterator<>() {
final int bx = minX;
final int bz = minZ;
@ -410,8 +409,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector2 next() {
mutable.mutX(x);
mutable.mutZ(z);
int curX = x;
int curZ = z;
if (++x > rtx) {
if (++z > rtz) {
if (x > tx) {
@ -427,7 +426,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
x = tx;
hasNext = false;
return mutable;
return BlockVector2.at(curX, curZ);
}
} else {
z = rbz;
@ -442,7 +441,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
x = rbx;
}
}
return mutable;
return BlockVector2.at(curX, curZ);
}
};
}