Java Code Examples for com.sk89q.worldedit.regions.Region#getMaximumPoint()

The following examples show how to use com.sk89q.worldedit.regions.Region#getMaximumPoint() . 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: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"removelayers"},
        usage = "<id>",
        desc = "Removes matching chunk layers",
        help = "Remove if all the selected layers in a chunk match the provided id"
)
@CommandPermissions("worldedit.anvil.removelayer")
public void removeLayers(Player player, EditSession editSession, @Selection Region selection, int id) throws WorldEditException {
    Vector min = selection.getMinimumPoint();
    Vector max = selection.getMaximumPoint();
    int minY = min.getBlockY();
    int maxY = max.getBlockY();
    RemoveLayerFilter filter = new RemoveLayerFilter(minY, maxY, id);
    MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
    if (result != null) {
        player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
    }
}
 
Example 2
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 3
Source File: FaweAPI.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fix the lighting in a selection<br>
 * - First removes all lighting, then relights
 * - Relights in parallel (if enabled) for best performance<br>
 * - Also resends chunks<br>
 *
 * @param world
 * @param selection (assumes cuboid)
 * @return
 */
public static int fixLighting(World world, Region selection, @Nullable FaweQueue queue, final FaweQueue.RelightMode mode) {
    final Vector bot = selection.getMinimumPoint();
    final Vector top = selection.getMaximumPoint();

    final int minX = bot.getBlockX() >> 4;
    final int minZ = bot.getBlockZ() >> 4;

    final int maxX = top.getBlockX() >> 4;
    final int maxZ = top.getBlockZ() >> 4;

    int count = 0;
    if (queue == null) {
        queue = SetQueue.IMP.getNewQueue(world, true, false);
    }
    // Remove existing lighting first
    if (queue instanceof NMSMappedFaweQueue) {
        final NMSMappedFaweQueue nmsQueue = (NMSMappedFaweQueue) queue;
        NMSRelighter relighter = new NMSRelighter(nmsQueue);
        for (int x = minX; x <= maxX; x++) {
            for (int z = minZ; z <= maxZ; z++) {
                relighter.addChunk(x, z, null, 65535);
                count++;
            }
        }
        if (mode != FaweQueue.RelightMode.NONE) {
            boolean sky = nmsQueue.hasSky();
            if (sky) {
                relighter.fixSkyLighting();
            }
            relighter.fixBlockLighting();
        } else {
            relighter.removeLighting();
        }
        relighter.sendChunks();
    }
    return count;
}
 
Example 4
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 5
Source File: CylinderRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector from the given one.
 *
 * @param oldSelector the old selector
 */
public CylinderRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());

    if (oldSelector instanceof CylinderRegionSelector) {
        final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;

        region = new CylinderRegion(cylSelector.region);
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        Vector pos1 = oldRegion.getMinimumPoint();
        Vector pos2 = oldRegion.getMaximumPoint();

        Vector center = pos1.add(pos2).divide(2).floor();
        region.setCenter(center.toVector2D());
        region.setRadius(pos2.toVector2D().subtract(center.toVector2D()));

        region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
        region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
    }
}
 
Example 6
Source File: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"clear", "unset"},
        desc = "Clear the chunks in a selection (delete without defrag)"
)
@CommandPermissions("worldedit.anvil.clear")
public void unset(Player player, EditSession editSession, @Selection Region selection) throws WorldEditException {
    Vector bot = selection.getMinimumPoint();
    Vector top = selection.getMaximumPoint();
    RegionWrapper region = new RegionWrapper(bot, top);

    MCAFilterCounter filter = new MCAFilterCounter() {
        @Override
        public MCAFile applyFile(MCAFile file) {
            int X = file.getX();
            int Z = file.getZ();
            int bcx = X << 5;
            int bcz = Z << 5;
            int bx = X << 9;
            int bz = Z << 9;
            if (region.isIn(bx, bz) && region.isIn(bx + 511, bz + 511)) {
                file.setDeleted(true);
                get().add(512 * 512 * 256);
            } else if (region.isInMCA(X, Z)) {
                file.init();
                final byte[] empty = new byte[4];
                RandomAccessFile raf = file.getRandomAccessFile();
                file.forEachChunk(new RunnableVal4<Integer, Integer, Integer, Integer>() {
                    @Override
                    public void run(Integer cx, Integer cz, Integer offset, Integer size) {
                        if (region.isInChunk(bcx + cx, bcz + cz)) {
                            int index = ((cx & 31) << 2) + ((cz & 31) << 7);
                            try {
                                raf.seek(index);
                                raf.write(empty);
                                get().add(16 * 16 * 256);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
                file.clear();
            }
            return null;
        }
    };
    MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
    if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
}
 
Example 7
Source File: HeightMap.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public HeightMap(EditSession session, Region region, boolean naturalOnly, boolean layers) {
    checkNotNull(session);
    checkNotNull(region);

    this.session = session;
    this.region = region;

    this.width = region.getWidth();
    this.height = region.getLength();

    this.layers = layers;

    int minX = region.getMinimumPoint().getBlockX();
    int minY = region.getMinimumPoint().getBlockY();
    int minZ = region.getMinimumPoint().getBlockZ();
    int maxY = region.getMaximumPoint().getBlockY();

    data = new int[width * height];
    invalid = new boolean[data.length];

    if (layers) {
        Vector min = region.getMinimumPoint();
        Vector max = region.getMaximumPoint();
        int bx = min.getBlockX();
        int bz = min.getBlockZ();
        Iterable<Vector2D> flat = Regions.asFlatRegion(region).asFlatRegion();
        Iterator<Vector2D> iter = new Fast2DIterator(flat, session).iterator();
        int layer = 0;
        MutableBlockVector mutable = new MutableBlockVector();
        while (iter.hasNext()) {
            Vector2D pos = iter.next();
            int x = pos.getBlockX();
            int z = pos.getBlockZ();
            layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY);
            data[(z - bz) * width + (x - bx)] = layer;
        }
    } else {
        // Store current heightmap data
        int index = 0;
        if (naturalOnly) {
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    data[index] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY, naturalOnly);
                }
            }
        } else {
            int yTmp = 255;
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
                    switch (yTmp) {
                        case Integer.MIN_VALUE:
                            yTmp = minY;
                            invalid[index] = true;
                            break;
                        case Integer.MAX_VALUE:
                            yTmp = maxY;
                            invalid[index] = true;
                            break;
                    }
                    data[index] = yTmp;
                }
            }
        }
    }
}
 
