Java Code Examples for com.sk89q.worldedit.Vector

The following examples show how to use com.sk89q.worldedit.Vector. These examples are extracted from open source projects. 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
@Override
public void setDimensions(Vector dimensions) {
    try {
        width = dimensions.getBlockX();
        height = dimensions.getBlockY();
        length = dimensions.getBlockZ();
        area = width * length;
        volume = width * length * height;
        long size = width * height * length * 2l + HEADER_SIZE + (hasBiomes() ? area : 0);
        if (braf.length() < size) {
            close();
            this.braf = new RandomAccessFile(file, "rw");
            braf.setLength(size);
            init();
        }
        mbb.putChar(2, (char) width);
        mbb.putChar(4, (char) height);
        mbb.putChar(6, (char) length);
    } catch (IOException e) {
        MainUtil.handleError(e);
    }
}
 
Example 2
public void forEach(BlockVectorSetVisitor visitor) {
    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;
        int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21);
        int y = b1;
        int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21);
        visitor.run(x, y, z, index);
    }
}
 
Example 3
private Vector[] getChangesForEachDir(CommandContext args) {
    List<Vector> changes = new ArrayList<Vector>(6);
    int change = args.getInteger(0);

    if (!args.hasFlag('h')) {
        changes.add((new Vector(0, 1, 0)).multiply(change));
        changes.add((new Vector(0, -1, 0)).multiply(change));
    }

    if (!args.hasFlag('v')) {
        changes.add((new Vector(1, 0, 0)).multiply(change));
        changes.add((new Vector(-1, 0, 0)).multiply(change));
        changes.add((new Vector(0, 0, 1)).multiply(change));
        changes.add((new Vector(0, 0, -1)).multiply(change));
    }

    return changes.toArray(new Vector[0]);
}
 
Example 4
@Override
public boolean contains(Vector position) {
    if (!isDefined()) {
        return false;
    }
    final int x = position.getBlockX();
    final int y = position.getBlockY();
    final int z = position.getBlockZ();
    final Vector min = getMinimumPoint();
    final Vector max = getMaximumPoint();
    if (x < min.getBlockX()) return false;
    if (x > max.getBlockX()) return false;
    if (z < min.getBlockZ()) return false;
    if (z > max.getBlockZ()) return false;
    if (y < min.getBlockY()) return false;
    if (y > max.getBlockY()) return false;
    return containsRaw(position);
}
 
Example 5
Source Project: FastAsyncWorldedit   Source File: AngleMask.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean test(Vector vector) {
    int x = vector.getBlockX();
    int y = vector.getBlockY();
    int z = vector.getBlockZ();

    if ((lastX == (lastX = x) & lastZ == (lastZ = z))) {
        int height = getHeight(x, y, z);
        if (y <= height) return overlay ? (lastValue && y == height) : lastValue;
    }

    if (!mask.test(x, y, z)) {
        return false;
    }
    if (overlay) {
        if (y < 255 && !mask.test(x, y + 1, z)) return lastValue = false;
    } else if (!adjacentAir(vector)) {
        return false;
    }
    return testSlope(x, y, z);
}
 
Example 6
@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 7
@Override
public CylinderRegion asRegion(Element container) {
	Element centerElement = container.element("center");
	Element radiusElement = container.element("radius");
	Element minYElement = container.element("minY");
	Element maxYElement = container.element("maxY");
	
	int cx = Integer.parseInt(centerElement.elementText("x"));
	int cy = Integer.parseInt(centerElement.elementText("y"));
	int cz = Integer.parseInt(centerElement.elementText("z"));
	
	int rx = Integer.parseInt(radiusElement.elementText("x"));
	int rz = Integer.parseInt(radiusElement.elementText("z"));
	
	int minY = Integer.parseInt(minYElement.getText());
	int maxY = Integer.parseInt(maxYElement.getText());
	
	Vector center = new Vector(cx, cy, cz);
	Vector2D radius = new Vector2D(rx, rz);
	
	return new CylinderRegion(center, radius, minY, maxY);
}
 
