Rotate Clipboard in WorldEdit API 7.0 (1.13.2)

Discussion in 'Spigot Plugin Development' started by Nowaha, Dec 14, 2019.

  1. Hello!

    I am trying to rotate my clipboard using the 7.0 version of the WorldEdit API on a 1.13.2 Spigot server.
    It used to be very easy with the CuboidClipboard; you'd just do CuboidClipboard#rotate2D().

    What is the new equivalent for the plain Clipboard? (the CuboidClipboard has been removed)

    My code:

    Code (Java):

    Location loc = locations.get(id);
    File schematic = new File(getDataFolder().getParentFile(), "WorldEdit/schematics/mine1.schem");
    ClipboardFormat format = ClipboardFormats.findByFile(schematic);
    ClipboardReader reader = format.getReader(new FileInputStream(schematic));
    Clipboard clipboard = reader.read();

    try {
        com.sk89q.worldedit.world.World adaptedWorld = BukkitAdapter.adapt(loc.getWorld());
        EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(adaptedWorld, -1);
        Operation operation = new ClipboardHolder(clipboard).createPaste(editSession).to(BlockVector3.at(loc.getBlockX(), loc.getBlockY() + 5, loc.getBlockZ())).ignoreAirBlocks(true).build();

        try {
            Operations.complete(operation);
            editSession.flushSession();
        } catch (WorldEditException ignored) { }
    } catch (Exception ignored) { }
     
    Thank you very much!
     
  2. I've wondered this recently and did my own digging.
    From FastAsyncWorldEdit's github, you can use WorldEdit's AffineTransformation class:
    Code (Java):

    ClipboardHolder holder = new ClipboardHolder(clipboard);
    holder.setTransform(new AffineTransformation().rotateY(90));
     
     
  3. I'm trying this, but it's not working. When I paste the clipboard it ends up unchanged, no rotation. I'm not getting any exceptions either. This is a method I created for the class Structure, which holds a Clipboard object:
    Code (Java):

    public void rotate(double degrees){
        ClipboardHolder clipboardHolder = new ClipboardHolder(this.clipboard);
        clipboardHolder.setTransform(new AffineTransform().rotateY(degrees));
        this.clipboard = clipboardHolder.getClipboard();
        System.out.println("Structure rotated");
     
    I'm testing with degrees = 90. The "Structure rotated" message does get printed.
     
  4. I figured it out! I made it so that the Structure class holds a ClipboardHolder object instead, and I'm applying the rotation directly on it.
     
  5. Sweet!
    Yeah, ClipboardHolder only applies its transformation with #createPaste()