Example 8
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 9
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of regions covering the borders of the original region.
 * <b>Note:</b> complements the #getInnerChunks
 *
 * <pre>
 *     ^
 *     |           +---+---+---+---+---+---+
 *     |           |   |   |   |   |   |   |
 *     |           |   |   |   |   |   |   |
 *     |           +---+---+---+---+---+---+
 *     |         l |   | D=======C |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         k +---+-I-R---Q-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         j +---+-I-O---P-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |         i |   | A=======B |   |   |
 *     |           +---+---+---+---+---+---+
 *     |                 a b   c d
 *     +----------------------------------------->
 *
 * Points:
 *     A = (a,i)
 *     B = (d,i)
 *     C = (d,l)
 *     D = (a,l)
 *
 *     M(x) = X mod 16, i.e. Mc = C mod 16.
 *
 * Borders:
 *     O = A + 16 - Ma   | A > 0
 *       = A - Ma        | A <= 0
 *
 *     Q = C - Mc - 1    | C > 0 && Mc != 15
 *       = C + Mc - 16   | C < 0 && Mc != -1
 * </pre>
 */
public static Set<Region> getBorderRegions(Region region) {
    Set<Region> borders = new HashSet<>();
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    int minY = min.getBlockY();
    int maxY = max.getBlockY();
    int minX = min.getBlockX();
    int maxX = max.getBlockX();
    int minZ = min.getBlockZ();
    int maxZ = max.getBlockZ();

    int minModX = minX % 16;
    int maxModX = maxX % 16;
    int minModZ = minZ % 16;
    int maxModZ = maxZ % 16;
    // Negative values are aligned differently than positive values
    int minChunkX = minModX > 0 ? minX + 16 - minModX : minX - minModX;
    int maxChunkX = maxModX >= 0 && maxModX != 15 ? maxX - maxModX - 1 : maxModX < 0 && maxModX != -1 ? maxX - 16 + maxModX : maxX;
    int minChunkZ = minModZ > 0 ? minZ + 16 - minModZ : minZ - minModZ;
    int maxChunkZ = maxModZ >= 0 && maxModZ != 15 ? maxZ - maxModZ - 1 : maxModZ < 0 && maxModZ != -1 ? maxZ - 16 + maxModZ : maxZ;
    // min < minChunk < maxChunk < max
    if (minModX != 0) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minX, minY, minZ),
                BlockVector3.at(minChunkX - 1, maxY, maxZ)));
    }
    if (maxModZ != 15 && maxModZ != -1) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minChunkX, minY, maxChunkZ + 1),
                BlockVector3.at(maxChunkX, maxY, maxZ)));
    }
    if (maxModX != 15 && maxModX != -1) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(maxChunkX + 1, minY, minZ),
                BlockVector3.at(maxX, maxY, maxZ)));
    }
    if (minModZ != 0) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minChunkX, minY, minZ),
                BlockVector3.at(maxChunkX, maxY, minChunkZ - 1)));
    }
    return borders;
}
 
Example 10
Source File: RegionCommand.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private void showRegion(Player player, Region region) {
    int y = player.getLocation().getBlockY();
    BlockVector3 minP = region.getMinimumPoint();
    BlockVector3 maxP = region.getMaximumPoint();
    showRegion(player, y, minP, maxP);
}