Example 8
@Override
public void dispatchCUIEvent(CUIEvent event) {
    if (event instanceof SelectionShapeEvent) {
        clear();
        this.cuboid = event.getParameters()[0].equalsIgnoreCase("cuboid");
    } else if (cuboid && event instanceof SelectionPointEvent) {
        SelectionPointEvent spe = (SelectionPointEvent) event;
        String[] param = spe.getParameters();
        int id = Integer.parseInt(param[0]);
        int x = Integer.parseInt(param[1]);
        int y = Integer.parseInt(param[2]);
        int z = Integer.parseInt(param[3]);
        Vector pos = new Vector(x, y, z);
        if (id == 0) {
            pos1 = pos;
        } else {
            pos2 = pos;
        }
        update();
    }
}
 
Example 9
@Override
public void floatAt(final int x, final int y, final int z, final boolean alwaysGlass) {
    RuntimeException caught = null;
    try {
        EditSession edit = new EditSessionBuilder(parent.getWorld()).player(FawePlayer.wrap(this)).build();
        edit.setBlockFast(new Vector(x, y - 1, z), new BaseBlock(BlockType.GLASS.getID()));
        edit.flushQueue();
        LocalSession session = Fawe.get().getWorldEdit().getSession(this);
        if (session != null) {
            session.remember(edit, true, FawePlayer.wrap(this).getLimit().MAX_HISTORY);
        }
    } catch (RuntimeException e) {
        caught = e;
    }
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            setPosition(new Vector(x + 0.5, y, z + 0.5));
        }
    });
    if (caught != null) {
        throw caught;
    }
}
 
Example 10
public static Vector getVertex(Vector pos1, Vector pos2, double lenPercent) {
    if (lenPercent <= 1) return Vector.getMidpoint(pos1, pos2);
    double curveLen = pos1.distance(pos2) * lenPercent;
    double dy = pos2.getY() - pos1.getY();
    double dx = pos2.getX() - pos1.getX();
    double dz = pos2.getZ() - pos1.getZ();
    double dh = Math.sqrt(dx * dx + dz * dz);
    double g = Math.sqrt(curveLen * curveLen - dy * dy) / 2;
    double a = 0.00001;
    for (;g < a * Math.sinh(dh/(2 * a)); a *= 1.00001);
    double vertX = (dh-a*Math.log((curveLen + dy)/(curveLen - dy)))/2.0;
    double z = (dh/2)/a;
    double oY = (dy - curveLen * (Math.cosh(z) / Math.sinh(z))) / 2;
    double vertY = a * 1 + oY;
    return pos1.add(pos2.subtract(pos1).multiply(vertX / dh).add(0, vertY, 0)).round();
}
 
Example 11
protected void fixDirection(Vector direction, String key, Byte mask, int data) {
    FaweState state = states.remove(key);
    if (state != null && !state.hasDirection()) {
        FaweState facing = states.get("facing");
        if (facing == null) {
            facing = BundledBlockData.getInstance().new FaweState();
            facing.values = new HashMap<>();
            states.put("facing", facing);
        }
        if (mask != null) facing.dataMask = (byte) (facing.getDataMask() | mask);
        FaweStateValue value = BundledBlockData.getInstance().new FaweStateValue();
        value.state = facing;
        value.data = (byte) data;
        value.direction = direction;
        facing.values.put(key, value);
    }
}
 
Example 12
@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 13
@Override
public int getSlope(BaseBlock block, Vector vector) {
    int slope = super.getSlope(block, vector);
    if (slope != -1) {
        int x = vector.getBlockX();
        int y = vector.getBlockY();
        int z = vector.getBlockZ();
        int height = extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
        if (height > 0) {
            BaseBlock below = extent.getLazyBlock(x, height - 1, z);
            if (FaweCache.canPassThrough(below.getId(), below.getData())) {
                return Integer.MAX_VALUE;
            }
        }
    }
    return slope;
}
 
Example 14
Source Project: FastAsyncWorldedit   Source File: Masks.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Negate the given mask.
 *
 * @param finalMask the mask
 * @return a new mask
 */
