Java Code Examples for com.sk89q.worldedit.Vector#mutZ()

The following examples show how to use com.sk89q.worldedit.Vector#mutZ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScaleTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
    boolean result = false;
    Vector pos = getPos(location);
    double sx = pos.getX();
    double sy = pos.getY();
    double sz = pos.getZ();
    double ex = sx + dx;
    double ey = Math.min(maxy, sy + dy);
    double ez = sz + dz;
    for (pos.mutY(sy); pos.getY() < ey; pos.mutY(pos.getY() + 1)) {
        for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) {
            for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) {
                result |= super.setBlock(pos, block);
            }
        }
    }
    return result;
}
 
Example 2
Source File: ScaleTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean setBlock(int x1, int y1, int z1, BaseBlock block) throws WorldEditException {
    boolean result = false;
    Vector pos = getPos(x1, y1, z1);
    double sx = pos.getX();
    double sy = pos.getY();
    double sz = pos.getZ();
    double ex = pos.getX() + dx;
    double ey = Math.min(maxy, sy + dy);
    double ez = pos.getZ() + dz;
    for (pos.mutY(sy); pos.getY() < ey; pos.mutY(pos.getY() + 1)) {
        for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) {
            for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) {
                result |= super.setBlock(pos, block);
            }
        }
    }
    return result;
}
 
Example 3
Source File: LocalBlockVectorSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean retainAll(Collection<?> c) {
    boolean result = false;
    int size = size();
    int index = -1;
    Vector mVec = MutableBlockVector.get(0, 0, 0);
    for (int i = 0; i < size; i++) {
        index = set.nextSetBit(index + 1);
        int b1 = (index & 0xFF);
        int b2 = ((byte) (index >> 8)) & 0x7F;
        int b3 = ((byte) (index >> 15)) & 0xFF;
        int b4 = ((byte) (index >> 23)) & 0xFF;
        mVec.mutX(offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21));
        mVec.mutY(b1);
        mVec.mutZ(offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21));
        if (!c.contains(mVec)) {
            result = true;
            set.clear(index);
        }
    }
    return result;
}
 
Example 4
Source File: BlockVectorSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public Vector get(int index) {
    int count = 0;
    ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> iter = localSets.int2ObjectEntrySet().iterator();
    while (iter.hasNext()) {
        Int2ObjectMap.Entry<LocalBlockVectorSet> entry = iter.next();
        LocalBlockVectorSet set = entry.getValue();
        int size = set.size();
        int newSize = count + size;
        if (newSize > index) {
            int localIndex = index - count;
            Vector pos = set.getIndex(localIndex);
            if (pos != null) {
                int pair = entry.getIntKey();
                int cx = MathMan.unpairX(pair);
                int cz = MathMan.unpairY(pair);
                pos.mutX((cx << 11) + pos.getBlockX());
                pos.mutZ((cz << 11) + pos.getBlockZ());
                return pos;
            }
        }
        count += newSize;
    }
    return null;
}
 
Example 5
Source File: ScaleTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    boolean result = false;
    Vector pos = getPos(position.getBlockX(), 0, position.getBlockZ());
    double sx = pos.getX();
    double sz = pos.getZ();
    double ex = pos.getX() + dx;
    double ez = pos.getZ() + dz;
    for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) {
        for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) {
            result |= super.setBiome(pos.toVector2D(), biome);
        }
    }
    return result;
}
 
Example 6
Source File: WallMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean test(Vector v) {
    int count = 0;
    double x = v.getX();
    double y = v.getY();
    double z = v.getZ();
    v.mutX(x + 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutX(x);
        return true;
    }
    v.mutX(x - 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutX(x);
        return true;
    }
    v.mutX(x);
    v.mutZ(z + 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z - 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z);
    return count >= min && count <= max;
}
 
Example 7
Source File: SplineBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector getCentroid(Collection<Vector> points) {
    Vector sum = new Vector();
    for (Vector p : points) {
        sum.mutX(sum.getX() + p.getX());
        sum.mutY(sum.getY() + p.getY());
        sum.mutZ(sum.getZ() + p.getZ());
    }
    return sum.multiply(1.0 / points.size());
}
 
Example 8
Source File: ExtentBlockCopy.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Transform NBT data in the given block state and return a new instance
 * if the NBT data needs to be transformed.
 *
 * @param state the existing state
 * @return a new state or the existing one
 */
private BaseBlock transformNbtData(BaseBlock state) {
    CompoundTag tag = state.getNbtData();
    if (tag != null) {
        // Handle blocks which store their rotation in NBT
        if (tag.containsKey("Rot")) {
            int rot = tag.asInt("Rot");

            Direction direction = MCDirections.fromRotation(rot);

            if (direction != null) {
                Vector applyAbsolute = transform.apply(direction.toVector());
                Vector applyOrigin = transform.apply(Vector.ZERO);
                applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
                applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
                applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());

                Direction newDirection = Direction.findClosest(applyAbsolute, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);

                if (newDirection != null) {
                    Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
                    values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
                }
            }
        }
    }
    return state;
}
 
