Square creating.

Discussion in 'Plugin Development' started by DevManABCD, Aug 28, 2014.

Not open for further replies.
1. Offline

DevManABCD

Hey, today i started good pvp plugin project, and i need something to release rc.

I know how to loop all blocks between selections, but i really dont have any idea how to create hollow square in radius 10 from player location...

Is it possible without worlddit or with? It must be but not easy :/

#1
2. Offline

Zupsub

Just use the same as the square, but ignore the filling?
Code:java
`for (int x = startX; x < endX; x++)    for (int z = startZ; z < endZ; z++)      if ((x != startX && x != endX) ||          (z != startZ && z != endZ))          continue;        else          //do something`

Sorry if I didn't understand your question right.

#2
3. Offline

AlphaRLee

Squares? Spheres? I got a technique, but I'm not sure how efficient it is. If you guys can make a more optimal code, please do. But here's my help:

For cubes:
Code:java
`for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {     for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {          for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {               player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);          }     }}`

For spheres:
Code:java
`for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {     for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {          for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {               if (x*x + y*y + z*z <= 10*10) {                    player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);               }          }     }}`

I hope this helps!

#3
4. Offline

DevManABCD

Your cube works, but i need to hollow that cube, to get only walls from this ;/

#4
5. Offline

AlphaRLee

DevManABCD Wait, so you want to add walls around the player? Can you clarify your question? As far as I can tell, this method hollows the cube, making a pure space around the player that is empty. If you want walls around your cube, do this (I'm sorry, I'm a bit lazy right now. I'll give you some pseudocode for now, please tahg me again if you want some working code):

-------------------------------------------------------------------
Set x to be player location - 11.
Loop through all the Y and Z blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be (Material.STONE)

Set x to be player location + 11.
Loop through all the Y and Z blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be

Set y to be player location - 11.
Loop through all the X and Z blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be

Set y to be player location + 11.
Loop through all the X and Z blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be

Set z to be player location - 11.
Loop through all the X and Y blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be

Set z to be player location + 11.
Loop through all the X and Y blocks that are within the player's location - 11 blocks and + 11 blocks
Set all blocks to be whatever you need it to be
--------------------------------------------------------------------------------

It's messy, but that's what I'd do to add walls. But I don't know what you want when you say "hollow cubes"

#5
6. Offline

DevManABCD

Watch at 0:26.

I want to create code for that generating walls B)

#6