public static Mask negate(final Mask finalMask) {
    if (finalMask instanceof AlwaysTrue) {
        return ALWAYS_FALSE;
    } else if (finalMask instanceof AlwaysFalse) {
        return ALWAYS_TRUE;
    }
    checkNotNull(finalMask);
    return new AbstractMask() {
        private Mask mask = finalMask;

        @Override
        public boolean test(Vector vector) {
            return !mask.test(vector);
        }

        @Nullable
        @Override
        public Mask2D toMask2D() {
            Mask2D mask2d = mask.toMask2D();
            if (mask2d != null) {
                return negate(mask2d);
            } else {
                return null;
            }
        }
    };
}
 
Example 15
@Override
public Vector apply(Vector input) {
    Vector val = transform.apply(input);
    mutable.mutX((int) Math.floor(val.getX() + 0.5));
    mutable.mutY((int) Math.floor(val.getY() + 0.5));
    mutable.mutZ((int) Math.floor(val.getZ() + 0.5));
    return mutable;
}
 
Example 16
@Override
public void streamBiomes(NBTStreamer.ByteReader task) {
    Vector dim = getDimensions();
    int index = 0;
    for (int z = 0; z <= dim.getBlockZ(); z++) {
        for (int x = 0; x <= dim.getBlockX(); x++, index++) {
            task.run(index, getBiome(x, z).getId());
        }
    }
}
 
Example 17
Source Project: FastAsyncWorldedit   Source File: Triangle.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Triangle(Vector pos1, Vector pos2, Vector pos3) {
    verts[0] = new double[]{pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ()};
    verts[1] = new double[]{pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ()};
    verts[2] = new double[]{pos3.getBlockX(), pos3.getBlockY(), pos3.getBlockZ()};
    radius[0] = RADIUS;
    radius[1] = RADIUS;
    radius[2] = RADIUS;
    this.normalVec = pos2.subtract(pos1).cross(pos3.subtract(pos1)).normalize();
    this.b = Math.max(Math.max(this.normalVec.dot(pos1), this.normalVec.dot(pos2)), this.normalVec.dot(pos3));
}
 
Example 18
private Vector calculateChanges(Vector... changes) {
    Vector total = new Vector();
    for (Vector change : changes) {
        total = total.add(change.positive());
    }

    return total.divide(2).floor();
}
 
Example 19
@Override
public boolean selectSecondary(Vector position, SelectorLimits limits) {
    if (!started) {
        return false;
    }

    final double radiusScalar = Math.ceil(position.distance(region.getCenter()));
    region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));

    return true;
}
 
Example 20
/**
 * Create a new clipboard pattern.
 *
 * @param clipboard the clipboard
 */
public ClipboardPattern(Clipboard clipboard) {
    checkNotNull(clipboard);
    this.clipboard = clipboard;
    Vector size = clipboard.getMaximumPoint().subtract(clipboard.getMinimumPoint()).add(1, 1, 1);
    this.sx = size.getBlockX();
    this.sy = size.getBlockY();
    this.sz = size.getBlockZ();
    this.min = clipboard.getMinimumPoint();
}
 
Example 21
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 22
Source Project: FastAsyncWorldedit   Source File: RockBrush.java    License: 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 {
    double seedX = ThreadLocalRandom.current().nextDouble();
    double seedY = ThreadLocalRandom.current().nextDouble();
    double seedZ = ThreadLocalRandom.current().nextDouble();

    int px = position.getBlockX();
    int py = position.getBlockY();
    int pz = position.getBlockZ();

    double distort = this.frequency / size;

    double modX = 1d/radius.getX();
    double modY = 1d/radius.getY();
    double modZ = 1d/radius.getZ();

    int radiusSqr = (int) (size * size);
    int sizeInt = (int) size * 2;
    for (int x = -sizeInt; x <= sizeInt; x++) {
        double nx = seedX + x * distort;
        double d1 = x * x * modX;
        for (int y = -sizeInt; y <= sizeInt; y++) {
            double d2 = d1 + y * y * modY;
            double ny = seedY + y * distort;
            for (int z = -sizeInt; z <= sizeInt; z++) {
                double nz = seedZ + z * distort;
                double distance = d2 + z * z * modZ;
                double noise = this.amplitude * SimplexNoise.noise(nx, ny, nz);
                if (distance + distance * noise < radiusSqr) {
                    editSession.setBlock(px + x, py + y, pz + z, pattern);
                }
            }
        }
    }
}
 
