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

The following examples show how to use com.sk89q.worldedit.Vector#getBlockZ() . 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: CorruptSchematicStreamer.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public FaweClipboard setupClipboard() {
    if (fc != null) {
        return fc;
    }
    Vector dimensions = guessDimensions(volume.get(), width.get(), height.get(), length.get());
    if (width.get() == 0 || height.get() == 0 || length.get() == 0) {
        Fawe.debug("No dimensions found! Estimating based on factors:" + dimensions);
    }
    if (Settings.IMP.CLIPBOARD.USE_DISK) {
        fc = new DiskOptimizedClipboard(dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ(), uuid);
    } else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) {
        fc = new CPUOptimizedClipboard(dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ());
    } else {
        fc = new MemoryOptimizedClipboard(dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ());
    }
    return fc;
}
 
Example 2
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Set<Vector> getChunkCubes() {
    Set chunks = new LocalBlockVectorSet();

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

    for (int x = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x >= min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; --x) {
        for (int z = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z >= min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; --z) {
            for (int y = max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y >= min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; --y) {
                chunks.add(new Vector(x, y, z));
            }
        }
    }

    return chunks;
}
 
Example 3
Source File: CuboidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
    checkNotNull(player);
    checkNotNull(session);
    checkNotNull(pos);

    Message msg;
    if (position1 != null && position2 != null) {
        msg = BBC.SELECTOR_POS.m(1, position1, region.getArea());
    } else {
        msg = BBC.SELECTOR_POS.m(1, position1, "");
    }
    String prefix = WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/";
    String cmd = prefix + Commands.getAlias(SelectionCommands.class, "/pos1") + " " + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
    msg.suggestTip(cmd).send(player);

    session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
}
 
Example 4
Source File: AdjacentAnyMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean test(Vector v) {
    int x = v.getBlockX();
    int y = v.getBlockY();
    int z = v.getBlockZ();
    if (mask.test(x + 1, y, z)) {
        return true;
    }
    if (mask.test(x - 1, y, z)) {
        return true;
    }
    if (mask.test(x, y, z + 1)) {
        return true;
    }
    if (mask.test(x, y, z - 1)) {
        return true;
    }
    if (y < 256 && mask.test(x, y + 1, z)) {
        return true;
    }
    if (y > 0 && mask.test(x, y - 1, z)) {
        return true;
    }
    return false;
}
 
Example 5
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean selectSecondary(Vector position, SelectorLimits limits) {
    if (region.size() > 0) {
        final List<BlockVector2D> points = region.getPoints();

        final BlockVector2D lastPoint = points.get(region.size() - 1);
        if (lastPoint.getBlockX() == position.getBlockX() && lastPoint.getBlockZ() == position.getBlockZ()) {
            return false;
        }

        Optional<Integer> vertexLimit = limits.getPolygonVertexLimit();

        if (vertexLimit.isPresent() && points.size() > vertexLimit.get()) {
            return false;
        }
    }

    region.addPoint(position);
    region.expandY(position.getBlockY());

    return true;
}
 
Example 6
Source File: EllipsoidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean contains(Vector position) {
    int cx = position.getBlockX() - center.getBlockX();
    int cx2 = cx * cx;
    if (cx2 > radiusSqr.getBlockX()) {
        return false;
    }
    int cz = position.getBlockZ() - center.getBlockZ();
    int cz2 = cz * cz;
    if (cz2 > radiusSqr.getBlockZ()) {
        return false;
    }
    int cy = position.getBlockY() - center.getBlockY();
    int cy2 = cy * cy;
    if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
        return false;
    }
    if (sphere) {
        return cx2 + cy2 + cz2 <= radiusLengthSqr;
    }
    double cxd = (double) cx / radius.getBlockX();
    double cyd = (double) cy / radius.getBlockY();
    double czd = (double) cz / radius.getBlockZ();
    return cxd * cxd + cyd * cyd + czd * czd <= 1;
}
 
