Making a cube selection from two points

Discussion in 'Plugin Development' started by RandomPanda30, Apr 1, 2014.

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

    RandomPanda30

    Hi there,

    I am currently working on a plugin and I need to make a cube selection with two points. So I have created a wand and I will select two points, both diagonal from each other. With these two points, I would like to know how I would select all the blocks inbetween these two points. I know WorldEdit depends on this selection but I do not want to go ripping code off them ;3

    Thank you for your help

    ~ Panda
     
  2. Offline

    Bionicrm

    I've done something like this before.
    I hate to spoonfeed, but I was kinda proud of myself when I figured it out on my own :3

    Anyway, in sorta-sudo code:

    Code:java
    1. int x1 = 1;
    2. int y1 = 1;
    3. int z1 = 1;
    4.  
    5. int x2 = 3;
    6. int y2 = 3;
    7. int z2 = 3;
    8.  
    9. for (int x = x1; x <= x2; x++) {
    10. for (int y = y1; y <= y2; y++) {
    11. for (int z = z1; z <= z2; z++) {
    12. World.getBlockAt(x, y, z). // do stuff
    13. }
    14. }
    15. }


    x1, y1, and z1 should be the MINIMUM values, and x2, y2, z2 should be MAXIMUM values. The best way to do this would be to use: Math.max(x1, x2) for the maximums, and Math.min(x1, x2) for the minimums. If it's a little confusing, it's really just common sense.
     
  3. Offline

    TwerkinCraft

    Code:java
    1. //I didnt test this in my IDE, but im guessing it will be something like this
    2. public ArrayList<Block>(){
    3. Location point1;
    4. Location point2;
    5. ArrayList<Block> Blocks = new ArrayList<Block>();
    6. for(int x=point1.getX(); x((x<point2.getX())? <=:>=); x((x<point2.getX())? ++:--)){
    7. for(same here but with y){
    8. for(same here but with z){
    9. Blocks.add(new Location(point1.getWorld(), x, y, z).getBlock());
    10. }
    11. }
    12. }
    13. return Blocks;
    14. }


    I messed up, use location.getBlockX(); instead of getX();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    RandomPanda30

    Bionicrm Thank you so much. I understand what you mean by spoon feeding code but I see it as if you help me, then you can help 1000 people who have the same issue ;3 I will let you know how it goes.

    TwerkinCraft I will also try this method to see if this works, I should be able to let you know the results tonight ;3 Thank you so much guys ;D
     
Thread Status:
Not open for further replies.

Share This Page