com.sk89q.worldedit.Vector Java Examples

The following examples show how to use com.sk89q.worldedit.Vector. 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: LocalBlockVectorSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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 #2
Source File: AngleColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: AngleMask.java    From FastAsyncWorldedit with 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 #4
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 #5
Source File: ScaleTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: PolyhedralRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #7
Source File: SelectionCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source File: PlayerWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: CylinderRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@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 #10
Source File: CatenaryBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: BundledBlockData.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: StructureCUI.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #13
Source File: DiskOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: DataAnglePattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public int getSlope(BaseBlock block, Vector vector) {
    int x = vector.getBlockX();
    int y = vector.getBlockY();
    int z = vector.getBlockZ();
    if (FaweCache.canPassThrough(block.getId(), block.getData())) {
        return -1;
    }
    int slope;
    boolean aboveMin;
    slope = Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7;
    slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x, z - distance, y, 0, maxY)) * 7;
    slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z - distance, y, 0, maxY)) * 5;
    slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x - distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x + distance, z - distance, y, 0, maxY)) * 5;
    return slope;
}
 
Example #16
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 #17
Source File: ExistingPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
    if (set.getBlockX() == get.getBlockX() && set.getBlockZ() == get.getBlockZ() && set.getBlockY() == get.getBlockY()) {
        return false;
    }
    return extent.setBlock(set, extent.getBlock(get));
}
 
Example #18
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 #19
Source File: ClipboardPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #20
Source File: LocalBlockVectorSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 #21
Source File: NukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dropItem(Vector pt, BaseItemStack item) {
    Level world = getLevel();
    Item nukkitItem = new Item(item.getType(), item.getAmount(),
            item.getData());
    world.dropItem(NukkitUtil.toLocation(world, pt), nukkitItem);
}
 
Example #22
Source File: WorldCopyClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
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 #23
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 #24
Source File: BlockVectorSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean addAll(Collection<? extends Vector> c) {
    boolean result = false;
    for (Vector v : c) {
        result |= add(v);
    }
    return result;
}
 
Example #25
Source File: BukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 #26
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 #27
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #28
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"<"},
        desc = "below a specific block",
        usage = "<mask>",
        min = 1,
        max = 1
)
public Mask below(Mask mask) throws ExpressionException {
    OffsetMask offsetMask = new OffsetMask(mask, new Vector(0, 1, 0));
    return new MaskIntersection(offsetMask, Masks.negate(mask));
}
 
Example #29
Source File: BackwardsExtentBlockCopy.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public BackwardsExtentBlockCopy(Extent source, Region region, Extent destination, Vector origin, Transform transform, RegionFunction function) {
    this.source = source;
    this.region = region;
    this.destination = destination;
    this.transform = transform;
    this.function = function;
    this.origin = origin;
}
 
Example #30
Source File: WorldWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean generateRedwoodTree(final EditSession editSession, final Vector pt) throws MaxChangedBlocksException {
    return TaskManager.IMP.sync(new RunnableVal<Boolean>() {
        @Override
        public void run(Boolean ignore) {
            try {
                this.value = parent.generateRedwoodTree(editSession, pt);
            } catch (MaxChangedBlocksException e) {
                MainUtil.handleError(e);
            }
        }
    });
}