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

The following examples show how to use com.sk89q.worldedit.Vector#getX() . 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: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get a region that contains the faces of this cuboid.
 *
 * @return a new complex region
 */
public Region getFaces() {
    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();

    return new RegionIntersection(
            // Project to Z-Y plane
            new CuboidRegion(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())),
            new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())),

            // Project to X-Y plane
            new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())),
            new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), max.getZ())),

            // Project to the X-Z plane
            new CuboidRegion(new Vector(pos1.getX(), min.getY(), pos1.getZ()), new Vector(pos2.getX(), min.getY(), pos2.getZ())),
            new CuboidRegion(new Vector(pos1.getX(), max.getY(), pos1.getZ()), new Vector(pos2.getX(), max.getY(), pos2.getZ())));
}
 
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: ArbitraryShape.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ArbitraryShape(Region extent) {
    this.extent = extent;

    Vector min = extent.getMinimumPoint();
    Vector max = extent.getMaximumPoint();

    cacheOffsetX = min.getBlockX() - 1;
    cacheOffsetY = min.getBlockY() - 1;
    cacheOffsetZ = min.getBlockZ() - 1;

    cacheSizeX = (int) (max.getX() - cacheOffsetX + 2);
    cacheSizeY = (int) (max.getY() - cacheOffsetY + 2);
    cacheSizeZ = (int) (max.getZ() - cacheOffsetZ + 2);

    cache = new short[cacheSizeX * cacheSizeY * cacheSizeZ];
}
 
Example 4
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
    org.spongepowered.api.world.Location<World> loc = new org.spongepowered.api.world.Location<>(
            this.player.getWorld(), pos.getX(), pos.getY(), pos.getZ()
    );

    this.player.setLocationAndRotation(loc, new Vector3d(pitch, yaw, 0));
}
 
Example 5
Source File: AffineTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public Vector apply(Vector vector) {
        // vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03
        // vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13
        // vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23
        return new Vector(
                vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
                vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
                vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
//        mutable.mutX((vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03));
//        mutable.mutY((vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13));
//        mutable.mutZ((vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23));
//        return mutable;
    }
 
Example 6
Source File: CircleBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector any90Rotate(Vector normal) {
    normal = normal.normalize();
    if (normal.getX() == 1 || normal.getY() == 1 || normal.getZ() == 1) {
        return new Vector(normal.getZ(), normal.getX(), normal.getY());
    }
    AffineTransform affine = new AffineTransform();
    affine = affine.rotateX(90);
    affine = affine.rotateY(90);
    affine = affine.rotateZ(90);
    Vector random = affine.apply(normal);
    return random.cross(normal).normalize();
}
 
Example 7
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 8
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 9
Source File: TemporalExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getLazyBlock(Vector position) {
    if (position.getX() == x && position.getY() == y && position.getZ() == z) {
        return block;
    }
    return super.getLazyBlock(position);
}
 
Example 10
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a region that contains the walls (all faces but the ones parallel to
 * the X-Z plane) of this cuboid.
 *
 * @return a new complex region
 */
public Region getWalls() {
    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();

    return new RegionIntersection(
            // Project to Z-Y plane
            new CuboidRegion(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())),
            new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())),

            // Project to X-Y plane
            new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())),
            new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), max.getZ())));
}
 
Example 11
Source File: FawePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void checkConfirmationStack(@Nullable ThrowableRunnable<WorldEditException> task, String command, Region region, int times, CommandContext context) throws WorldEditException {
    if (command != null && !getMeta("cmdConfirmRunning", false)) {
        if (region != null) {
            Vector min = region.getMinimumPoint().toBlockVector();
            Vector max = region.getMaximumPoint().toBlockVector();
            long area = (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times;
            if (area > 2 << 18) {
                setConfirmTask(task, context, command);
                long volume = (long) max.subtract(min).add(Vector.ONE).volume() * times;
                throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command, NumberFormat.getNumberInstance().format(volume)));
            }
        }
    }
    if (task != null) task.run();
}
 
