Java Code Examples for com.sk89q.worldedit.session.ClipboardHolder#setTransform()

The following examples show how to use com.sk89q.worldedit.session.ClipboardHolder#setTransform() . 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: RandomFullClipboardPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
    AffineTransform transform = new AffineTransform();
    if (randomRotate) {
        transform = transform.rotateY(PseudoRandom.random.random(4) * 90);
        holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
    }
    if (randomFlip) {
        transform = transform.scale(new Vector(1, 0, 0).multiply(-2).add(1, 1, 1));
    }
    if (!transform.isIdentity()) {
        holder.setTransform(transform);
    }
    Clipboard clipboard = holder.getClipboard();
    Schematic schematic = new Schematic(clipboard);
    Transform newTransform = holder.getTransform();
    if (newTransform.isIdentity()) {
        schematic.paste(extent, setPosition, false);
    } else {
        schematic.paste(extent, worldData, setPosition, false, newTransform);
    }
    return true;
}
 
Example 2
Source File: SchemGen.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean spawn(PseudoRandom random, int x, int z) throws WorldEditException {
    mutable.mutX(x);
    mutable.mutZ(z);
    int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255);
    if (y == -1) return false;
    mutable.mutY(y);
    if (!mask.test(mutable)) {
        return false;
    }
    mutable.mutY(y + 1);
    ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
    if (randomRotate) {
        holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
    }
    Clipboard clipboard = holder.getClipboard();
    Schematic schematic = new Schematic(clipboard);
    Transform transform = holder.getTransform();
    if (transform.isIdentity()) {
        schematic.paste(extent, mutable, false);
    } else {
        schematic.paste(extent, worldData, mutable, false, transform);
    }
    mutable.mutY(y);
    return true;
}
 
Example 3
Source File: ClipboardCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"/rotate"},
        usage = "<y-axis> [<x-axis>] [<z-axis>]",
        desc = "Rotate the contents of the clipboard",
        help = "Non-destructively rotate the contents of the clipboard.\n" +
                "Angles are provided in degrees and a positive angle will result in a clockwise rotation. " +
                "Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n"
)
@CommandPermissions("worldedit.clipboard.rotate")
public void rotate(Player player, LocalSession session, Double yRotate, @Optional Double xRotate, @Optional Double zRotate) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    AffineTransform transform = new AffineTransform();
    transform = transform.rotateY(-(yRotate != null ? yRotate : 0));
    transform = transform.rotateX(-(xRotate != null ? xRotate : 0));
    transform = transform.rotateZ(-(zRotate != null ? zRotate : 0));
    holder.setTransform(transform.combine(holder.getTransform()));
    BBC.COMMAND_ROTATE.send(player);
    if (!FawePlayer.wrap(player).hasPermission("fawe.tips"))
        BBC.TIP_FLIP.or(BBC.TIP_DEFORM, BBC.TIP_TRANSFORM).send(player);
}
 
Example 4
Source File: ClipboardCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"/flip"},
        usage = "[<direction>]",
        desc = "Flip the contents of the clipboard",
        help =
                "Flips the contents of the clipboard across the point from which the copy was made.\n",
        min = 0,
        max = 1
)
@CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session,
                 @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();
    AffineTransform transform = new AffineTransform();
    transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1));
    holder.setTransform(transform.combine(holder.getTransform()));
    BBC.COMMAND_FLIPPED.send(player);
}
 
Example 5
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 6
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void addSchems(BufferedImage img, Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException {
    if (img.getWidth() != getWidth() || img.getHeight() != getLength())
        throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
    double doubleRarity = rarity / 100d;
    int index = 0;
    AffineTransform identity = new AffineTransform();
    LocalBlockVector2DSet placed = new LocalBlockVector2DSet();
    for (int z = 0; z < getLength(); z++) {
        mutable.mutZ(z);
        for (int x = 0; x < getWidth(); x++, index++) {
            int y = heights.getByte(index) & 0xFF;
            int height = img.getRGB(x, z) & 0xFF;
            if (height == 0 || PseudoRandom.random.nextInt(256) > height * doubleRarity) {
                continue;
            }
            mutable.mutX(x);
            mutable.mutY(y);
            if (!mask.test(mutable)) {
                continue;
            }
            if (placed.containsRadius(x, z, distance)) {
                continue;
            }
            placed.add(x, z);
            ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
            if (randomRotate) {
                int rotate = PseudoRandom.random.random(4) * 90;
                if (rotate != 0) {
                    holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
                } else {
                    holder.setTransform(identity);
                }
            }
            Clipboard clipboard = holder.getClipboard();
            Schematic schematic = new Schematic(clipboard);
            Transform transform = holder.getTransform();
            if (transform.isIdentity()) {
                schematic.paste(this, mutable, false);
            } else {
                schematic.paste(this, worldData, mutable, false, transform);
            }
            if (x + distance < getWidth()) {
                x += distance;
                index += distance;
            } else {
                break;
            }
        }
    }
}
 
Example 7
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void addSchems(Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException {
    int scaledRarity = (256 * rarity) / 100;
    int index = 0;
    AffineTransform identity = new AffineTransform();
    LocalBlockVector2DSet placed = new LocalBlockVector2DSet();
    for (int z = 0; z < getLength(); z++) {
        mutable.mutZ(z);
        for (int x = 0; x < getWidth(); x++, index++) {
            int y = heights.getByte(index) & 0xFF;
            if (PseudoRandom.random.nextInt(256) > scaledRarity) {
                continue;
            }
            mutable.mutX(x);
            mutable.mutY(y);
            if (!mask.test(mutable)) {
                continue;
            }
            if (placed.containsRadius(x, z, distance)) {
                continue;
            }
            mutable.mutY(y + 1);
            placed.add(x, z);
            ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
            if (randomRotate) {
                int rotate = PseudoRandom.random.random(4) * 90;
                if (rotate != 0) {
                    holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
                } else {
                    holder.setTransform(identity);
                }
            }
            Clipboard clipboard = holder.getClipboard();
            Schematic schematic = new Schematic(clipboard);
            Transform transform = holder.getTransform();
            if (transform.isIdentity()) {
                schematic.paste(this, mutable, false);
            } else {
                schematic.paste(this, worldData, mutable, false, transform);
            }
            if (x + distance < getWidth()) {
                x += distance;
                index += distance;
            } else {
                break;
            }
        }
    }
}