# 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: #1
Last edited: May 3, 2017
2. Math lots of math

3. can give a example? i try using even and odd, but isnt work

4. I summon the math magician @finnbon

5. ### ChefJava

could you explain a bit more of what you're trying to do?

6. i want place block by block alternately, like in picture. but idk how do this

#6
Last edited: May 3, 2017
7. 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
Last edited: May 3, 2017
• Like x 1