mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Clean up AugmentedUtils and make the code readable by humans
This commit is contained in:
parent
ce177c3c46
commit
e88b331155
@ -63,19 +63,27 @@ public class AugmentedUtils {
|
|||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// The coordinates of the block on the
|
||||||
|
// least positive corner of the chunk
|
||||||
final int blockX = chunkX << 4;
|
final int blockX = chunkX << 4;
|
||||||
final int blockZ = chunkZ << 4;
|
final int blockZ = chunkZ << 4;
|
||||||
|
// Create a region that contains the
|
||||||
|
// entire chunk
|
||||||
CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15);
|
CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15);
|
||||||
|
// Query for plot areas in the chunk
|
||||||
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(world, region);
|
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(world, region);
|
||||||
if (areas.isEmpty()) {
|
if (areas.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean toReturn = false;
|
boolean generationResult = false;
|
||||||
for (final PlotArea area : areas) {
|
for (final PlotArea area : areas) {
|
||||||
|
// A normal plot world may not contain any clusters
|
||||||
|
// and so there's no reason to continue searching
|
||||||
if (area.getType() == PlotAreaType.NORMAL) {
|
if (area.getType() == PlotAreaType.NORMAL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// This means that full vanilla generation is used
|
||||||
|
// so we do not interfere
|
||||||
if (area.getTerrain() == PlotAreaTerrainType.ALL) {
|
if (area.getTerrain() == PlotAreaTerrainType.ALL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -87,16 +95,17 @@ public class AugmentedUtils {
|
|||||||
}
|
}
|
||||||
LocalBlockQueue primaryMask;
|
LocalBlockQueue primaryMask;
|
||||||
// coordinates
|
// coordinates
|
||||||
int bxx;
|
int relativeBottomX;
|
||||||
int bzz;
|
int relativeBottomZ;
|
||||||
int txx;
|
int relativeTopX;
|
||||||
int tzz;
|
int relativeTopZ;
|
||||||
// gen
|
// Generation
|
||||||
if (area.getType() == PlotAreaType.PARTIAL) {
|
if (area.getType() == PlotAreaType.PARTIAL) {
|
||||||
bxx = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX);
|
relativeBottomX = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX);
|
||||||
bzz = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ);
|
relativeBottomZ = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ);
|
||||||
txx = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX);
|
relativeTopX = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX);
|
||||||
tzz = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ);
|
relativeTopZ = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ);
|
||||||
|
|
||||||
primaryMask = new DelegateLocalBlockQueue(queue) {
|
primaryMask = new DelegateLocalBlockQueue(queue) {
|
||||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||||
if (area.contains(x, z)) {
|
if (area.contains(x, z)) {
|
||||||
@ -113,24 +122,25 @@ public class AugmentedUtils {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
bxx = bzz = 0;
|
relativeBottomX = relativeBottomZ = 0;
|
||||||
txx = tzz = 15;
|
relativeTopX = relativeTopZ = 15;
|
||||||
primaryMask = queue;
|
primaryMask = queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalBlockQueue secondaryMask;
|
LocalBlockQueue secondaryMask;
|
||||||
BlockState air = BlockTypes.AIR.getDefaultState();
|
BlockState air = BlockTypes.AIR.getDefaultState();
|
||||||
if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
||||||
PlotManager manager = area.getPlotManager();
|
PlotManager manager = area.getPlotManager();
|
||||||
final boolean[][] canPlace = new boolean[16][16];
|
final boolean[][] canPlace = new boolean[16][16];
|
||||||
boolean has = false;
|
boolean has = false;
|
||||||
for (int x = bxx; x <= txx; x++) {
|
for (int x = relativeBottomX; x <= relativeTopX; x++) {
|
||||||
for (int z = bzz; z <= tzz; z++) {
|
for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
|
||||||
int rx = x + blockX;
|
int worldX = x + blockX;
|
||||||
int rz = z + blockZ;
|
int worldZ = z + blockZ;
|
||||||
boolean can = manager.getPlotId(rx, 0, rz) == null;
|
boolean can = manager.getPlotId(worldX, 0, worldZ) == null;
|
||||||
if (can) {
|
if (can) {
|
||||||
for (int y = 1; y < 128; y++) {
|
for (int y = 1; y < 128; y++) {
|
||||||
queue.setBlock(rx, y, rz, air);
|
queue.setBlock(worldX, y, worldZ, air);
|
||||||
}
|
}
|
||||||
canPlace[x][z] = true;
|
canPlace[x][z] = true;
|
||||||
has = true;
|
has = true;
|
||||||
@ -140,7 +150,7 @@ public class AugmentedUtils {
|
|||||||
if (!has) {
|
if (!has) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
toReturn = true;
|
generationResult = true;
|
||||||
secondaryMask = new DelegateLocalBlockQueue(primaryMask) {
|
secondaryMask = new DelegateLocalBlockQueue(primaryMask) {
|
||||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||||
if (canPlace[x - blockX][z - blockZ]) {
|
if (canPlace[x - blockX][z - blockZ]) {
|
||||||
@ -173,14 +183,14 @@ public class AugmentedUtils {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
secondaryMask = primaryMask;
|
secondaryMask = primaryMask;
|
||||||
for (int x = bxx; x <= txx; x++) {
|
for (int x = relativeBottomX; x <= relativeTopX; x++) {
|
||||||
for (int z = bzz; z <= tzz; z++) {
|
for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
|
||||||
for (int y = 1; y < 128; y++) {
|
for (int y = 1; y < 128; y++) {
|
||||||
queue.setBlock(blockX + x, y, blockZ + z, air);
|
queue.setBlock(blockX + x, y, blockZ + z, air);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toReturn = true;
|
generationResult = true;
|
||||||
}
|
}
|
||||||
primaryMask.setChunkObject(chunkObject);
|
primaryMask.setChunkObject(chunkObject);
|
||||||
primaryMask.setForceSync(true);
|
primaryMask.setForceSync(true);
|
||||||
@ -196,6 +206,7 @@ public class AugmentedUtils {
|
|||||||
queue.setForceSync(true);
|
queue.setForceSync(true);
|
||||||
queue.flush();
|
queue.flush();
|
||||||
}
|
}
|
||||||
return toReturn;
|
return generationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user