Solved Getting blocks in squared. How?

Discussion in 'Spigot Plugin Development' started by GeraldFrito, May 29, 2020.

Thread Status:
Not open for further replies.
  1. I'm trying to protect blocks from one block as center, but when I use ".distance().", for example, it returns what I almost want: blocks near of a limit of center block but in a circle. I used "distanceSquared()" but it's the same.

    How can I get those blocks exactly in square? Is there another methods that I can use? I want it to protect a specific zone.
  2. You would need to calculate the difference to the center block, and check it in all directions. So for example:
    Code (Text):
    final int MAX_DISTANCE = 10;
    Location center = ...
    Location location = ...

    int dX = Math.abs(center.getBlockX() - location.getBlockX());
    int dY = Math.abs(center.getBlockY() - location.getBlockY());
    int dZ = Math.abs(center.getBlockZ() - location.getBlockZ());

        // The block is NOT protected
    } else {
        // The block IS PROTECTED
Thread Status:
Not open for further replies.