Search in sources :

Example 1 with NullRegionFunction

use of com.fastasyncworldedit.core.function.NullRegionFunction in project FastAsyncWorldEdit by IntellectualSites.

the class CopyPastaBrush method build.

@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
    Actor actor = editSession.getActor();
    if (!(actor instanceof Player)) {
        throw FaweCache.PLAYER_ONLY;
    }
    Player player = (Player) actor;
    ClipboardHolder clipboard = session.getExistingClipboard();
    if (clipboard == null) {
        Mask mask = editSession.getMask();
        if (mask == null) {
            mask = Masks.alwaysTrue();
        }
        final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
        final int minY = position.getBlockY();
        mask = new AbstractDelegateMask(mask) {

            @Override
            public boolean test(BlockVector3 vector) {
                if (super.test(vector) && vector.getBlockY() >= minY) {
                    BaseBlock block = editSession.getFullBlock(vector);
                    if (!block.getBlockType().getMaterial().isAir()) {
                        builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block);
                        return true;
                    }
                }
                return false;
            }
        };
        // Add origin
        mask.test(position);
        RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession.getMinY(), editSession.getMaxY());
        visitor.visit(position);
        Operations.completeBlindly(visitor);
        // Build the clipboard
        Clipboard newClipboard = builder.build();
        newClipboard.setOrigin(position);
        ClipboardHolder holder = new ClipboardHolder(newClipboard);
        session.setClipboard(holder);
        int blocks = builder.size();
        player.print(Caption.of("fawe.worldedit.copy.command.copy", blocks));
    } else {
        AffineTransform transform = null;
        if (randomRotate) {
            transform = new AffineTransform();
            int rotate = 90 * ThreadLocalRandom.current().nextInt(4);
            transform = transform.rotateY(rotate);
        }
        if (autoRotate) {
            if (transform == null) {
                transform = new AffineTransform();
            }
            Location loc = player.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);
        }
        Operation operation = clipboard.createPaste(editSession).to(position.add(0, 1, 0)).ignoreAirBlocks(true).build();
        Operations.completeLegacy(operation);
        editSession.flushQueue();
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) Operation(com.sk89q.worldedit.function.operation.Operation) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) NullRegionFunction(com.fastasyncworldedit.core.function.NullRegionFunction) Actor(com.sk89q.worldedit.extension.platform.Actor) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) ResizableClipboardBuilder(com.fastasyncworldedit.core.extent.clipboard.ResizableClipboardBuilder) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) Location(com.sk89q.worldedit.util.Location)

Aggregations

ResizableClipboardBuilder (com.fastasyncworldedit.core.extent.clipboard.ResizableClipboardBuilder)1 NullRegionFunction (com.fastasyncworldedit.core.function.NullRegionFunction)1 AbstractDelegateMask (com.fastasyncworldedit.core.function.mask.AbstractDelegateMask)1 Player (com.sk89q.worldedit.entity.Player)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 Location (com.sk89q.worldedit.util.Location)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1