Solved WorldEdit API - Pasting Schematics.

Discussion in 'Plugin Development' started by bkleinman1, Nov 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bkleinman1

    Using some code that I found here on these forums, I was able to use the world edit API to paste a schematic file:

    Code:java
    1. public static void loadArea(World world, String str, Vector origin) throws DataException, IOException, MaxChangedBlocksException {
    2. File file = new File(str);
    3. EditSession es = new EditSession(new BukkitWorld(world), 999999999);
    4. CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
    5. cc.paste(es, origin, false);
    6. }


    Now, my question: Would it be possible to change the way these schematics are pasted? I would like to paste them one 'layer' at a time. So, relative to the pasted blocks, I would like to start pasting when Y = 0, then I would add a little delay, and then paste all of the blocks that are on the level of Y = 1 (ect, ect).

    Thanks in advance to any help that you could offer me.
     
  2. Offline

    bkleinman1

    Bump .-.
     
  3. Offline

    bkleinman1

    Bump. If it helps, I am not stuck to WorldEdit, if someone knows how to do it without, then please do help out.
     
  4. Offline

    mythbusterma

    bkleinman1

    Not by using WorldEdit, no. You can do this yourself, however. It's not too difficult.
     
  5. Offline

    bkleinman1

    mythbusterma Would you mind pointing me in the right direction?
     
  6. Offline

    Avygeil

    bkleinman1 If you want to depend on WorldEdit to load schematics and not have to code that part, you can write your own paste implementation. See how CuboidClipboard#place does it. Keep the first part of the code until your CuboidClipboard loaded the schematic. Then, pass it to your own place function. Use CuboidClipboard#getWidth/getLength/getHeight/getBlock to get sizes/blocks, but loop through the Y layer as the first loop. You could use a recursive task that calls itself with y+1 until everything is pasted. :)
     
    bkleinman1 likes this.
  7. Offline

    bkleinman1

    Avygeil Thank you! If I were pasting the blocks like this:

    Code:java
    1. for (int y = 0; y < height; y++) {
    2. for (int z = 0; z < length; z++) {
    3. for (int x = 0; x < width; x++) {
    4. Vector pos = new Vector(x, y, z);
    5. BaseBlock block = cc.getBlock(pos);
    6. es.setBlock(pos.add(origin), block);
    7. }
    8. }
    9. }


    I have been trying to delay each layer being pasted. I tried using BukkitRunnables without any success. Any suggestions on what I could use?
     
  8. Offline

    ColonelHedgehog

  9. Offline

    Avygeil

    bkleinman1 BukkitRunnable should work. Here's what I'd do :
    Code:java
    1. public class DelayedPaste extends BukkitRunnable {
    2. public DelayedPaste(JavaPlugin plugin, CuboidClipboard cc, int layer) {
    3. //
    4. }
    5.  
    6. @Override
    7. public void run() {
    8. // paste the layer
    9.  
    10. if (layer <= cc.getHeight()) {
    11. new DelayedPaste(plugin, cc, ++layer).runTaskLater(plugin, 20L);
    12. }
    13. }
    14. }

    That way it will paste all layers. You can also do it with repeating tasks, as long as you don't run them asynchronously. Lookup the javadocs for more help with BukkitRunnable.
     
    bkleinman1 likes this.
  10. Offline

    bkleinman1

    Avygeil Ah, that makes sense. I will implement it later. Thank you ever so much for the help, it is greatly appreciated. :)
     
    Avygeil likes this.
Thread Status:
Not open for further replies.

Share This Page