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

The following examples show how to use com.sk89q.worldedit.Vector#getBlockX() . 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: 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 2
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 3
Source File: PlayerWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
    final Vector pos = getBlockIn();
    final int x = pos.getBlockX();
    final int initialY = Math.max(0, pos.getBlockY());
    int y = Math.max(0, pos.getBlockY() + 1);
    final int z = pos.getBlockZ();
    final int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance);
    final World world = getPosition().getWorld();

    while (y <= world.getMaxY() + 2) {
        if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
            break; // Hit something
        } else if (y > maxY + 1) {
            break;
        } else if (y == maxY + 1) {
            floatAt(x, y - 1, z, alwaysGlass);
            return true;
        }

        ++y;
    }

    return false;
}
 
Example 4
Source File: RadiusMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean test(Vector to) {
    if (pos == null) {
        pos = new MutableBlockVector(to);
    }
    int dx = pos.getBlockX() - to.getBlockX();
    int d = dx * dx;
    if (d > maxSqr) {
        return false;
    }
    int dz = pos.getBlockZ() - to.getBlockZ();
    d += dz * dz;
    if (d > maxSqr) {
        return false;
    }
    int dy = pos.getBlockY() - to.getBlockY();
    d += dy * dy;
    if (d < minSqr || d > maxSqr) {
        return false;
    }
    return true;
}
 
Example 5
Source File: MemoryOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 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[1 + (volume >> BLOCK_SHIFT)][];
        datas = new byte[1 + (volume >> BLOCK_SHIFT)][];
        lastAddI = -1;
        lastIdsI = -1;
        lastDatasI = -1;
        saveIds = false;
        saveAdd = false;
        saveDatas = false;
    }
}
 
Example 6
Source File: CuboidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Clamps the cuboid according to boundaries of the world.
 */
protected void recalculate() {
    if (pos1 == null || pos2 == null) {
        return;
    }
    pos1 = pos1.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY());
    pos2 = pos2.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY());
    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();
    minX = min.getBlockX();
    minY = min.getBlockY();
    minZ = min.getBlockZ();
    maxX = max.getBlockX();
    maxY = max.getBlockY();
    maxZ = max.getBlockZ();
}
 
Example 7
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 8
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static boolean setBlock(Level level, Vector pos, BaseBlock block) {
    int x = pos.getBlockX();
    int y = pos.getBlockY();
    int z = pos.getBlockZ();
    level.setBlockIdAt(x, y, z, block.getId());
    level.setBlockDataAt(x, y, z, block.getData());
    return true;

}
 
Example 9
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 10
Source File: DFSVisitor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void visit(final Vector pos) {
    Node node = new Node(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
    if (!this.hashQueue.contains(node)) {
        isVisitable(pos, pos); // Ignore this, just to initialize mask on this point
        queue.addFirst(new NodePair(null, node, 0));
        hashQueue.add(node);
    }
}
 
Example 11
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 12
Source File: AbstractPlayerActor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
    Vector pos = getBlockIn();
    int x = pos.getBlockX();
    int initialY = Math.max(0, pos.getBlockY());
    int y = Math.max(0, pos.getBlockY() + 2);
    int z = pos.getBlockZ();
    World world = getPosition().getWorld();

    // No free space above
    if (world.getBlockType(new Vector(x, y, z)) != 0) {
        return false;
    }

    while (y <= world.getMaxY()) {
        // Found a ceiling!
        if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
            int platformY = Math.max(initialY, y - 3 - clearance);
            floatAt(x, platformY + 1, z, alwaysGlass);
            return true;
        }

        ++y;
    }

    return false;
}
 
Example 13
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 14
Source File: EllipsoidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the radii.
 *
 * @param radius the radius
 */
public void setRadius(Vector radius) {
    this.radius = new MutableBlockVector(radius.add(0.5, 0.5, 0.5));
    radiusSqr = new MutableBlockVector(radius.multiply(radius));
    radiusLengthSqr = radiusSqr.getBlockX();
    if (radius.getBlockY() == radius.getBlockX() && radius.getBlockX() == radius.getBlockZ()) {
        this.sphere = true;
    } else {
        this.sphere = false;
    }
}
 
Example 15
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getBlock(Vector position) {
    if (region.contains(position)) {
        int x = position.getBlockX() - mx;
        int y = position.getBlockY() - my;
        int z = position.getBlockZ() - mz;
        return IMP.getBlock(x, y, z);
    }
    return EditSession.nullBlock;
}
 