Example 23
@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 24
public WorldCopyClipboard(EditSession editSession, Region region, boolean hasEntities, boolean hasBiomes) {
    super(region);
    this.hasBiomes = hasBiomes;
    this.hasEntities = hasEntities;
    final Vector origin = region.getMinimumPoint();
    this.mx = origin.getBlockX();
    this.my = origin.getBlockY();
    this.mz = origin.getBlockZ();
    this.editSession = editSession;
}
 
Example 25
@Override
public Iterator<Vector> iterator() {
    return new Iterator<Vector>() {
        int index = set.nextSetBit(0);
        int previous = -1;
        MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);

        @Override
        public void remove() {
            set.clear(previous);
        }

        @Override
        public boolean hasNext() {
            return index != -1;
        }

        @Override
        public BlockVector next() {
            if (index != -1) {
                int b1 = (index & 0xFF);
                int b2 = ((byte) (index >> 8)) & 0x7F;
                int b3 = ((byte) (index >> 15)) & 0xFF;
                int b4 = ((byte) (index >> 23)) & 0xFF;
                mutable.mutX(offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21));
                mutable.mutY(b1);
                mutable.mutZ(offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21));
                previous = index;
                index = set.nextSetBit(index + 1);
                return mutable;
            }
            return null;
        }
    };
}
 
Example 26
@Command(
        aliases = {"paste"},
        desc = "Paste chunks from your anvil clipboard",
        help =
                "Paste the chunks from your anvil clipboard.\n" +
                        "The -c flag will align the paste to the chunks.",
        flags = "c"

)
@CommandPermissions("worldedit.anvil.pastechunks")
public void paste(Player player, LocalSession session, EditSession editSession, @Switch('c') boolean alignChunk) throws WorldEditException, IOException {
    FawePlayer fp = FawePlayer.wrap(player);
    MCAClipboard clipboard = fp.getMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD);
    if (clipboard == null) {
        fp.sendMessage(BBC.getPrefix() + "You must first use `//anvil copy`");
        return;
    }
    CuboidRegion cuboid = clipboard.getRegion();
    RegionWrapper copyRegion = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
    final Vector offset = player.getPosition().subtract(clipboard.getOrigin());
    if (alignChunk) {
        offset.setComponents((offset.getBlockX() >> 4) << 4, offset.getBlockY(), (offset.getBlockZ() >> 4) << 4);
    }
    int oX = offset.getBlockX();
    int oZ = offset.getBlockZ();
    RegionWrapper pasteRegion = new RegionWrapper(copyRegion.minX + oX, copyRegion.maxX + oX, copyRegion.minZ + oZ, copyRegion.maxZ + oZ);
    String pasteWorldName = Fawe.imp().getWorldName(editSession.getWorld());
    FaweQueue tmpTo = SetQueue.IMP.getNewQueue(pasteWorldName, true, false);
    MCAQueue copyQueue = clipboard.getQueue();
    MCAQueue pasteQueue = new MCAQueue(tmpTo);

    fp.checkAllowedRegion(pasteRegion);
    recordHistory(fp, editSession.getWorld(), iAnvilHistory -> {
        try {
            pasteQueue.pasteRegion(copyQueue, copyRegion, offset, iAnvilHistory);
        } catch (IOException e) { throw new RuntimeException(e); }
    });
    BBC.COMMAND_PASTE.send(player, player.getPosition().toBlockVector());
}
 
Example 27
@Override
public boolean addAll(Collection<? extends Vector> c) {
    boolean result = false;
    for (Vector v : c) {
        result |= add(v);
    }
    return result;
}
 
Example 28
@SuppressWarnings("deprecation")
@Override
public BaseBlock getLazyBlock(Vector position) {
    World world = getWorld();
    Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position);
}
 
Example 29
@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 30
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.worldObj),
            position,
            this.player.cameraYaw,
            this.player.cameraPitch);
}