Java Code Examples for com.sk89q.worldedit.extent.clipboard.Clipboard#getRegion()

The following examples show how to use com.sk89q.worldedit.extent.clipboard.Clipboard#getRegion() . 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: DefaultFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	Clipboard clipboard = floor.getClipboard();
	
	Region region = clipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(clipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
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 3
Source File: ClipboardRemapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void apply(Clipboard clipboard) throws WorldEditException {
    if (clipboard instanceof BlockArrayClipboard) {
        BlockArrayClipboard bac = (BlockArrayClipboard) clipboard;
        bac.IMP = new RemappedClipboard(bac.IMP, this);
    } else {
        Region region = clipboard.getRegion();
        for (BlockVector pos : region) {
            BaseBlock block = clipboard.getBlock(pos);
            BaseBlock newBlock = remap(block);
            if (block != newBlock) {
                clipboard.setBlock(pos, newBlock);
            }
        }
    }
}
 
Example 4
Source File: TextureUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static TextureUtil fromClipboard(Clipboard clipboard) throws FileNotFoundException {
    boolean[] ids = new boolean[Character.MAX_VALUE + 1];
    for (Vector pt : clipboard.getRegion()) {
        ids[clipboard.getBlock(pt).getCombined()] = true;
    }
    HashSet<BaseBlock> blocks = new HashSet<>();
    for (int combined = 0; combined < ids.length; combined++) {
        if (ids[combined]) blocks.add(FaweCache.CACHE_BLOCK[combined]);
    }
    return fromBlocks(blocks);
}
 
Example 5
Source File: FAWEFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
    Clipboard clipboard = floor.getClipboard();
    Schematic faweSchematic = new Schematic(clipboard);

    Region region = clipboard.getRegion();
    World world = region.getWorld();
    if (world == null) {
        throw new IllegalStateException("World of floor " + floor.getName() + " is null!");
    }

    faweSchematic.paste(world, region.getMinimumPoint(), false, false, (Transform) null);
}
 
Example 6
Source File: CopyPastaBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void build(final EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    FawePlayer fp = editSession.getPlayer();
    ClipboardHolder clipboard = session.getExistingClipboard();
    if (clipboard == null) {
        if (editSession.getExtent() instanceof VisualExtent) {
            return;
        }
        Mask mask = editSession.getMask();
        if (mask == null) {
            mask = Masks.alwaysTrue();
        }
        final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
        final int size2 = (int) (size * size);
        final int minY = position.getBlockY();
        mask = new AbstractDelegateMask(mask) {
            @Override
            public boolean test(Vector vector) {
                if (super.test(vector) && vector.getBlockY() >= minY) {
                    BaseBlock block = editSession.getLazyBlock(vector);
                    if (block.getId() != 0) {
                        builder.add(vector, EditSession.nullBlock, block);
                        return true;
                    }
                }
                return false;
            }
        };
        // Add origin
        mask.test(position);
        RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession);
        visitor.visit(position);
        Operations.completeBlindly(visitor);
        // Build the clipboard
        Clipboard newClipboard = builder.build();
        newClipboard.setOrigin(position);
        ClipboardHolder holder = new ClipboardHolder(newClipboard, editSession.getWorld().getWorldData());
        session.setClipboard(holder);
        int blocks = builder.size();
        BBC.COMMAND_COPY.send(fp, blocks);
        return;
    } else {
        AffineTransform transform = null;
        if (randomRotate) {
            if (transform == null) transform = new AffineTransform();
            int rotate = 90 * PseudoRandom.random.nextInt(4);
            transform = transform.rotateY(rotate);
        }
        if (autoRotate) {
            if (transform == null) transform = new AffineTransform();
            Location loc = editSession.getPlayer().getPlayer().getLocation();
            float yaw = loc.getYaw();
            float pitch = loc.getPitch();
            transform = transform.rotateY((-yaw) % 360);
            transform = transform.rotateX(pitch - 90);
        }
        if (transform != null && !transform.isIdentity()) {
            clipboard.setTransform(transform);
        }
        Clipboard faweClip = clipboard.getClipboard();
        Region region = faweClip.getRegion();

        Operation operation = clipboard
                .createPaste(editSession, editSession.getWorldData())
                .to(position.add(0, 1, 0))
                .ignoreAirBlocks(true)
                .build();
        Operations.completeLegacy(operation);
        editSession.flushQueue();
    }
}
 
