Solved Set from block to block?

Discussion in 'Plugin Development' started by Meatiex, Nov 24, 2013.

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

    Meatiex

    Is their any way to set from corner to corner like worldedit instead of each block individually?
     
  2. Offline

    GusGold

    Meatiex
    Obviously, WorldEdit has to do it somehow :p
    So, iterate through each block inside your 2 points. You'll need 3 for loops, once for each axis. You'll want to make one of the points, the smallest values and another the largest values so you can easily iterate through them
    Make a location the smallest (open)
    Code:java
    1. if(loc1.getBlockX() > loc2.getBlockX()){ //Making loc1 have the smaller X value
    2. double buffer = loc1.getBlockX();
    3. loc1.setX(loc2.getBlockX());
    4. loc2.setX(buffer) ;
    5. }
    6. if(loc1.getBlockY() > loc2.getBlockY()){ //Making loc1 have the smaller Y value
    7. double buffer = loc1.getBlockY();
    8. loc1.setY(loc2.getBlockX());
    9. loc2.setY(buffer) ;
    10. }
    11. if(loc1.getBlockZ() > loc2.getBlockZ()){ //Making loc1 have the smaller Z value
    12. double buffer = loc1.getBlockZ();
    13. loc1.setZ(loc2.getBlockZ());
    14. loc2.setZ(buffer) ;
    15. }
    Go through each point in area (open)
    Code:java
    1. for (int x = loc1.getX(), x < loc2.getX(); x++){
    2. for (int y = loc1.getY(), y < loc2.getY(); y++){
    3. for (int z = loc1.getZ(), z < loc2.getZ(); z++){
    4. loc1.getWorld().getBlockAt(x, y, z).setType(Material.MYMATERIAL);
    5. }
    6. }
    7. }
     
  3. Offline

    Meatiex

    Sorry to bump so late, but any idea why this didn't work?
    Code:java
    1. World world = Bukkit.getWorld("plotworld");
    2. for (int x = 64; x < 101; x++){
    3. int y = 64;
    4. for (int z = 130; z < 177; z++){
    5. world.getBlockAt(x, y, z).setType(Material.SNOW_BLOCK);
    6. }
    7. }
     
  4. Offline

    GusGold

    Meatiex
    First off, move your y initiator out of the for loop, that is unnessecary load on the server. As for not working, and without seeing any stack trace, I would assume that your world variable is null. Check that it is actually finding a world by that name.
     
  5. Offline

    Meatiex

    The world's definitely named that, I tp the players with that "world' code :p
    I removed the Y :)
    Code:java
    1. World world = Bukkit.getWorld("plotworld");
    2. for (int x = 64; x < 101; x++){
    3. for (int z = 130; z < 177; z++){
    4. world.getBlockAt(x, 64, z).setType(Material.SNOW_BLOCK);
    5. }
    6. }

    Still doesn't work...
    //Ignore above...
    It works now :D thank you so much.
     
  6. Offline

    GusGold

    Meatiex
    No problems :) Might want to mark it as solved then :p
     
Thread Status:
Not open for further replies.

Share This Page