Search in sources :

Example 1 with Transform

use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardSpline method pasteBlocks.

@Override
protected int pasteBlocks(BlockVector3 target, Vector3 offset, double angle) throws MaxChangedBlocksException {
    RoundedTransform transform = new RoundedTransform(new AffineTransform().translate(offset).rotateY(angle));
    if (!this.transform.isIdentity()) {
        transform = transform.combine(this.transform);
    }
    if (!originalTransform.isIdentity()) {
        transform = transform.combine(originalTransform);
    }
    // Pasting
    Clipboard clipboard = clipboardHolder.getClipboard();
    clipboard.setOrigin(center.subtract(centerOffset).round());
    clipboardHolder.setTransform(transform);
    BlockVector3 functionOffset = target.subtract(clipboard.getOrigin());
    final int offX = functionOffset.getBlockX();
    final int offY = functionOffset.getBlockY();
    final int offZ = functionOffset.getBlockZ();
    Operation operation = clipboardHolder.createPaste(editSession).to(target).ignoreAirBlocks(true).filter(v -> buffer.add(v.getBlockX() + offX, v.getBlockY() + offY, v.getBlockZ() + offZ)).build();
    Operations.completeLegacy(operation);
    // Cleanup
    clipboardHolder.setTransform(originalTransform);
    clipboard.setOrigin(originalOrigin);
    return operation instanceof ForwardExtentCopy ? ((ForwardExtentCopy) operation).getAffected() : 0;
}
Also used : EditSession(com.sk89q.worldedit.EditSession) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RoundedTransform(com.fastasyncworldedit.core.math.transform.RoundedTransform) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Interpolation(com.sk89q.worldedit.math.interpolation.Interpolation) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) Transform(com.sk89q.worldedit.math.transform.Transform) Vector3(com.sk89q.worldedit.math.Vector3) Operations(com.sk89q.worldedit.function.operation.Operations) Operation(com.sk89q.worldedit.function.operation.Operation) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) RoundedTransform(com.fastasyncworldedit.core.math.transform.RoundedTransform) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Operation(com.sk89q.worldedit.function.operation.Operation) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy)

Example 2 with Transform

use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.

the class SchemGen method spawn.

@Override
public boolean spawn(Random random, int x, int z) throws WorldEditException {
    mutable.mutX(x);
    mutable.mutZ(z);
    int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), this.extent.getMinY(), this.extent.getMaxY(), Integer.MIN_VALUE, Integer.MAX_VALUE);
    if (y == Integer.MIN_VALUE || y == Integer.MAX_VALUE) {
        return false;
    }
    mutable.mutY(y);
    if (!mask.test(mutable)) {
        return false;
    }
    mutable.mutY(y + 1);
    ClipboardHolder holder = clipboards.get(ThreadLocalRandom.current().nextInt(clipboards.size()));
    if (randomRotate) {
        holder.setTransform(new AffineTransform().rotateY(ThreadLocalRandom.current().nextInt(4) * 90));
    }
    Clipboard clipboard = holder.getClipboard();
    Transform transform = holder.getTransform();
    if (transform.isIdentity()) {
        clipboard.paste(extent, mutable, false);
    } else {
        clipboard.paste(extent, mutable, false, transform);
    }
    mutable.mutY(y);
    return true;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Transform(com.sk89q.worldedit.math.transform.Transform) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform)

Example 3 with Transform

use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.

the class FlattenedClipboardTransform method getTransformedRegion.

/**
 * Get the transformed region.
 *
 * @return the transformed region
 */
public Region getTransformedRegion() {
    Region region = original.getRegion();
    Vector3 minimum = region.getMinimumPoint().toVector3();
    Vector3 maximum = region.getMaximumPoint().toVector3();
    Transform transformAround = new CombinedTransform(new AffineTransform().translate(original.getOrigin().multiply(-1)), transform, new AffineTransform().translate(original.getOrigin()));
    Vector3[] corners = new Vector3[] { minimum, maximum, minimum.withX(maximum.getX()), minimum.withY(maximum.getY()), minimum.withZ(maximum.getZ()), maximum.withX(minimum.getX()), maximum.withY(minimum.getY()), maximum.withZ(minimum.getZ()) };
    for (int i = 0; i < corners.length; i++) {
        corners[i] = transformAround.apply(corners[i]);
    }
    Vector3 newMinimum = corners[0];
    Vector3 newMaximum = corners[0];
    for (int i = 1; i < corners.length; i++) {
        newMinimum = newMinimum.getMinimum(corners[i]);
        newMaximum = newMaximum.getMaximum(corners[i]);
    }
    // After transformation, the points may not really sit on a block,
    // so we should expand the region for edge cases
    newMinimum = newMinimum.floor();
    newMaximum = newMaximum.ceil();
    return new CuboidRegion(newMinimum.toBlockPoint(), newMaximum.toBlockPoint());
}
Also used : CombinedTransform(com.sk89q.worldedit.math.transform.CombinedTransform) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Vector3(com.sk89q.worldedit.math.Vector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Transform(com.sk89q.worldedit.math.transform.Transform) CombinedTransform(com.sk89q.worldedit.math.transform.CombinedTransform) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform)