Example 7
Source File: WEManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean intersects(final Region region1, final Region region2) {
    Vector rg1P1 = region1.getMinimumPoint();
    Vector rg1P2 = region1.getMaximumPoint();
    Vector rg2P1 = region2.getMinimumPoint();
    Vector rg2P2 = region2.getMaximumPoint();

    return (rg1P1.getBlockX() <= rg2P2.getBlockX()) && (rg1P2.getBlockX() >= rg2P1.getBlockX()) && (rg1P1.getBlockZ() <= rg2P2.getBlockZ()) && (rg1P2.getBlockZ() >= rg2P1.getBlockZ());
}
 
Example 8
Source File: CPUOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setDimensions(Vector dimensions) {
    width = dimensions.getBlockX();
    height = dimensions.getBlockY();
    length = dimensions.getBlockZ();
    area = width * length;
    int newVolume = area * height;
    if (newVolume != volume) {
        volume = newVolume;
        ids = new byte[volume];
        datas = new byte[volume];
    }
}
 
Example 9
Source File: RandomOffsetTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(Vector pos, BaseBlock block) throws WorldEditException {
    int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx;
    int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy;
    int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz;
    return getExtent().setBlock(x, y, z, block);
}
 
Example 10
Source File: DFSVisitor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private IntegerTrio[] getIntDirections() {
    IntegerTrio[] array = new IntegerTrio[directions.size()];
    for (int i = 0; i < array.length; i++) {
        Vector dir = directions.get(i);
        array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ());
    }
    return array;
}
 
Example 11
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 12
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 13
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 14
Source File: BreadthFirstSearch.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private IntegerTrio[] getIntDirections() {
    IntegerTrio[] array = new IntegerTrio[directions.size()];
    for (int i = 0; i < array.length; i++) {
        Vector dir = directions.get(i);
        array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ());
    }
    return array;
}
 
Example 15
Source File: ReadOnlyClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 16
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector getRelPos(PacketEvent event, VirtualWorld generator) {
    PacketContainer packet = event.getPacket();
    StructureModifier<BlockPosition> position = packet.getBlockPositionModifier();
    BlockPosition loc = position.readSafely(0);
    if (loc == null) return null;
    Vector origin = generator.getOrigin();
    Vector pt = new Vector(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ());
    return pt;
}
 
Example 17
Source File: HeightMap.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public int apply(int[] data) throws WorldEditException {
    checkNotNull(data);

    Vector minY = region.getMinimumPoint();
    int originX = minY.getBlockX();
    int originY = minY.getBlockY();
    int originZ = minY.getBlockZ();

    int maxY = region.getMaximumPoint().getBlockY();
    BaseBlock fillerAir = EditSession.nullBlock;

    int blocksChanged = 0;

    BaseBlock tmpBlock = EditSession.nullBlock;

    // Apply heightmap
    int index = 0;
    for (int z = 0; z < height; ++z) {
        int zr = z + originZ;
        for (int x = 0; x < width; ++x, index++) {
            int curHeight = this.data[index];
            if (this.invalid != null && this.invalid[index]) continue;
            int newHeight = Math.min(maxY, data[index]);

            int xr = x + originX;

            // Depending on growing or shrinking we need to start at the bottom or top
            if (newHeight > curHeight) {
                // Set the top block of the column to be the same type (this might go wrong with rounding)
                BaseBlock existing = session.getBlock(xr, curHeight, zr);


                // Skip water/lava
                if (!FaweCache.isLiquidOrGas(existing.getId())) {
                    int y0 = newHeight - 1;
                    for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) {
                        BaseBlock get = session.getBlock(xr, getY, zr);
                        if (get != EditSession.nullBlock) tmpBlock = get;
                        session.setBlock(xr, setY, zr, tmpBlock);
                        ++blocksChanged;
                    }
                    session.setBlock(xr, newHeight, zr, existing);
                    ++blocksChanged;
                }
            } else if (curHeight > newHeight) {
                // Set the top block of the column to be the same type
                // (this could otherwise go wrong with rounding)
                session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr));
                ++blocksChanged;

                // Fill rest with air
                for (int y = newHeight + 1; y <= curHeight; ++y) {
                    session.setBlock(xr, y, zr, fillerAir);
                    ++blocksChanged;
                }
            }
        }
    }
    return blocksChanged;
}
 