Example 16
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 17
Source File: ScalableHeightMap.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static ScalableHeightMap fromClipboard(Clipboard clipboard) {
    Vector dim = clipboard.getDimensions();
    byte[][] heightArray = new byte[dim.getBlockX()][dim.getBlockZ()];
    int minX = clipboard.getMinimumPoint().getBlockX();
    int minZ = clipboard.getMinimumPoint().getBlockZ();
    int minY = clipboard.getMinimumPoint().getBlockY();
    int maxY = clipboard.getMaximumPoint().getBlockY();
    int clipHeight = maxY - minY + 1;
    HashSet<IntegerPair> visited = new HashSet<>();
    for (Vector pos : clipboard.getRegion()) {
        IntegerPair pair = new IntegerPair(pos.getBlockX(), pos.getBlockZ());
        if (visited.contains(pair)) {
            continue;
        }
        visited.add(pair);
        int xx = pos.getBlockX();
        int zz = pos.getBlockZ();
        int highestY = minY;
        for (int y = minY; y <= maxY; y++) {
            pos.mutY(y);
            BaseBlock block = clipboard.getBlock(pos);
            if (block.getId() != 0) {
                highestY = y + 1;
            }
        }
        int pointHeight = Math.min(255, (256 * (highestY - minY)) / clipHeight);
        int x = xx - minX;
        int z = zz - minZ;
        heightArray[x][z] = (byte) pointHeight;
    }
    return new ArrayHeightMap(heightArray);
}
 
Example 18
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 19
Source File: StencilBrush.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 sizeDouble) throws MaxChangedBlocksException {
    final int cx = position.getBlockX();
    final int cy = position.getBlockY();
    final int cz = position.getBlockZ();
    int size = (int) sizeDouble;
    int size2 = (int) (sizeDouble * sizeDouble);
    int maxY = editSession.getMaxY();
    int add;
    if (yscale < 0) {
        add = maxY;
    } else {
        add = 0;
    }
    double scale = (yscale / sizeDouble) * (maxY + 1);
    final HeightMap map = getHeightMap();
    map.setSize(size);
    int cutoff = onlyWhite ? maxY : 0;
    final SolidBlockMask solid = new SolidBlockMask(editSession);
    final AdjacentAnyMask adjacent = new AdjacentAnyMask(Masks.negate(solid));


    Player player = editSession.getPlayer().getPlayer();
    Vector pos = player.getPosition();



    Location loc = editSession.getPlayer().getPlayer().getLocation();
    float yaw = loc.getYaw();
    float pitch = loc.getPitch();
    AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse();


    RecursiveVisitor visitor = new RecursiveVisitor(new Mask() {
        private final MutableBlockVector mutable = new MutableBlockVector();
        @Override
        public boolean test(Vector vector) {
            if (solid.test(vector)) {
                int dx = vector.getBlockX() - cx;
                int dy = vector.getBlockY() - cy;
                int dz = vector.getBlockZ() - cz;

                Vector srcPos = transform.apply(mutable.setComponents(dx, dy, dz));
                dx = srcPos.getBlockX();
                dz = srcPos.getBlockZ();

                int distance = dx * dx + dz * dz;
                if (distance > size2 || Math.abs(dx) > 256 || Math.abs(dz) > 256) return false;

                double raise = map.getHeight(dx, dz);
                int val = (int) Math.ceil(raise * scale) + add;
                if (val < cutoff) {
                    return true;
                }
                if (val >= 255 || PseudoRandom.random.random(maxY) < val) {
                    editSession.setBlock(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), pattern);
                }
                return true;
            }
            return false;
        }
    }, vector -> true, Integer.MAX_VALUE, editSession);
    visitor.setDirections(Arrays.asList(visitor.DIAGONAL_DIRECTIONS));
    visitor.visit(position);
    Operations.completeBlindly(visitor);
}
 
Example 20
Source File: SolidPlaneMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean test(Vector vector) {
    switch (mode) {
        case -1:
            if (!super.test(vector)) {
                return false;
            }
            originX = vector.getBlockX();
            originY = vector.getBlockY();
            originZ = vector.getBlockZ();
            mode = 0;
            Extent extent = getExtent();
            if (extent.getBlock(mutable.setComponents(originX - 1, originY, originZ)).getId() != 0 && extent.getBlock(mutable.setComponents(originX + 1, originY, originZ)).getId() != 0) {
                mode &= 1;
            }
            if (extent.getBlock(mutable.setComponents(originX, originY, originZ - 1)).getId() != 0 && extent.getBlock(mutable.setComponents(originX, originY, originZ + 1)).getId() != 0) {
                mode &= 4;
            }
            if (extent.getBlock(mutable.setComponents(originX, originY - 1, originZ + 1)).getId() != 0 && extent.getBlock(mutable.setComponents(originX, originY + 1, originZ + 1)).getId() != 0) {
                mode &= 2;
            }
            if (Integer.bitCount(mode) >= 3) {
                return false;
            }
        case 0:
        case 1:
        case 2:
        case 4:
            if (!super.test(vector)) {
                return false;
            }
            int original = mode;
            if (originX != vector.getBlockX()) {
                mode &= 1;
            }
            if (originY != vector.getBlockY()) {
                mode &= 2;
            }
            if (originZ != vector.getBlockZ()) {
                mode &= 4;
            }
            if (Integer.bitCount(mode) >= 3) {
                mode = original;
                return false;
            }
        default:
            if (originX != vector.getBlockX() && (mode & 1) == 0) {
                return false;
            }
            if (originZ != vector.getBlockZ() && (mode & 4) == 0) {
                return false;
            }
            if (originY != vector.getBlockY() && (mode & 2) == 0) {
                return false;
            }
            return super.test(vector);

    }
}