Example 12
Source File: PatternExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getBlock(Vector position) {
    BaseBlock tmp = pattern.apply(position);
    if (position == target || (position.getX() == target.getX() && position.getY() == target.getY() && position.getZ() == target.getZ())) {
        block = tmp;
    } else {
        block = null;
    }
    return tmp;
}
 
Example 13
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
    org.spongepowered.api.world.Location<World> loc = new org.spongepowered.api.world.Location<>(
            this.player.getWorld(), pos.getX(), pos.getY(), pos.getZ()
    );

    this.player.setLocationAndRotation(loc, new Vector3d(pitch, yaw, 0));
}
 
Example 14
Source File: BukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private static org.bukkit.Location adapt(org.bukkit.World world, Vector position) {
    checkNotNull(world);
    checkNotNull(position);
    return new org.bukkit.Location(
            world,
            position.getX(), position.getY(), position.getZ());
}
 
Example 15
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void contract(Vector... changes) {
    checkNotNull(changes);

    for (Vector change : changes) {
        if (change.getX() < 0) {
            if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
                pos1 = pos1.add(new Vector(change.getX(), 0, 0));
            } else {
                pos2 = pos2.add(new Vector(change.getX(), 0, 0));
            }
        } else {
            if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) {
                pos1 = pos1.add(new Vector(change.getX(), 0, 0));
            } else {
                pos2 = pos2.add(new Vector(change.getX(), 0, 0));
            }
        }

        if (change.getY() < 0) {
            if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) {
                pos1 = pos1.add(new Vector(0, change.getY(), 0));
            } else {
                pos2 = pos2.add(new Vector(0, change.getY(), 0));
            }
        } else {
            if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) {
                pos1 = pos1.add(new Vector(0, change.getY(), 0));
            } else {
                pos2 = pos2.add(new Vector(0, change.getY(), 0));
            }
        }

        if (change.getZ() < 0) {
            if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
                pos1 = pos1.add(new Vector(0, 0, change.getZ()));
            } else {
                pos2 = pos2.add(new Vector(0, 0, change.getZ()));
            }
        } else {
            if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
                pos1 = pos1.add(new Vector(0, 0, change.getZ()));
            } else {
                pos2 = pos2.add(new Vector(0, 0, change.getZ()));
            }
        }
    }

    recalculate();
}
 
Example 16
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);
}
 
Example 17
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public static cn.nukkit.level.Location toLocation(Level world, Vector pt) {
    return new cn.nukkit.level.Location(pt.getX(), pt.getY(), pt.getZ(), 0, 0, world);
}
 
Example 18
Source File: NukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
private Vector3 setMutable(Vector pt) {
    mutable.x = pt.getX();
    mutable.y = pt.getY();
    mutable.z = pt.getZ();
    return mutable;
}
 
Example 19
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 20
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void expand(Vector... changes) {
    checkNotNull(changes);

    for (Vector change : changes) {
        if (change.getX() > 0) {
            if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
                pos1 = pos1.add(new Vector(change.getX(), 0, 0));
            } else {
                pos2 = pos2.add(new Vector(change.getX(), 0, 0));
            }
        } else {
            if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) {
                pos1 = pos1.add(new Vector(change.getX(), 0, 0));
            } else {
                pos2 = pos2.add(new Vector(change.getX(), 0, 0));
            }
        }

        if (change.getY() > 0) {
            if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) {
                pos1 = pos1.add(new Vector(0, change.getY(), 0));
            } else {
                pos2 = pos2.add(new Vector(0, change.getY(), 0));
            }
        } else {
            if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) {
                pos1 = pos1.add(new Vector(0, change.getY(), 0));
            } else {
                pos2 = pos2.add(new Vector(0, change.getY(), 0));
            }
        }

        if (change.getZ() > 0) {
            if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
                pos1 = pos1.add(new Vector(0, 0, change.getZ()));
            } else {
                pos2 = pos2.add(new Vector(0, 0, change.getZ()));
            }
        } else {
            if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
                pos1 = pos1.add(new Vector(0, 0, change.getZ()));
            } else {
                pos2 = pos2.add(new Vector(0, 0, change.getZ()));
            }
        }
    }

    recalculate();
}