10 Pasting a schematic
0xLyptox | Lars edited this page 2019-07-18 23:23:39 +02:00

Pasting a schematic with FAWE

boolean allowUndo = true;
EditSession editSession = ClipboardFormats.findByFile(file).load(file).paste(world, position, allowUndo, !noAir, (Transform) null);

Saving a schematic with FAWE

File file = new File("mySchem.schematic");
Vector bot = new Vector(0, 0, 0); //MUST be a whole number eg integer
Vector top = new Vector(50, 255, 50); //MUST be a whole number eg integer
CuboidRegion region = new CuboidRegion(new BukkitWorld(world), bot, top);
Schematic schem = new Schematic(region);
schem.save(file, ClipboardFormat.SCHEMATIC);

Pasting a schematic without FAWE (1.7 -> 1.12)

File file = new File("myFile"); // The schematic file
Vector to = new Vector(0, 0, 0); // Where you want to paste

World weWorld = new BukkitWorld(world);
WorldData worldData = weWorld.getWorldData();
Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(file)).read(worldData);
Region region = clipboard.getRegion();

EditSession extent = WorldEdit.getInstance().getEditSessionFactory().getEditSession(weWorld, -1);
AffineTransform transform = new AffineTransform();

//{ // Uncomment this if you want to rotate the schematic
//    transform = transform.rotateY(90); // E.g. Rotate 90
//    extent = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry());
//}

ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), clipboard.getOrigin(), extent, to);
if (!transform.isIdentity()) copy.setTransform(transform);
if (ignoreAirBlocks) {
    copy.setSourceMask(new ExistingBlockMask(clipboard));
}
Operations.completeLegacy(copy);
extent.flushQueue();