Creating a Cuboid

Discussion in 'Plugin Development' started by BungeeTheCookie, Jun 15, 2014.

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

    BungeeTheCookie

    How do you create a cuboid? WorldEdit is not an acceptable answer.
     
  2. Offline

    Antybarrel

    What do you mean create a cuboid? Like blocks or what be more specific.
     
  3. Offline

    BungeeTheCookie

    A region that contains blocks.
     
  4. Offline

    xize

    BungeeTheCookie

    well there are lots of topics out there about this, I generally don't want to sound harsh but show us what you already got, and maybe some more description in what you want could be nice, if its for creating cuboids based on a center then there are less threads of them.
     
  5. Offline

    amhokies

    You need two locations. One corner, and the opposite corner. For instance, let's say they're called maxLoc and minLoc. You need to create nested for loops in order to iterate through all the x, y, and z coordinates of each of these to account for every block in the region.

    Code:java
    1. for(int x = minLoc.getBlockX(); x <= maxLoc.getBlockX(); x++) {
    2. for(int y = minLoc.getBlockY(); y <= maxLoc.getBlockY(); y++) {
    3. for(int z = minLoc.getBlockZ(); z <= maxLoc.getBlockZ(); z++) {
    4.  
    5. }
    6. }
    7. }
     
  6. Offline

    BungeeTheCookie

    Alright. As of now I got nothing.

    Could you lead me to a thread that has a solution for creating cuboids from the center? (using a radius)

    amhokies
    How do you do it from the center?
     
  7. Offline

    Gamecube762

    Location pos1, pos2

    onLclick pos1 = getLoc
    onRclick pos2 = getLoc

    if (blah > blah && blah < blah) loc is within cuboid

    something like this? BungeeTheCookie

    Edit: Double ninja'd...
     
  8. Offline

    BungeeTheCookie

    Thats what amhokies suggested, but I wanted to create it from the center?
     
  9. Offline

    amhokies

    From the center, if you know the size of the cuboid is 9x9x9 for instance, you add 4 to x, y, and z of the middle location to get your maxLoc and subtract 4 from x, y, and z of the middle location to get the minLoc. Generally, the amount to add/subtract is (size-1) / 2
     
  10. Offline

    xize

    BungeeTheCookie

    in that case its smilliar as from amhokies but then as /2

    I'm not super smart in math though but lets say:

    Code:
    int range = 10;
    Location loc = p.getLocation();
    loc.setX(loc.getX()-(range/2)); //because this is x - half the range it points to the center
    loc.setZ(loc.getZ()-(range/2)); //because this is z - half the range it points to the center
     
    //then do for loop, like how you calculate litters length * width * height (for me it won't make sense but maybe you remember) :P
    
    I'm not going to spoonfeed futher, but math is always something I could understand as anoying:p
     
  11. Offline

    amhokies

    This would make the size 11. It's a bit difficult to do without restricting them to odd numbers.
     
  12. Offline

    AoH_Ruthless

    xize
    The first couple lines of your code, while your intention to spoonfeed is great, doesn't really give the OP a sufficient answer.

    BungeeTheCookie
    If you were to center your cuboid on a player location:
    Code:java
    1. Location center = p.getLocation();
    2. int radius = 8;


    You would want to get the minimum, and the maximum point.
    Just like xize said (sorry for double tahg), you will subtract the radius from the x and z to get the minimum.
    Code:java
    1. Location minimum = new Location(center.getWorld(), center.getX() - (radius / 2), <your Y value, possibly center.getY(), center.getZ() - (radius / 2));
    2.  
    3. // Do the same thing in opposite direction for maximum
    4. // Return all locations that are between these two locations (check if x, y, and z values are in between the min and max inclusively, like others told you.


    But, radii are hard when even numbers, so you will have a better time rounding one way or another like amhokies said.
     
  13. Offline

    xize

    amhokies
    in which way? if you do i < range it would be 9 but actually still counts as 10 for me its not that visible in effect unless when I'm going to iterate through a Array but yes you are right.
     
  14. Offline

    BungeeTheCookie

    xize AoH_Ruthless amhokies
    Alright, I have my cuboid code
    Code:java
    1. Location minimum = new Location(center.getWorld(), center.getX() - (radius / 2), center.getY(), center.getZ() - (radius / 2));
    2. Location maximum = new Location(center.getWorld(), center.getX() + (radius / 2), center.getY(), center.getZ() + (radius / 2));
    3.  
    4. for(int x = minimum.getBlockX(); x <= maximum.getBlockX(); x++) {
    5. for(int y = minimum.getBlockY(); y <= maximum.getBlockY(); y++) {
    6. for(int z = minimum.getBlockZ(); z <= maximum.getBlockZ(); z++) {
    7.  
    8. }
    9. }
    10. }

    How do you find all of the blocks within the cuboid?
     
  15. *takes out one hand* You have some numbers in your loop
    *takes out other hand* Location is made of numbers (and something else) and you can get a block from it
    *puts hands together*

    See what I'm saying? :)
     
    Garris0n likes this.
  16. Offline

    BungeeTheCookie

    You are applauding yourself for how good you are at charades. :p
     
    AdamQpzm likes this.
  17. BungeeTheCookie My hands are too full of integers and locations for clapping.
     
  18. Offline

    BungeeTheCookie

    Like this?
    Code:
    for(int x = minimum.getBlockX(); x <= maximum.getBlockX(); x++) {
                for(int y = minimum.getBlockY(); y <= maximum.getBlockY(); y++) {
                    for(int z = minimum.getBlockZ(); z <= maximum.getBlockZ(); z++) {
                        Block b = new Location(center.getWorld(), x, y, z).getBlock();
                    }
                }
            }
     
  19. BungeeTheCookie Looks good to me, but then again, I'm not a java runtime environment :)
     
  20. Offline

    BungeeTheCookie

    Yea.. Im coding a large plugin. so I want to test it all at once.. :) Thank you though!
     
    AdamQpzm likes this.
  21. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Deleted a bunch of offtopic posts.
     
Thread Status:
Not open for further replies.

Share This Page