use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class AbstractRegion method getChunkCubes.
@Override
public Set<BlockVector3> getChunkCubes() {
final Set<BlockVector3> chunks = new BlockVectorSet();
final BlockVector3 min = getMinimumPoint();
final BlockVector3 max = getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
if (!contains(BlockVector3.at(x, y, z))) {
continue;
}
chunks.add(BlockVector3.at(x >> ChunkStore.CHUNK_SHIFTS, y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
}
}
}
return chunks;
}
use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class CuboidRegion method getChunkCubes.
// FAWE end
@Override
public Set<BlockVector3> getChunkCubes() {
// FAWE start - BlockVectorSet instead of HashMap
Set<BlockVector3> chunks = new BlockVectorSet();
// FAWE end
BlockVector3 min = getMinimumPoint();
BlockVector3 max = getMaximumPoint();
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) {
chunks.add(BlockVector3.at(x, y, z));
}
}
}
return chunks;
}
use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class LayerBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException {
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR), editSession.getMinY(), editSession.getMaxY());
final SolidBlockMask solid = new SolidBlockMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
visitor = new RecursiveVisitor(new MaskIntersection(adjacent, solid, radius), funcion -> true, Integer.MAX_VALUE, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited();
visitor = new RecursiveVisitor(new LayerBrushMask(editSession, visitor, layers, adjacent), pos -> {
int depth = visitor.getDepth();
Pattern currentPattern = layers[depth];
return currentPattern.apply(editSession, pos, pos);
}, layers.length - 1, editSession.getMinY(), editSession.getMaxY());
for (BlockVector3 pos : visited) {
visitor.visit(pos);
}
Operations.completeBlindly(visitor);
visitor = null;
}
use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class ScatterBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
this.mask = editSession.getMask();
if (this.mask == null) {
this.mask = Masks.alwaysTrue();
}
surface = new SurfaceMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
final int distance = Math.min((int) size, this.distance);
RecursiveVisitor visitor = new RecursiveVisitor(new MaskIntersection(radius, surface), function -> true, Integer.MAX_VALUE, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited();
int length = visited.size();
if (size == 0) {
length = 1;
visited.add(position);
}
LocalBlockVectorSet placed = new LocalBlockVectorSet();
placed.setOffset(position.getX(), position.getZ());
int maxFails = 1000;
for (int i = 0; i < count; i++) {
int index = ThreadLocalRandom.current().nextInt(length);
BlockVector3 pos = visited.get(index);
if (pos != null && canApply(pos)) {
int x = pos.getBlockX();
int y = pos.getBlockY();
int z = pos.getBlockZ();
if (placed.containsRadius(x, y, z, distance)) {
if (maxFails-- <= 0) {
break;
}
i--;
continue;
}
placed.add(x, y, z);
apply(editSession, placed, pos, pattern, size);
}
}
finish(editSession, placed, position, pattern, size);
}
use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class BreadthFirstSearch method resume.
@Override
public Operation resume(RunContext run) throws WorldEditException {
// FAWE start - directions, visited and preloading
MutableBlockVector3 mutable = new MutableBlockVector3();
BlockVector3[] dirs = directions;
BlockVectorSet tempQueue = new BlockVectorSet();
BlockVectorSet chunkLoadSet = new BlockVectorSet();
for (currentDepth = 0; !queue.isEmpty() && currentDepth <= maxDepth; currentDepth++) {
int loadCount = 0;
if (singleQueue != null && Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT > 1) {
int cx = Integer.MIN_VALUE;
int cz = Integer.MIN_VALUE;
outer: for (BlockVector3 from : queue) {
for (BlockVector3 direction : dirs) {
if (loadCount > Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT) {
break outer;
}
int x = from.getBlockX() + direction.getBlockX();
int z = from.getBlockZ() + direction.getBlockX();
if (cx != (cx = x >> 4) || cz != (cz = z >> 4)) {
int y = from.getBlockY() + direction.getBlockY();
if (y < singleQueue.getMinY() || y > singleQueue.getMaxY()) {
continue;
}
if (!visited.contains(x, y, z)) {
loadCount++;
chunkLoadSet.add(cx, 0, cz);
}
}
}
}
for (BlockVector3 chunk : chunkLoadSet) {
singleQueue.addChunkLoad(chunk.getBlockX(), chunk.getBlockZ());
}
}
for (BlockVector3 from : queue) {
if (function.apply(from)) {
affected++;
}
for (int i = 0, j = 0; i < dirs.length && j < maxBranch; i++) {
BlockVector3 direction = dirs[i];
int y = from.getBlockY() + direction.getY();
if (y < minY || y > maxY) {
continue;
}
int x = from.getBlockX() + direction.getX();
int z = from.getBlockZ() + direction.getZ();
if (!visited.contains(x, y, z)) {
if (isVisitable(from, mutable.setComponents(x, y, z))) {
j++;
visited.add(x, y, z);
tempQueue.add(x, y, z);
}
}
}
}
if (currentDepth == maxDepth) {
break;
}
BlockVectorSet tmp = queue;
queue = tempQueue;
tmp.clear();
tempQueue = tmp;
}
return null;
}
Aggregations