Example 4 with Transform

use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.

the class BackwardsExtentBlockCopy method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    CuboidRegion destRegion = transform(this.transform, this.region);
    Transform inverse = this.transform.inverse();
    for (BlockVector3 pt : destRegion) {
        BlockVector3 copyFrom = transform(inverse, pt);
        if (region.contains(copyFrom)) {
            if (function.apply(pt)) {
                affected++;
            }
        }
    }
    return null;
}
Also used : CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Transform(com.sk89q.worldedit.math.transform.Transform) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 5 with Transform

use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method download.

// FAWE start
@Command(name = "download", aliases = { "/download" }, desc = "Downloads your clipboard through the configured web interface")
@Deprecated
@CommandPermissions({ "worldedit.clipboard.download" })
public void download(final Actor actor, final LocalSession session, @Arg(name = "format", desc = "String", def = "fast") final String formatName) throws WorldEditException {
    final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
    if (format == null) {
        actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
        return;
    }
    actor.print(Caption.of("fawe.web.generating.link", formatName));
    ClipboardHolder holder = session.getClipboard();
    URL url;
    if (holder instanceof MultiClipboardHolder) {
        MultiClipboardHolder multi = (MultiClipboardHolder) holder;
        Set<File> files = new HashSet<>();
        Set<URI> invalid = new HashSet<>();
        for (ClipboardHolder cur : multi.getHolders()) {
            if (cur instanceof URIClipboardHolder) {
                URIClipboardHolder uriHolder = (URIClipboardHolder) cur;
                URI uri = uriHolder.getUri();
                File file = new File(uri.getPath());
                if (file.exists() && file.isFile()) {
                    files.add(file.getAbsoluteFile());
                } else if (!uri.getPath().isEmpty()) {
                    invalid.add(uri);
                }
            }
        }
        final LocalConfiguration config = WorldEdit.getInstance().getConfiguration();
        final File working = WorldEdit.getInstance().getWorkingDirectoryFile(config.saveDir).getAbsoluteFile();
        url = MainUtil.upload(null, null, "zip", new RunnableVal<>() {

            @Override
            public void run(OutputStream out) {
                try (ZipOutputStream zos = new ZipOutputStream(out)) {
                    for (File file : files) {
                        String fileName = file.getName();
                        if (MainUtil.isInSubDirectory(working, file)) {
                            fileName = working.toURI().relativize(file.toURI()).getPath();
                        }
                        ZipEntry ze = new ZipEntry(fileName);
                        zos.putNextEntry(ze);
                        Files.copy(file.toPath(), zos);
                        zos.closeEntry();
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    } else {
        Clipboard clipboard = holder.getClipboard();
        final Transform transform = holder.getTransform();
        final Clipboard target;
        // If we have a transform, bake it into the copy
        if (!transform.isIdentity()) {
            final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
            target = new BlockArrayClipboard(result.getTransformedRegion(), actor.getUniqueId());
            target.setOrigin(clipboard.getOrigin());
            Operations.completeLegacy(result.copyTo(target));
        } else {
            target = clipboard;
        }
        if (format == BuiltInClipboardFormat.PNG) {
            try {
                FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
                ClipboardWriter writer = format.getWriter(baos);
                writer.write(target);
                baos.flush();
                url = ImgurUtility.uploadImage(baos.toByteArray());
            } catch (IOException e) {
                e.printStackTrace();
                url = null;
            }
        } else {
            if (Settings.settings().WEB.URL.isEmpty()) {
                actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
                return;
            }
            url = FaweAPI.upload(target, format);
        }
    }
    if (url == null) {
        actor.print(Caption.of("fawe.web.generating.link.failed"));
    } else {
        String urlText = url.toString();
        actor.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
    }
}
Also used : ClipboardWriter(com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) FastByteArrayOutputStream(com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) BuiltInClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) URI(java.net.URI) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) URL(java.net.URL) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) FastByteArrayOutputStream(com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) RunnableVal(com.fastasyncworldedit.core.util.task.RunnableVal) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Transform(com.sk89q.worldedit.math.transform.Transform) File(java.io.File) HashSet(java.util.HashSet) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Transform (com.sk89q.worldedit.math.transform.Transform)6 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)5 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)4 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Vector3 (com.sk89q.worldedit.math.Vector3)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 Region (com.sk89q.worldedit.regions.Region)2 DiskOptimizedClipboard (com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard)1 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)1 ReadOnlyClipboard (com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard)1 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1 FastByteArrayOutputStream (com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream)1 LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 RoundedTransform (com.fastasyncworldedit.core.math.transform.RoundedTransform)1 RunnableVal (com.fastasyncworldedit.core.util.task.RunnableVal)1 EditSession (com.sk89q.worldedit.EditSession)1 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1