Solved Blocks between two points goes off in Z direction

Discussion in 'Plugin Development' started by jolbol1, Aug 6, 2015.

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

    jolbol1

    Code:
      public List<Block> blocksFromTwoPoints(Location loc1, Location loc2)
    
        {
    
    
            List<Block> blocks = new ArrayList<Block>();
            int topBlockX = (loc1.getBlockX() < loc2.getBlockX() ? loc2.getBlockX() : loc1.getBlockX());
            int bottomBlockX = (loc1.getBlockX() > loc2.getBlockX() ? loc2.getBlockX() : loc1.getBlockX());
            int topBlockY = (loc1.getBlockY() < loc2.getBlockY() ? loc2.getBlockY() : loc1.getBlockY());
            int bottomBlockY = (loc1.getBlockY() > loc2.getBlockY() ? loc2.getBlockY() : loc1.getBlockY());
            int topBlockZ = (loc1.getBlockZ() < loc2.getBlockZ() ? loc2.getBlockZ() : loc1.getBlockZ());
            int bottomBlockZ = (loc1.getBlockZ() > loc2.getBlockZ() ? loc2.getBlockZ() : loc1.getBlockZ());
            for (int x = bottomBlockX; x <= topBlockX; x++) {
                for (int z = bottomBlockZ; z <= topBlockZ; z++)
    
    
                {
    
    
                    for (int y = bottomBlockY; y <= topBlockY; y++)
    
    
                    {
    
                        Block block = loc1.getWorld().getBlockAt(x, y, z);
    
    
                        blocks.add(block);
    
    
                    }
                }
            }
            return blocks;
        }
    This code works fine in the X and Y directions, However it seems to add a lot of blocks in the Z direction. I use World edit to get the selection, Then the Max min points, and use this code to get all the blocks between it. At one point I had counted it added 36 blocks in the z direction to the list.

    Solved. One of the Locations was wrong.

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

Share This Page