Get Blocks in Selected Area

Discussion in 'Plugin Development' started by Pit910, Jan 24, 2014.

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

    Pit910

    Hey,

    iam German, sorry for my bad English!!

    I have a selected Area with Startx, Starty and Startz. Also Endx, Endy and Endz.

    I want to get all Blocks in this selected Area. Here my attempt:

    Code:
            int anfangx = -43;
        int anfangy = 4;
        int anfangz = 1494;
       
        int endex = -67;
        int endey = 2;
        int endez = 1517;
     
     
     
    World baumfarmw = Bukkit.getServer().getWorld("baumfarm");
     
     
            for (int i = anfangx; i<endex; i++){
               
                for (int j = anfangy; j<endey; j++){
                   
                    for (int k = anfangz; k<endez; k++){
                       
                       
                       
                        Block getblock = baumfarmw.getBlockAt(i, j, k);
                       
                       
                        getblock.setType(Material.AIR);
                       
                       
                       
                       
                       
                        }
                       
                       
                       
                    }
                   
                }
               
               
               
            }

    But it isn´t work! Knows anyone why?

    Thank You!
     
  2. Offline

    Maurdekye

    Does it throw an error, or does it just not do what you want?
     
  3. Offline

    Pit910

    It gives nor Error. It would been selected 0 Blocks!
     
  4. your anfangx is higher than your endex, so it won't loop at for (int i = anfangx; i<endex; i++){
     
  5. Offline

    Maurdekye

    Try some simpler numbers so it's not as hard to get them wrong;
    Code:java
    1. for (int x = 0 ; x < 50 ; x ++) {
    2. for (int y = 20 ; y < 80 ; y ++) {
    3. for (int z = 10 ; z < 20 ; z ++) {
    4. getServer().getWorld().getBlockAt(x, y, z).setType(Material.AIR);
    5. }
    6. }
    7. }


    That should work well within the given coordinates.
     
  6. Offline

    Pit910

    Thanks. I have exchanged it. It doesen´t work! :(

    Code:
           
        int anfangx = -67;
        int anfangy = 2;
        int anfangz = 1494;
       
        int endex = -43;
        int endey = 4;
        int endez = 1494;
     
     
     
    World baumfarmw = Bukkit.getServer().getWorld("baumfarm");
     
     
            for (int i = anfangx; i<endex; i++){
               
                for (int j = anfangy; j<endey; j++){
                   
                    for (int k = anfangz; k<endez; k++){
                       
                       
                       
                        Block getblock = baumfarmw.getBlockAt(i, j, k);
                       
                       
                        getblock.setType(Material.AIR);
                       
                       
                       
                       
                       
                        }
                       
                       
                       
                    }
                   
                }
               
               
               
            }
     
     
    
     
  7. Offline

    Maurdekye

    Pit910 Your start and end Z are the same.
     
  8. Pit910

    When looking at your code again, I see that
    int anfangz = 1494;
    and
    int endez = 1494;

    Your code uses < inside the loop, so it won't place blocks on the max coordinate (endex,endey,endez). It is really hard to explain this over the chat, but you can solve this by using =< instead of < inside al your loops

    EDIT: ninja'ed by Maurdekye
     
  9. Offline

    Pit910

    Okay, my Code is now like this:

    Code:
     
            for (int x = -67 ; x < -43 ; x ++) {
                for (int y = 4 ; y < 2 ; y ++) {
                for (int z = 1517 ; z < 1494 ; z ++) {
               
           
               
                    Block getblock = baumfarmw.getBlockAt(x, y, z);
               
                getBlock.setType(Material.AIR);
           
           
                }
                }
                }
            }
    It doesen´t work!

    Thank you for your answers!

    Please Correct it <3
     
  10. Offline

    _Filip

    Try google. Thank me later.
    I had this question many months ago, you should still be able to find it.
     
  11. Offline

    L33m4n123

    Because all of the starting values of your loops are greater than the end-values of your loops
     
  12. Offline

    Maurdekye

    swampshark19 That's no way to treat someone on the forums. He probably got here by googling it.

    Pit910 Your starting indexes must be smaller than your ending indexes;

    Code:java
    1. for (int x = -67 ; x < -43 ; x++) {
    2. for (int y = 2 ; y < 4; y ++) {
    3. for (int z = 1494 ; z < 1517 ; z++) {
    4. baumfarm.getBlockAt(x, y, z).setType(Material.AIR);
    5. }
    6. }
    7. }


    Replace your snippet of code with this and you should be good.
     
  13. Offline

    Pit910

    I have change them now so:

    Code:
            for (int x = -43 ; x < -67 ; x ++) {
                for (int y = 2 ; y < 4 ; y ++) {
                for (int z = 1494 ; z < 1517 ; z ++) {
                   
               
                   
                    Block getblock = baumfarmw.getBlockAt(x, y, z);
                   
                   
                    getblock.setType(Material.AIR);
                   
               
               
                }
                }
                }
            }
    Doesen´t Work.

    Thanks work now!

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

Share This Page