Blocks Alternates

Discussion in 'Spigot Plugin Development' started by jetao, May 3, 2017.

  1. i've a square, and i want place blocks alternates in the edges. how i can code it?
    like this:
    [​IMG]
     
    #1 jetao, May 3, 2017
    Last edited: May 3, 2017
  2. can give a example? i try using even and odd, but isnt work
     
  3. I summon the math magician @finnbon
     
  4. could you explain a bit more of what you're trying to do?
     
  5. i want place block by block alternately, like in picture. but idk how do this
     
    #6 jetao, May 3, 2017
    Last edited: May 3, 2017
  6. And here comes the plane! Yum yum yum yum
    Code (Text):
    int length = 5;
    int y = 78; // set to position y

    for (int x = 0; x < length; x++) {
        for (int z = 0; z < length; z++) {
            if (x == 0 || z == 0 || z == length - 1 || x == length - 1) {
                if (x + z % 2 == 0)
                    new Location(x,y,z).getBlock().setMaterial(Material.DIRT);
                else
                    new Location(x,y,z).getBlock().setMaterial(Material.COBBLE);
            }
        }
    }
    This is DEFINITELY not the most efficient way to do it.

    It loops through positions in a 2 deminsional square, if the current x and y are corners values then it will set the block to dirt if the sum is even... Or if the sum is odd it will set the block to cobble to give the alternate effect.

    Please someone come up with a cooler way that loops through the corners only instead of making a full square
     
    #7 Synapz, May 3, 2017
    Last edited: May 3, 2017
    • Like Like x 1