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

The following examples show how to use com.sk89q.worldedit.Vector#subtract() . 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: CommandBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    int radius = (int) size;
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    WorldVectorFace face = player.getBlockTraceFace(256, true);
    if (face == null) {
        position = position.add(0, 1, 1);
    } else {
        position = face.getFaceVector();
    }
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example 2
Source File: Spline.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paste structure at the provided position on the curve. The position will not be position-corrected
 * but will be passed directly to the interpolation algorithm.
 * @param position The position on the curve. Must be between 0.0 and 1.0 (both inclusive)
 * @return         The amount of blocks that have been changed
 * @throws MaxChangedBlocksException Thrown by WorldEdit if the limit of block changes for the {@link EditSession} has been reached
 */
public int pastePositionDirect(double position) throws MaxChangedBlocksException {
    Preconditions.checkArgument(position >= 0);
    Preconditions.checkArgument(position <= 1);

    // Calculate position from spline
    Vector target = interpolation.getPosition(position);
    Vector offset = target.subtract(target.round());
    target = target.subtract(offset);

    // Calculate rotation from spline

    Vector deriv = interpolation.get1stDerivative(position);
    Vector2D deriv2D = new Vector2D(deriv.getX(), deriv.getZ()).normalize();
    double angle = Math.toDegrees(
            Math.atan2(direction.getZ(), direction.getX()) - Math.atan2(deriv2D.getZ(), deriv2D.getX())
    );

    return pasteBlocks(target, offset, angle);
}
 
Example 3
Source File: ScatterCommand.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector position, Pattern p, double size) throws MaxChangedBlocksException {
    int radius = getDistance();
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example 4
Source File: SchematicStreamer.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public Clipboard getClipboard() throws IOException {
    try {
        addDimensionReaders();
        addBlockReaders();
        readFully();
        Vector min = new Vector(originX, originY, originZ);
        Vector offset = new Vector(offsetX, offsetY, offsetZ);
        Vector origin = min.subtract(offset);
        Vector dimensions = new Vector(width, height, length);
        fc.setDimensions(dimensions);
        CuboidRegion region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
        clipboard.init(region, fc);
        clipboard.setOrigin(origin);
        return clipboard;
    } catch (Throwable e) {
        if (fc != null) {
            fc.close();
        }
        throw e;
    }
}
 
Example 5
Source File: PopulateSchem.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    new MaskTraverser(mask).reset(editSession);
    SchemGen gen = new SchemGen(mask, editSession, editSession.getWorldData(), clipboards, randomRotate);
    CuboidRegion cuboid = new CuboidRegion(editSession.getWorld(), position.subtract(size, size, size), position.add(size, size, size));
    try {
        editSession.addSchems(cuboid, mask, editSession.getWorldData(), clipboards, rarity, randomRotate);
    } catch (WorldEditException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: ClipboardSpline.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected int pasteBlocks(Vector target, Vector offset, double angle) throws MaxChangedBlocksException {
    RoundedTransform transform = new RoundedTransform(new AffineTransform()
            .translate(offset)
            .rotateY(angle));
    if (!this.transform.isIdentity()) {
        transform = transform.combine(this.transform);
    }
    if (!originalTransform.isIdentity()) {
        transform = transform.combine(originalTransform);
    }

    // Pasting
    Clipboard clipboard = clipboardHolder.getClipboard();
    clipboard.setOrigin(center.subtract(centerOffset).round());
    clipboardHolder.setTransform(transform);

    Vector functionOffset = target.subtract(clipboard.getOrigin());
    final int offX = functionOffset.getBlockX();
    final int offY = functionOffset.getBlockY();
    final int offZ = functionOffset.getBlockZ();

    Operation operation = clipboardHolder
            .createPaste(editSession, editSession.getWorldData())
            .to(target)
            .ignoreAirBlocks(true)
            .filter(v -> buffer.add(v.getBlockX() + offX, v.getBlockY() + offY, v.getBlockZ() + offZ))
            .build();
    Operations.completeLegacy(operation);

    // Cleanup
    clipboardHolder.setTransform(originalTransform);
    clipboard.setOrigin(originalOrigin);

    return operation instanceof ForwardExtentCopy ? ((ForwardExtentCopy) operation).getAffected() : 0;
}
 
Example 7
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 8
Source File: ExtentBlockCopy.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Vector position) throws WorldEditException {
    BaseBlock block = source.getBlock(position);
    Vector orig = position.subtract(from);
    Vector transformed = transform.apply(orig);

    // Apply transformations to NBT data if necessary
    block = transformNbtData(block);

    return destination.setBlock(transformed.add(to), block);
}
 
Example 9
Source File: EllipsoidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean selectSecondary(Vector position, SelectorLimits limits) {
    if (!started) {
        return false;
    }

    final Vector diff = position.subtract(region.getCenter());
    final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
    region.extendRadius(minRadius);
    return true;
}
 
Example 10
Source File: CircleBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    Vector normal = position.subtract(player.getPosition());
    editSession.makeCircle(position, pattern, size, size, size, false, normal);
}
 
Example 11
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Make a cuboid from the center.
 *
 * @param origin  the origin
 * @param apothem the apothem, where 0 is the minimum value to make a 1x1 cuboid
 * @return a cuboid region
 */
public static CuboidRegion fromCenter(Vector origin, int apothem) {
    checkNotNull(origin);
    checkArgument(apothem >= 0, "apothem => 0 required");
    Vector size = new Vector(1, 1, 1).multiply(apothem);
    return new CuboidRegion(origin.subtract(size), origin.add(size));
}