Clearing out all blocks

Discussion in 'Plugin Development' started by OcelotcR, Sep 11, 2013.

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

    OcelotcR

    hey there, i create a "disc" or a "flat sphere" with the following code

    Code:java
    1. for (int X = -radius; X < radius; X++) {
    2. for (int Y = -radius; Y < radius; Y++) {
    3. for (int Z = -radius; Z < radius; Z++) {
    4. if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
    5. Block block = center.getWorld().getBlockAt(X + center.getBlockX(), center.getBlockY(), Z + center.getBlockZ());
    6. block.setType(Material.NETHERRACK);
    7. sphere.add(block);
    8. if (!(block.getType().equals(Material.NETHERRACK) && (block.getType().equals(Material.AIR)))) {
    9. } else {
    10. block.setType(Material.AIR);
    11. }
    12. }
    13. }
    14. }
    15. }

    But im wondering how to use those blocks to clear all blocks above that radius? (In the Y Co-ord)
     
  2. Offline

    OcelotcR

  3. Offline

    Chinwe

    I'd suggest doing something like this:

    Code:
    for (Block block : cylinderBlocks)
    {
        int y = block.getY();
        while (y <= 256)
        {
            block.getWorld().getBlockAt(block.getX(), y, block.getZ()).setType(Material.AIR);
            y++;
        }
    }
    EDIT: Forgot to increment y :oops:
     
  4. Offline

    OcelotcR

    As for the array cylinderBlocks, what list would i apply to it?
     
  5. Offline

    Chinwe

    OcelotcR
    Put it in the nested loop below block.setType(Material.NETHERRACK) so it executes for every block ;)
    Looping through cylinderBlocks was just to show it was looping through all the blocks :)
     
  6. Offline

    OcelotcR

    Im sorry, but im totally confused, do you mean like this?

    Code:java
    1. for (int X = -radius; X < radius; X++) {
    2. for (int Y = -radius; Y < radius; Y++) {
    3. for (int Z = -radius; Z < radius; Z++) {
    4. if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
    5. Block block = center.getWorld().getBlockAt(X + center.getBlockX(), center.getBlockY(), Z + center.getBlockZ());
    6. int y = block.getY();
    7. while (y <= 256)
    8. block.getWorld().getBlockAt(block.getX(), y, block.getZ()).setType(Material.AIR);
    9. block.setType(Material.NETHERRACK);
    10. sphere.add(block);
    11. if (!(block.getType().equals(Material.NETHERRACK) && (block.getType().equals(Material.AIR)))) {
    12. } else {
    13. block.setType(Material.AIR);
    14. }
    15.  
    16. }
     
  7. Offline

    Chinwe

    OcelotcR
    Yus :) Though you need to change the while loop to what I edited it to above, as I forgot to increment y - if you don't, it will be an infinite loop and hang the server :'(

    Code:
    for (int X = -radius; X < radius; X++) {
                for (int Y = -radius; Y < radius; Y++) {
                    for (int Z = -radius; Z < radius; Z++) {
                        if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
                            Block block = center.getWorld().getBlockAt(X + center.getBlockX(), center.getBlockY(), Z + center.getBlockZ());     
                            int y = block.getY();
                            while (y <= 256)
                            {
                                block.getWorld().getBlockAt(block.getX(), y, block.getZ()).setType(Material.AIR); 
                                y++;
                            }
                            block.setType(Material.NETHERRACK);             
                            sphere.add(block);
                           
                            if (!(block.getType().equals(Material.NETHERRACK) && (block.getType().equals(Material.AIR)))) {
                            } else {
                                block.setType(Material.AIR);
                            }
     
                        }
    By the way, with lines 11 - 144, what is the point of them? You are setting 'block' to netherrack, then checking if it is netherrack, then setting it to air? Or checking if it isn't netherrack or air, and setting to air? :confused:
     
Thread Status:
Not open for further replies.

Share This Page