Example 9
Source File: SurfaceRandomOffsetPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
private boolean allowed(Vector v) {
    BaseBlock block = pattern.apply(v);
    if (FaweCache.canPassThrough(block.getId(), block.getData())) {
        return false;
    }
    int x = v.getBlockX();
    int y = v.getBlockY();
    int z = v.getBlockZ();
    v.mutY(y + 1);
    if (canPassthrough(v)) {
        v.mutY(y);
        return true;
    }
    v.mutY(y - 1);
    if (canPassthrough(v)) {
        v.mutY(y);
        return true;
    }
    v.mutY(y);
    v.mutX(x + 1);
    if (canPassthrough(v)) {
        v.mutX(x);
        return true;
    }
    v.mutX(x - 1);
    if (canPassthrough(v)) {
        v.mutX(x);
        return true;
    }
    v.mutX(x);
    v.mutZ(z + 1);
    if (canPassthrough(v)) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z - 1);
    if (canPassthrough(v)) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z);
    return false;
}
 
Example 10
Source File: AdjacentMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean test(Vector v) {
    int count = 0;
    double x = v.getX();
    double y = v.getY();
    double z = v.getZ();
    v.mutX(x + 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutX(x);
        return true;
    }
    v.mutX(x - 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutX(x);
        return true;
    }
    v.mutX(x);
    v.mutY(y + 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutY(y);
        return true;
    }
    v.mutY(y - 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutY(y);
        return true;
    }
    v.mutY(y);
    v.mutZ(z + 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z - 1);
    if (mask.test(v) && ++count == min && max >= 8) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z);
    return count >= min && count <= max;
}
 
Example 11
Source File: DFSVisitor.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Operation resume(RunContext run) throws WorldEditException {
    NodePair current;
    Node from;
    Node adjacent;
    MutableBlockVector mutable = new MutableBlockVector();
    Vector mutable2 = new Vector();
    int countAdd, countAttempt;
    IntegerTrio[] dirs = getIntDirections();

    for (int layer = 0; !queue.isEmpty(); layer++) {
        current = queue.poll();
        from = current.to;
        hashQueue.remove(from);
        if (visited.containsKey(from)) {
            continue;
        }
        mutable.mutX(from.getX());
        mutable.mutY(from.getY());
        mutable.mutZ(from.getZ());
        function.apply(mutable);
        countAdd = 0;
        countAttempt = 0;
        for (IntegerTrio direction : dirs) {
            mutable2.mutX(from.getX() + direction.x);
            mutable2.mutY(from.getY() + direction.y);
            mutable2.mutZ(from.getZ() + direction.z);
            if (isVisitable(mutable, mutable2)) {
                adjacent = new Node(mutable2.getBlockX(), mutable2.getBlockY(), mutable2.getBlockZ());
                if ((current.from == null || !adjacent.equals(current.from))) {
                    AtomicInteger adjacentCount = visited.get(adjacent);
                    if (adjacentCount == null) {
                        if (countAdd++ < maxBranch) {
                            if (!hashQueue.contains(adjacent)) {
                                if (current.depth == maxDepth) {
                                    countAttempt++;
                                } else {
                                    hashQueue.add(adjacent);
                                    queue.addFirst(new NodePair(from, adjacent, current.depth + 1));
                                }
                            } else {
                                countAttempt++;
                            }
                        } else {
                            countAttempt++;
                        }
                    } else if (adjacentCount.decrementAndGet() == 0) {
                        visited.remove(adjacent);
                    } else if (hashQueue.contains(adjacent)) {
                        countAttempt++;
                    }
                }
            }
        }
        if (countAttempt > 0) {
            visited.put(from, new AtomicInteger(countAttempt));
        }
        affected++;
    }
    return null;
}
 
Example 12
Source File: FlattenedClipboardTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the transformed region.
 *
 * @return the transformed region
 */
public Region getTransformedRegion() {
    Region region = original.getRegion();
    Vector minimum = region.getMinimumPoint();
    Vector maximum = region.getMaximumPoint();

    Transform transformAround =
            new CombinedTransform(
                    new AffineTransform().translate(original.getOrigin().multiply(-1)),
                    transform,
                    new AffineTransform().translate(original.getOrigin()));

    // new Vector(minimum.getX(), minimum.getY(), minimum.getZ())
    // new Vector(maximum.getX(), maximum.getY(), maximum.getZ())
    Vector[] corners = new Vector[]{
            minimum,
            maximum,
            new Vector(maximum.getX(), minimum.getY(), minimum.getZ()),
            new Vector(minimum.getX(), maximum.getY(), minimum.getZ()),
            new Vector(minimum.getX(), minimum.getY(), maximum.getZ()),
            new Vector(minimum.getX(), maximum.getY(), maximum.getZ()),
            new Vector(maximum.getX(), minimum.getY(), maximum.getZ()),
            new Vector(maximum.getX(), maximum.getY(), minimum.getZ())};

    for (int i = 0; i < corners.length; i++) {
        corners[i] = transformAround.apply(new Vector(corners[i]));
    }

    Vector newMinimum = corners[0];
    Vector newMaximum = corners[0];

    for (int i = 1; i < corners.length; i++) {
        newMinimum = Vector.getMinimum(newMinimum, corners[i]);
        newMaximum = Vector.getMaximum(newMaximum, corners[i]);
    }

    // After transformation, the points may not really sit on a block,
    // so we should expand the region for edge cases
    newMinimum.mutX(Math.ceil(Math.floor(newMinimum.getX())));
    newMinimum.mutY(Math.ceil(Math.floor(newMinimum.getY())));
    newMinimum.mutZ(Math.ceil(Math.floor(newMinimum.getZ())));

    return new CuboidRegion(newMinimum, newMaximum);
}