Get a specific block within co-ordinates

Discussion in 'Plugin Development' started by Daniel Few, May 24, 2011.

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

    Daniel Few

    How would I get a specific block inside co-ordinates.
    So eg, i have a set cuboid and i want to Get the doors inside that selection.
    -DanJames
     
  2. Offline

    narrowtux

    I would make a for loop like this:
    Assuming you've got two Location objects that define the cuboid:
    Code:
    Location loc1, loc2; //Have to be defined before
    for(int x = Math.min(loc1.getBlockX(),loc2.getBlockX()); x<=Math.max(loc1.getBlockX(),loc2.getBlockX());x++){
    for(int y = Math.min(loc1.getBlockY(),loc2.getBlockY()); y<=Math.max(loc1.getBlockY(),loc2.getBlockY());y++){
    for(int z = Math.min(loc1.getBlockZ(),loc2.getBlockZ()); z<=Math.max(loc1.getBlockZ(),loc2.getBlockZ());x++){
    Location current = new Location(loc1.getWorld(), x, y, z);
    Block b = current.getBlock();
    if(b.getType.equals(Material.WOODEN_DOOR)){
    ...
    }
    }
    }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page