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

The following examples show how to use com.sk89q.worldedit.Vector#add() . 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: PolyhedralRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void shift(Vector change) throws RegionOperationException {
    shiftCollection(vertices, change);
    shiftCollection(vertexBacklog, change);

    for (int i = 0; i < triangles.size(); ++i) {
        final Triangle triangle = triangles.get(i);

        final Vector v0 = change.add(triangle.getVertex(0));
        final Vector v1 = change.add(triangle.getVertex(1));
        final Vector v2 = change.add(triangle.getVertex(2));

        triangles.set(i, new Triangle(v0, v1, v2));
    }

    minimumPoint = change.add(minimumPoint);
    maximumPoint = change.add(maximumPoint);
    centerAccum = change.multiply(vertices.size()).add(centerAccum);
    lastTriangle = null;
}
 
Example 2
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 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: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private boolean sendBlockChange(Player plr, VirtualWorld gen, Vector pt, Interaction action) {
    PlatformManager platform = WorldEdit.getInstance().getPlatformManager();
    com.sk89q.worldedit.entity.Player actor = FawePlayer.wrap(plr).getPlayer();
    com.sk89q.worldedit.util.Location location = new com.sk89q.worldedit.util.Location(actor.getWorld(), pt);
    BlockInteractEvent toCall = new BlockInteractEvent(actor, location, action);
    platform.handleBlockInteract(toCall);
    if (toCall.isCancelled() || action == Interaction.OPEN) {
        Vector realPos = pt.add(gen.getOrigin());
        BaseBlock block = gen.getBlock(pt);
        sendBlockChange(plr, realPos, block);
        return true;
    }
    return false;
}
 
Example 5
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector getRelative(PacketEvent container, Vector pt) {
    PacketContainer packet = container.getPacket();
    StructureModifier<EnumWrappers.Direction> dirs = packet.getDirections();
    EnumWrappers.Direction dir = dirs.readSafely(0);
    if (dir == null) return pt;
    switch (dir.ordinal()) {
        case 0: return pt.add(0, -1, 0);
        case 1: return pt.add(0, 1, 0);
        case 2: return pt.add(0, 0, -1);
        case 3: return pt.add(0, 0, 1);
        case 4: return pt.add(-1, 0, 0);
        case 5: return pt.add(1, 0, 0);
        default: return pt;
    }
}
 
Example 6
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 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: EllipsoidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector calculateChanges(Vector... changes) {
    Vector total = new Vector();
    for (Vector change : changes) {
        total = total.add(change.positive());
    }

    return total.divide(2).floor();
}
 
Example 9
Source File: EllipsoidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the radii.
 *
 * @param radius the radius
 */
public void setRadius(Vector radius) {
    this.radius = new MutableBlockVector(radius.add(0.5, 0.5, 0.5));
    radiusSqr = new MutableBlockVector(radius.multiply(radius));
    radiusLengthSqr = radiusSqr.getBlockX();
    if (radius.getBlockY() == radius.getBlockX() && radius.getBlockX() == radius.getBlockZ()) {
        this.sphere = true;
    } else {
        this.sphere = false;
    }
}
 
Example 10
Source File: WorldEditExpressionEnvironment.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public WorldEditExpressionEnvironment(Extent extent, Vector unit, Vector zero) {
    this.extent = extent;
    this.unit = unit;
    this.zero2 = zero.add(0.5, 0.5, 0.5);
}
 
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));
}