Square creating.

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

Thread Status:
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 :/


    Sorry for bad english.
     
  2. Offline

    Zupsub

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

    Sorry if I didn't understand your question right.
     
  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
    1. for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {
    2. for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {
    3. for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {
    4. player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
    5. }
    6. }
    7. }


    For spheres:
    Code:java
    1. for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {
    2. for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {
    3. for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {
    4. if (x*x + y*y + z*z <= 10*10) {
    5. player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
    6. }
    7. }
    8. }
    9. }


    I hope this helps!
     
  4. Offline

    DevManABCD


    Your cube works, but i need to hollow that cube, to get only walls from this ;/
     
  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"
     
  6. Offline

    DevManABCD




    Watch at 0:26.

    I want to create code for that generating walls B)
     
Thread Status:
Not open for further replies.

Share This Page