Example 7
Source File: ClipboardSpline.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor with position-correction. Use this constructor for an interpolation implementation that needs position-correction.
 * <p>
 * Some interpolation implementations calculate the position on the curve (used by {@link #pastePosition(double)})
 * based on an equidistant distribution of the nodes on the curve. For example: on a spline with 5 nodes position 0.0 would refer
 * to the first node, 0.25 to the second, 0.5 to the third, ... .<br>
 * By providing this method with the amount of nodes used by the interpolation implementation the distribution of the
 * nodes is converted to a proportional distribution based on the length between two adjacent nodes calculated by {@link Interpolation#arcLength(double, double)}.<br>
 * This means that the distance between two positions used to paste the clipboard (e.g. 0.75 - 0.5 = 0.25) on the curve
 * will always amount to that part of the length (e.g. 40 units) of the curve. In this example it would amount to
 * 0.25 * 40 = 10 units of curve length between these two positions.
 * <p>
 * Be advised that currently subsequent changes to the interpolation parameters may not be supported.
 * @param editSession     The EditSession which will be used when pasting the clipboard content
 * @param clipboardHolder The clipboard that will be pasted along the spline
 * @param interpolation   An implementation of the interpolation algorithm used to calculate the curve
 * @param nodeCount       The number of nodes provided to the interpolation object
 */
public ClipboardSpline(EditSession editSession, ClipboardHolder clipboardHolder, Interpolation interpolation, Transform transform, int nodeCount) {
    super(editSession, interpolation, nodeCount);
    this.clipboardHolder = clipboardHolder;

    this.originalTransform = clipboardHolder.getTransform();
    Clipboard clipboard = clipboardHolder.getClipboard();
    this.originalOrigin = clipboard.getOrigin();

    Region region = clipboard.getRegion();
    Vector origin = clipboard.getOrigin();
    center = region.getCenter().setY(origin.getY() - 1);
    this.centerOffset = center.subtract(center.round());
    this.center = center.subtract(centerOffset);
    this.transform = transform;
    this.buffer = new LocalBlockVectorSet();
}
 
Example 8
Source File: CFICommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"paletteblocks", "colorpaletterblocks", "setcolorpaletteblocks"},
        usage = "<blocks|#clipboard|*>",
        desc = "Set the blocks used for coloring",
        help = "Allow only specific blocks to be used for coloring\n" +
                "`blocks` is a list of blocks e.g. stone,bedrock,wool\n" +
                "`#clipboard` will only use the blocks present in your clipboard."
)
@CommandPermissions("worldedit.anvil.cfi")
public void paletteblocks(FawePlayer fp, Player player, LocalSession session, @Optional String arg) throws ParameterException, EmptyClipboardException, InputParseException, FileNotFoundException {
    if (arg == null) {
        msg("What blocks do you want to color with?").newline()
        .text("&7[&aAll&7]").cmdTip(alias() + " PaletteBlocks *").text(" - All available blocks")
        .newline()
        .text("&7[&aClipboard&7]").cmdTip(alias() + " PaletteBlocks #clipboard").text(" - The blocks in your clipboard")
        .newline()
        .text("&7[&aList&7]").suggestTip(alias() + " PaletteBlocks stone,gravel").text(" - A comma separated list of blocks")
        .newline()
        .text("&7[&aComplexity&7]").cmdTip(alias() + " Complexity").text(" - Block textures within a complexity range")
        .newline()
        .text("&8< &7[&aBack&7]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "coloring"))
        .send(fp);
        return;
    }
    HeightMapMCAGenerator generator = assertSettings(fp).getGenerator();
    ParserContext context = new ParserContext();
    context.setActor(fp.getPlayer());
    context.setWorld(fp.getWorld());
    context.setSession(fp.getSession());
    context.setExtent(generator);
    Request.request().setExtent(generator);

    Set<BaseBlock> blocks;
    switch (arg.toLowerCase()) {
        case "true":
        case "*": {
            generator.setTextureUtil(Fawe.get().getTextureUtil());
            return;
        }
        case "#clipboard": {
            ClipboardHolder holder = fp.getSession().getClipboard();
            Clipboard clipboard = holder.getClipboard();
            boolean[] ids = new boolean[Character.MAX_VALUE + 1];
            for (Vector pt : clipboard.getRegion()) {
                ids[clipboard.getBlock(pt).getCombined()] = true;
            }
            blocks = new HashSet<>();
            for (int combined = 0; combined < ids.length; combined++) {
                if (ids[combined]) blocks.add(FaweCache.CACHE_BLOCK[combined]);
            }
            break;
        }
        default: {
            blocks = new HashSet<>();
            BlockPattern pattern = new BlockPattern(new BaseBlock(BlockID.AIR));
            PatternExtent extent = new PatternExtent(pattern);

            ParserContext parserContext = new ParserContext();
            parserContext.setActor(player);
            parserContext.setWorld(player.getWorld());
            parserContext.setSession(session);
            parserContext.setExtent(extent);
            Request.request().setExtent(extent);
            Mask mask = worldEdit.getMaskFactory().parseFromInput(arg, parserContext);
            TextureUtil tu = Fawe.get().getTextureUtil();
            for (int combinedId : tu.getValidBlockIds()) {
                BaseBlock block = FaweCache.CACHE_BLOCK[combinedId];
                pattern.setBlock(block);
                if (mask.test(Vector.ZERO)) blocks.add(block);
            }
            break;
        }
    }
    generator.setTextureUtil(new FilteredTextureUtil(Fawe.get().getTextureUtil(), blocks));
    coloring(fp);
}