Example 18
Source File: SurfaceRandomOffsetPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
private boolean allowed(Vector v) {
    BaseBlock block = pattern.apply(v);
    if (FaweCache.canPassThrough(block.getId(), block.getData())) {
        return false;
    }
    int x = v.getBlockX();
    int y = v.getBlockY();
    int z = v.getBlockZ();
    v.mutY(y + 1);
    if (canPassthrough(v)) {
        v.mutY(y);
        return true;
    }
    v.mutY(y - 1);
    if (canPassthrough(v)) {
        v.mutY(y);
        return true;
    }
    v.mutY(y);
    v.mutX(x + 1);
    if (canPassthrough(v)) {
        v.mutX(x);
        return true;
    }
    v.mutX(x - 1);
    if (canPassthrough(v)) {
        v.mutX(x);
        return true;
    }
    v.mutX(x);
    v.mutZ(z + 1);
    if (canPassthrough(v)) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z - 1);
    if (canPassthrough(v)) {
        v.mutZ(z);
        return true;
    }
    v.mutZ(z);
    return false;
}
 
Example 19
Source File: BlendBall.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 {
    final int outsetSize = (int) (size + 1);
    double brushSizeSquared = size * size;

    int tx = position.getBlockX();
    int ty = position.getBlockY();
    int tz = position.getBlockZ();

    Map<BaseBlock, Integer> frequency = Maps.newHashMap();

    int maxY = editSession.getMaximumPoint().getBlockY();

    for (int x = -outsetSize; x <= outsetSize; x++) {
        int x0 = x + tx;
        for (int y = -outsetSize; y <= outsetSize; y++) {
            int y0 = y + ty;
            for (int z = -outsetSize; z <= outsetSize; z++) {
                if (x * x + y * y + z * z >= brushSizeSquared) {
                    continue;
                }
                int z0 = z + tz;
                int highest = 1;
                BaseBlock currentState = editSession.getBlock(x0, y0, z0);
                BaseBlock highestState = currentState;
                frequency.clear();
                boolean tie = false;
                for (int ox = -1; ox <= 1; ox++) {
                    for (int oz = -1; oz <= 1; oz++) {
                        for (int oy = -1; oy <= 1; oy++) {
                            if (oy + y0 < 0 || oy + y0 > maxY) {
                                continue;
                            }
                            BaseBlock state = editSession.getBlock(x0 + ox, y0 + oy, z0 + oz);
                            Integer count = frequency.get(state);
                            if (count == null) {
                                count = 1;
                            } else {
                                count++;
                            }
                            if (count > highest) {
                                highest = count;
                                highestState = state;
                                tie = false;
                            } else if (count == highest) {
                                tie = true;
                            }
                            frequency.put(state, count);
                        }
                    }
                }
                if (!tie && currentState != highestState) {
                    editSession.setBlock(x0, y0, z0, highestState);
                }
            }
        }
    }
}
 
Example 20
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Set<Vector2D> getChunks() {
    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();
    final int maxX = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
    final int minX = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
    final int maxZ = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
    final int minZ = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
    final int size = (maxX - minX + 1) * (maxZ - minZ + 1);

    return new AbstractSet<Vector2D>() {
        @Override
        public Iterator<Vector2D> iterator() {
            return new Iterator<Vector2D>() {
                private MutableBlockVector2D pos = new MutableBlockVector2D().setComponents(maxX + 1, maxZ);

                @Override
                public boolean hasNext() {
                    return pos != null;
                }

                @Override
                public Vector2D next() {
                    Vector2D result = pos;
                    // calc next
                    pos.setComponents(pos.getX() - 1, pos.getZ());
                    if (pos.getX() <= minX) {
                        if (pos.getZ() == minZ) {
                            pos = null;
                        } else if (pos.getX() < minX) {
                            pos.setComponents(maxX, pos.getZ() - 1);
                        }
                    }
                    return result;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("This set is immutable.");
                }
            };
        }

        @Override
        public int size() {
            return size;
        }

        @Override
        public boolean contains(Object o) {
            if (o instanceof Vector2D) {
                Vector2D cv = (Vector2D) o;
                return cv.getX() >= minX && cv.getX() <= maxX && cv.getZ() >= minZ && cv.getZ() <= maxZ;
            } else {
                return false;
            }
        }
    };
}