use of com.fastasyncworldedit.core.math.LocalBlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotRestore method checkAndAddBlock.
private void checkAndAddBlock(BlockVector3 pos) {
if (editSession.getMask() != null && !editSession.getMask().test(pos)) {
return;
}
BlockVector2 chunkPos = ChunkStore.toChunk(pos);
// Unidentified chunk
if (!neededChunks.containsKey(chunkPos)) {
neededChunks.put(chunkPos, new LocalBlockVectorSet());
}
neededChunks.get(chunkPos).add(pos);
}
use of com.fastasyncworldedit.core.math.LocalBlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method getHollowed.
// FAWE end
public Set<BlockVector3> getHollowed(Set<BlockVector3> vset) {
final Set<BlockVector3> returnset = new LocalBlockVectorSet();
final LocalBlockVectorSet newset = new LocalBlockVectorSet();
newset.addAll(vset);
for (BlockVector3 v : newset) {
final int x = v.getX();
final int y = v.getY();
final int z = v.getZ();
if (!(newset.contains(x + 1, y, z) && newset.contains(x - 1, y, z) && newset.contains(x, y + 1, z) && newset.contains(x, y - 1, z) && newset.contains(x, y, z + 1) && newset.contains(x, y, z - 1))) {
returnset.add(v);
}
}
return returnset;
}
use of com.fastasyncworldedit.core.math.LocalBlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method drawSpline.
/**
* Draws a spline (out of blocks) between specified vectors.
*
* @param pattern The block pattern used to draw the spline.
* @param nodevectors The list of vectors to draw through.
* @param tension The tension of every node.
* @param bias The bias of every node.
* @param continuity The continuity of every node.
* @param quality The quality of the spline. Must be greater than 0.
* @param radius The radius (thickness) of the spline.
* @param filled If false, only a shell will be generated.
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) throws MaxChangedBlocksException {
LocalBlockVectorSet vset = new LocalBlockVectorSet();
List<Node> nodes = new ArrayList<>(nodevectors.size());
Interpolation interpol = new KochanekBartelsInterpolation();
for (BlockVector3 nodevector : nodevectors) {
Node n = new Node(nodevector.toVector3());
n.setTension(tension);
n.setBias(bias);
n.setContinuity(continuity);
nodes.add(n);
}
interpol.setNodes(nodes);
double splinelength = interpol.arcLength(0, 1);
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
BlockVector3 tipv = interpol.getPosition(loop).toBlockPoint();
if (radius == 0) {
pattern.apply(this, tipv, tipv);
changes++;
} else {
vset.add(tipv);
}
}
Set<BlockVector3> newVset;
if (radius != 0) {
newVset = getBallooned(vset, radius);
if (!filled) {
newVset = this.getHollowed(newVset);
}
return this.changes += setBlocks(newVset, pattern);
}
return changes;
}
use of com.fastasyncworldedit.core.math.LocalBlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class BlockVector3Set method getAppropriateVectorSet.
static BlockVector3Set getAppropriateVectorSet(Region region) {
BlockVector3 max = region.getMaximumPoint();
BlockVector3 min = region.getMinimumPoint();
BlockVector3 size = region.getDimensions();
if (size.getBlockX() > 2048 || size.getBlockZ() > 2048 || size.getBlockY() > 512) {
return new BlockVectorSet();
} else {
// Set default offset as many operations utilising a region are likely to start in a corner, this initialising the
// LocalBlockVectorSet poorly
// This needs to be ceiling as LocalBlockVector extends 1 block further "negative"
int offsetX = (int) Math.ceil((min.getX() + max.getX()) / 2d);
int offsetZ = (int) Math.ceil((min.getZ() + max.getZ()) / 2d);
int offsetY;
if (region.getMinimumY() < -128 || region.getMaximumY() > 320) {
offsetY = (min.getY() + max.getY()) / 2;
} else {
offsetY = 128;
}
return new LocalBlockVectorSet(offsetX, offsetY, offsetZ);
}
}
use of com.fastasyncworldedit.core.math.LocalBlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.
the class ShatterBrush method finish.
@Override
public void finish(EditSession editSession, LocalBlockVectorSet placed, final BlockVector3 position, Pattern pattern, double size) {
int radius2 = (int) (size * size);
// Individual frontier for each point
LocalBlockVectorSet[] frontiers = new LocalBlockVectorSet[placed.size()];
// Keep track of where each frontier has visited
LocalBlockVectorSet[] frontiersVisited = new LocalBlockVectorSet[placed.size()];
// Initiate the frontier with the starting points
int i = 0;
for (BlockVector3 pos : placed) {
LocalBlockVectorSet set = new LocalBlockVectorSet();
set.add(pos);
frontiers[i] = set;
frontiersVisited[i] = set.clone();
i++;
}
// Mask
Mask mask = editSession.getMask();
if (mask == null) {
mask = Masks.alwaysTrue();
}
final Mask finalMask = mask;
final SurfaceMask surfaceTest = new SurfaceMask(editSession);
// Expand
boolean notEmpty = true;
// Keep track of where we've visited
LocalBlockVectorSet tmp = new LocalBlockVectorSet();
while (notEmpty) {
notEmpty = false;
for (i = 0; i < frontiers.length; i++) {
LocalBlockVectorSet frontier = frontiers[i];
notEmpty |= !frontier.isEmpty();
final LocalBlockVectorSet frontierVisited = frontiersVisited[i];
// This is a temporary set with the next blocks the frontier will visit
final LocalBlockVectorSet finalTmp = tmp;
frontier.forEach((x, y, z, index) -> {
if (ThreadLocalRandom.current().nextInt(2) == 0) {
finalTmp.add(x, y, z);
return;
}
for (int i1 = 0; i1 < BreadthFirstSearch.DIAGONAL_DIRECTIONS.length; i1++) {
BlockVector3 direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i1];
int x2 = x + direction.getBlockX();
int y2 = y + direction.getBlockY();
int z2 = z + direction.getBlockZ();
// Check boundary
int dx = position.getBlockX() - x2;
int dy = position.getBlockY() - y2;
int dz = position.getBlockZ() - z2;
int dSqr = (dx * dx) + (dy * dy) + (dz * dz);
if (dSqr <= radius2) {
BlockVector3 bv = mutable.setComponents(x2, y2, z2);
if (surfaceTest.test(bv) && finalMask.test(bv)) {
// (collision) If it's visited and part of another frontier, set the block
if (!placed.add(x2, y2, z2)) {
if (!frontierVisited.contains(x2, y2, z2)) {
editSession.setBlock(x2, y2, z2, pattern);
}
} else {
// Hasn't visited and not a collision = add it
finalTmp.add(x2, y2, z2);
frontierVisited.add(x2, y2, z2);
}
}
}
}
});
// Swap the frontier with the temporary set
frontiers[i] = tmp;
tmp = frontier;
tmp.clear();
}
}
}
Aggregations