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

The following examples show how to use com.sk89q.worldedit.Vector#equals() . 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: CatenaryBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void build(EditSession editSession, Vector pos2, final Pattern pattern, double size) throws MaxChangedBlocksException {
    boolean visual = (editSession.getExtent() instanceof VisualExtent);
    if (pos1 == null || pos2.equals(pos1)) {
        if (!visual) {
            pos1 = pos2;
            BBC.BRUSH_LINE_PRIMARY.send(editSession.getPlayer(), pos2);
        }
        return;
    }
    if (this.vertex == null) {
        vertex = getVertex(pos1, pos2, slack);
        if (this.direction) {
            BBC.BRUSH_CATENARY_DIRECTION.send(editSession.getPlayer(), 2);
            return;
        }
    } else if (this.direction) {
        Location loc = editSession.getPlayer().getPlayer().getLocation();
        Vector facing = loc.getDirection().normalize();
        Vector midpoint = pos1.add(pos2).divide(2);
        Vector offset = midpoint.subtract(vertex);
        vertex = midpoint.add(facing.multiply(offset.length()));
    }
    List<Vector> nodes = Arrays.asList(pos1, vertex, pos2);
    vertex = null;
    editSession.drawSpline(pattern, nodes, 0, 0, 0, 10, size, !shell);
    if (!visual) {
        BBC.BRUSH_LINE_SECONDARY.send(editSession.getPlayer());
        if (!select) {
            pos1 = null;
            return;
        } else {
            pos1 = pos2;
        }
    }
}
 
Example 2
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean selectPrimary(Vector position, SelectorLimits limits) {
    if (position.equals(pos1)) {
        return false;
    }

    pos1 = position.toBlockVector();
    region = new Polygonal2DRegion(region.getWorld());
    region.addPoint(position);
    region.expandY(position.getBlockY());

    return true;
}
 
Example 3
Source File: CylinderRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
    Vector center = region.getCenter();

    if (!center.equals(Vector.ZERO)) {
        BBC.SELECTOR_RADIUS.send(player, NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()), region.getArea());
    } else {
        BBC.SELECTION_WAND.send(player);
        return;
    }

    session.describeCUI(player);
}
 
Example 4
Source File: EllipsoidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean selectPrimary(Vector position, SelectorLimits limits) {
    if (position.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
        return false;
    }

    region.setCenter(position.toBlockVector());
    region.setRadius(new Vector());
    started = true;

    return true;
}
 
Example 5
Source File: SurfaceSpline.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException {
    int maxY = editSession.getMaxY();
    boolean vis = editSession.getExtent() instanceof VisualExtent;
    if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) {
        int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY());
        if (max == -1) return;
        pos.mutY(max);
        path.add(pos);
        editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s());
        if (!vis) return;
    }
    LocalBlockVectorSet vset = new LocalBlockVectorSet();
    final List<Node> nodes = new ArrayList<>(path.size());
    final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation();

    for (final Vector nodevector : path) {
        final Node n = new Node(nodevector);
        n.setTension(tension);
        n.setBias(bias);
        n.setContinuity(continuity);
        nodes.add(n);
    }
    interpol.setNodes(nodes);
    final double splinelength = interpol.arcLength(0, 1);
    for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
        final Vector tipv = interpol.getPosition(loop);
        final int tipx = MathMan.roundInt(tipv.getX());
        final int tipz = (int) tipv.getZ();
        int tipy = MathMan.roundInt(tipv.getY());
        tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY);
        if (tipy == -1) continue;
        if (radius == 0) {
            editSession.setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz));
        } else {
            vset.add(tipx, tipy, tipz);
        }
    }
    if (radius != 0) {
        double radius2 = (radius * radius);
        LocalBlockVectorSet newSet = new LocalBlockVectorSet();
        final int ceilrad = (int) Math.ceil(radius);
        for (final Vector v : vset) {
            final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ();
            for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) {
                for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) {
                    if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) {
                        int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY);
                        if (y == -1) continue;
                        newSet.add(loopx, y, loopz);
                    }
                }
            }
        }
        editSession.setBlocks(newSet, pattern);
        if (!vis) path.clear();
    }
    editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY.s());
}