com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard Java Examples

The following examples show how to use com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard. 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: FaweSchematicHandler.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
    TaskManager.IMP.async(new Runnable() {
        @Override
        public void run() {
            Location[] corners = MainUtil.getCorners(world, regions);
            Location pos1 = corners[0];
            Location pos2 = corners[1];
            final CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
            final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();

            final int mx = pos1.getX();
            final int my = pos1.getY();
            final int mz = pos1.getZ();

            ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);

            Clipboard holder = new BlockArrayClipboard(region, clipboard);
            com.sk89q.jnbt.CompoundTag weTag = SchematicWriter.writeTag(holder);
            CompoundTag tag = new CompoundTag((Map<String, Tag>) (Map<?, ?>) weTag.getValue());
            whenDone.run(tag);
        }
    });
}
 
Example #2
Source File: Schematic.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void paste(Extent extent, WorldData worldData, Vector to, boolean pasteAir, Transform transform) {
    checkNotNull(transform);
    Region region = clipboard.getRegion();
    Extent source = clipboard;
    if (worldData != null && transform != null) {
        source = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to);
    if (transform != null) {
        copy.setTransform(transform);
    }
    copy.setCopyBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes());
    if (extent instanceof EditSession) {
        EditSession editSession = (EditSession) extent;
        Mask sourceMask = editSession.getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            editSession.setSourceMask(null);
        }
    }
    if (!pasteAir) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    Operations.completeBlindly(copy);
}
 
Example #3
Source File: PasteBuilder.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Build the operation.
 *
 * @return the operation
 */
