Solved Breaking blocks in a 3x3x3 area

Discussion in 'Plugin Development' started by JjStAr992_Gaming, May 31, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys,

    So I'm trying to make a pickaxe that breaks blocks in a 3x3x3 area, similar to the Tinkers Construct Hammer (which only does a 3x3x1 area iirc). Here's how it works.

    Image (open)
    [​IMG]

    Say you were to break the diamond block. All the area inside the wool area would be set to air. In this case, the wool blocks touching the diamond block would be broken, but not the wool wall flush with the stone.

    My question is: I have the diamond block's location stored in a variable. How would one go about getting the locations of those 27 blocks and clear them?

    Sorry if you don't understand my explanation, it's a tricky concept to explain :p I can provide code for my current listener on request.

    Thanks very much in advance!
    JjStAr992_Gaming (TheReturningVoid)
     
  2. Offline

    I Al Istannen

  3. Thats actually pretty easy: You need to use 3 for-loops (x, y, z)
    This is how the first for-loop would looks like:
    Code:
    for (int x = startX - 1; x <= startX + 1; x++) {
    And when you are done with all the loops, remove those blocks at the location
    Code:
    for (int x ....) {
    for (int y ....) {
    for (int z ....) {
    Block b = world.getBlockAt(x, y, z);
    b.setType(Material.AIR);
    }
    }
    }
     
    Last edited: Jun 1, 2015
  4. Thank you very much, does exactly as I expected it to do. However, those < in the for loops need to be <= eg. x <= startX not x < startX. Anyway, thank you for the reply! Marking as solved.

    EDIT: Yeah, that was easy. It was late when I posted this, must not have been using full thinking power :p
     
  5. Sorry. None of them worked. This works:
    Code:
    for (int x = startX - 1; x < startX + 2; x++) {
    Or what you said:
    Code:
    for (int x = startX - 1; x <= startX + 1; x++) {
     
  6. That would work too. It's essentially the exact same thing.
     
    nlthijs48 likes this.
Thread Status:
Not open for further replies.

Share This Page