Solved Setting blocks of a world edit cuboid region to 0 (air)

Discussion in 'Plugin Development' started by wreed12345, Nov 12, 2013.

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

    wreed12345

    Hello, I am trying to set the contents of a world edit region to 0. I am using
    Code:java
    1. while(c.iterator().hasNext()){
    2. BlockVector blockvec = c.iterator().next();
    3. Block block = a.getWorld().getBlockAt(blockvec.getBlockX(), blockvec.getBlockY(), blockvec.getBlockZ());
    4. block.setType(Material.AIR);
    5. }

    c is my cuboid region. When using this code it repeatedly goes over the first block if I use a print statement to show this the same value is repeatedly shown. Are there any other ways to accomplish this?
     
  2. Offline

    Minecrell

    wreed12345
    Why don't you use the inbuild WorldEdit method to clear the region?
    Code:java
    1. // Create a edit session with unlimited blocks
    2. EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(c.getWorld(), -1);
    3. try {
    4. editSession.setBlocks(c, new BaseBlock(BlockID.AIR));
    5. } catch (MaxChangedBlocksException e) {
    6. // As of the blocks are unlimited this should not be called
    7. }
    I don't know what's the problem in your code, but probably because you're always creating a new iterator and so it will always start from the beginning. You can just to it through a for-loop:
    Code:java
    1. for (BlockVector blockvec : c) {
    2. Block block = BukkitUtil.toBlock(new BlockWorldVector(c.getWorld(), blockvec));
    3. block.setType(Material.AIR);
    4. }
    However, I would recommend the first version to set the blocks in the region. :)

    Edit: By the way, copied it from this post: https://forums.bukkit.org/threads/worldguard-edit-region-api-get-blocks-from-poly.184201/
     
    wreed12345 likes this.
  3. Offline

    wreed12345

    Minecrell only because I didn't know there was a native world edit method for such. One more question: how do i cast a Bukkit World to a WorldEdit LocalWorld?

    BukkitUtil.getLocalWorld() thanks for your help however

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page