public Operation build() {
    Extent extent = clipboard;
    if (!transform.isIdentity()) {
        extent = new BlockTransformExtent(extent, transform, targetWorldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
    copy.setTransform(transform);
    copy.setCopyEntities(!ignoreEntities);
    copy.setCopyBiomes((!ignoreBiomes) && (!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes()));
    if (this.canApply != null) {
        copy.setFilterFunction(this.canApply);
    }
    if (targetExtent instanceof EditSession) {
        Mask sourceMask = ((EditSession) targetExtent).getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            ((EditSession) targetExtent).setSourceMask(null);
        }
    }
    if (ignoreAirBlocks) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    return copy;
}
 
Example #4
Source File: MultiClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public MultiClipboardHolder(Clipboard clipboard, WorldData worldData) {
    super(URI.create(""), EmptyClipboard.INSTANCE, worldData);
    holders = new ArrayList<>();
    URI uri = URI.create("");
    if (clipboard instanceof BlockArrayClipboard) {
        FaweClipboard fc = ((BlockArrayClipboard) clipboard).IMP;
        if (fc instanceof DiskOptimizedClipboard) {
            uri = ((DiskOptimizedClipboard) fc).getFile().toURI();
        }
    }
    add(uri, clipboard);
}
 
Example #5
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 #6
Source File: LazyClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void close() {
    if (clipboard instanceof BlockArrayClipboard) {
        ((BlockArrayClipboard) clipboard).close();
    }
    clipboard = null;
}
 
Example #7
Source File: DiskOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public BlockArrayClipboard toClipboard() {
    try {
        CuboidRegion region = new CuboidRegion(new Vector(0, 0, 0), new Vector(width - 1, height - 1, length - 1));
        int ox = mbb.getShort(8);
        int oy = mbb.getShort(10);
        int oz = mbb.getShort(12);
        BlockArrayClipboard clipboard = new BlockArrayClipboard(region, this);
        clipboard.setOrigin(new Vector(ox, oy, oz));
        return clipboard;
    } catch (Throwable e) {
        MainUtil.handleError(e);
    }
    return null;
}
 
Example #8
Source File: Schematic.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the schematic for a region
 *
 * @param region
 */
public Schematic(Region region) {
    checkNotNull(region);
    checkNotNull(region.getWorld(), "World cannot be null (use the other constructor for the region)");
    EditSession session = new EditSessionBuilder(region.getWorld()).allowedRegionsEverywhere().autoQueue(false).build();
    this.clipboard = new BlockArrayClipboard(region, ReadOnlyClipboard.of(session, region));
}
 
Example #9
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Lazily copy a region
 *
 * @param region
 * @return
 */
public BlockArrayClipboard lazyCopy(Region region) {
    WorldCopyClipboard faweClipboard = new WorldCopyClipboard(this, region);
    BlockArrayClipboard weClipboard = new BlockArrayClipboard(region, faweClipboard);
    weClipboard.setOrigin(region.getMinimumPoint());
    return weClipboard;
}
 
Example #10
Source File: SchematicWriter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(final Clipboard clipboard, WorldData data) throws IOException {
    if (clipboard instanceof BlockArrayClipboard) {
        stream((BlockArrayClipboard) clipboard);
    } else {
        outputStream.writeNamedTag("Schematic", writeTag(clipboard));
        outputStream.flush();
    }
}
 
Example #11
Source File: CuboidClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs the clipboard.
 *
 * @param size the dimensions of the clipboard (should be at least 1 on every dimension)
 */
public CuboidClipboard(Vector size) {
    checkNotNull(size);
    MainUtil.warnDeprecated(BlockArrayClipboard.class, ClipboardFormat.class);
    origin = new Vector();
    offset = new Vector();
    this.size = size;
    this.dx = size.getBlockX();
    this.dxz = dx * size.getBlockZ();
    ids = new byte[dx * size.getBlockZ() * ((size.getBlockY() + 15) >> 4)][];
    nbtMap = new HashMap<>();
}
 
Example #12
Source File: CuboidClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs the clipboard.
 *
 * @param size   the dimensions of the clipboard (should be at least 1 on every dimension)
 * @param origin the origin point where the copy was made, which must be the
 *               {@link CuboidRegion#getMinimumPoint()} relative to the copy
 */
public CuboidClipboard(Vector size, Vector origin) {
    checkNotNull(size);
    checkNotNull(origin);
    MainUtil.warnDeprecated(BlockArrayClipboard.class, ClipboardFormat.class);
    this.origin = origin;
    this.offset = new Vector();
    this.size = size;
    this.dx = size.getBlockX();
    this.dxz = dx * size.getBlockZ();
    ids = new byte[dx * size.getBlockZ() * ((size.getBlockY() + 15) >> 4)][];
    nbtMap = new HashMap<>();
}
 
Example #13
Source File: CuboidClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs the clipboard.
 *
 * @param size   the dimensions of the clipboard (should be at least 1 on every dimension)
 * @param origin the origin point where the copy was made, which must be the
 *               {@link CuboidRegion#getMinimumPoint()} relative to the copy
 * @param offset the offset from the minimum point of the copy where the user was
 */
public CuboidClipboard(Vector size, Vector origin, Vector offset) {
    checkNotNull(size);
    checkNotNull(origin);
    checkNotNull(offset);
    MainUtil.warnDeprecated(BlockArrayClipboard.class, ClipboardFormat.class);
    this.origin = origin;
    this.offset = offset;
    this.size = size;
    this.dx = size.getBlockX();
    this.dxz = dx * size.getBlockZ();
    ids = new byte[dx * size.getBlockZ() * ((size.getBlockY() + 15) >> 4)][];
    nbtMap = new HashMap<>();
}
 
Example #14
Source File: SchematicStreamer.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public SchematicStreamer(NBTInputStream stream, UUID uuid) {
    super(stream);
    this.uuid = uuid;
    clipboard = new BlockArrayClipboard(new CuboidRegion(new Vector(0, 0, 0), new Vector(0, 0, 0)), fc);
}
 
Example #15
Source File: ClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void close() {
    if (clipboard instanceof BlockArrayClipboard) {
        ((BlockArrayClipboard) clipboard).close();
    }
    clipboard = null;
}