use of com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator in project PlotSquared by IntellectualSites.
the class AugmentedUtils method generate.
public static boolean generate(@Nullable Object chunkObject, @NonNull final String world, final int chunkX, final int chunkZ, QueueCoordinator queue) {
if (!enabled) {
return false;
}
// The coordinates of the block on the
// least positive corner of the chunk
final int blockX = chunkX << 4;
final int blockZ = chunkZ << 4;
// Create a region that contains the
// entire chunk
CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, 0, 0, blockZ, blockZ + 15);
// Query for plot areas in the chunk
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
if (areas.isEmpty()) {
return false;
}
boolean enqueue = false;
boolean generationResult = false;
for (final PlotArea area : areas) {
// and so there's no reason to continue searching
if (area.getType() == PlotAreaType.NORMAL) {
return false;
}
// so we do not interfere
if (area.getTerrain() == PlotAreaTerrainType.ALL || !area.contains(blockX, blockZ)) {
continue;
}
IndependentPlotGenerator generator = area.getGenerator();
// Mask
if (queue == null) {
enqueue = true;
queue = PlotSquared.platform().globalBlockQueue().getNewQueue(PlotSquared.platform().worldUtil().getWeWorld(world));
if (chunkObject != null) {
queue.setChunkObject(chunkObject);
}
}
QueueCoordinator primaryMask;
// coordinates
int relativeBottomX;
int relativeBottomZ;
int relativeTopX;
int relativeTopZ;
// Generation
if (area.getType() == PlotAreaType.PARTIAL) {
relativeBottomX = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX);
relativeBottomZ = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ);
relativeTopX = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX);
relativeTopZ = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ);
primaryMask = new AreaBoundDelegateQueueCoordinator(area, queue);
} else {
relativeBottomX = relativeBottomZ = 0;
relativeTopX = relativeTopZ = 15;
primaryMask = queue;
}
QueueCoordinator secondaryMask;
BlockState air = BlockTypes.AIR.getDefaultState();
int startYOffset = !(area instanceof ClassicPlotWorld) || ((ClassicPlotWorld) area).PLOT_BEDROCK ? 1 : 0;
if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
PlotManager manager = area.getPlotManager();
final boolean[][] canPlace = new boolean[16][16];
boolean has = false;
for (int x = relativeBottomX; x <= relativeTopX; x++) {
for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
int worldX = x + blockX;
int worldZ = z + blockZ;
boolean can = manager.getPlotId(worldX, 0, worldZ) == null;
if (can) {
for (int y = area.getMinGenHeight() + startYOffset; y <= area.getMaxGenHeight(); y++) {
queue.setBlock(worldX, y, worldZ, air);
}
canPlace[x][z] = true;
has = true;
}
}
}
if (!has) {
continue;
}
generationResult = true;
secondaryMask = new LocationOffsetDelegateQueueCoordinator(canPlace, blockX, blockZ, primaryMask);
} else {
secondaryMask = primaryMask;
for (int x = relativeBottomX; x <= relativeTopX; x++) {
for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
for (int y = area.getMinGenHeight() + startYOffset; y <= area.getMaxGenHeight(); y++) {
queue.setBlock(blockX + x, y, blockZ + z, air);
}
}
}
generationResult = true;
}
if (chunkObject != null) {
primaryMask.setChunkObject(chunkObject);
}
if (chunkObject != null) {
secondaryMask.setChunkObject(chunkObject);
}
ScopedQueueCoordinator scoped = new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, area.getMinGenHeight(), blockZ), Location.at(world, blockX + 15, area.getMaxGenHeight(), blockZ + 15));
generator.generateChunk(scoped, area);
generator.populateChunk(scoped, area);
scoped.setForceSync(true);
scoped.enqueue();
}
if (enqueue) {
queue.enqueue();
}
return generationResult;
}
Aggregations