How to select position 1, position 2, and then make a wall?

Discussion in 'Plugin Development' started by Ambamore2000, Mar 8, 2014.

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

    Ambamore2000

    So, as most of you know/heard, there is a plugin called worldedit. It is a very helpful plugin, and it includes the command //walls <blocktype>. I was wondering how they did that. I want it, so you do //specwalls <radius> for this. If there is any way you can tell me, please tell me. I don't think you would give code, because I'm expecting this'll take a long time, but please tell me with words.
     
  2. Offline

    CraftThatBlock

    Idea:
    loc1
    loc2

    xMin = Math.min(loc1.getX, loc2.getX)
    xMax = Math.max(loc1.getX, loc2.getX)

    yMin = Math.min(loc1.getY, loc2.getY)
    yMax = Math.max(loc1.getY, loc2.getY)

    zMin = Math.min(loc1.getZ, loc2.getZ)
    zMax = Math.max(loc1.getZ, loc2.getZ)

    for(int x = xMin; x < xMax; x++){
    for(int y = yMin; y < yMax; y++){
    for(int z = xMin; z < zMax; z++){
    (new Location(loc1.getWorld(), x, y, z)).getBlock().setType(Material.Stone);

    }
    }
    }
    (Note: This is not real java code, I was just outlining most of the code. the min and max should be ints,
     
    AoH_Ruthless likes this.
  3. Offline

    ArthurMaker

  4. Offline

    CraftThatBlock

    To expand on what ArthurMaker did, (great lib btw), you can use this code:

    Code:java
    1.  
    2. for(Location loc : getCuboid(loc1, loc2){
    3. Block b = loc.getBlock();
    4. b.setMaterial(Material.Stone);
    5. }
    6.  
    7.  
    8. // From Arthur:
    9. public static List<Location> getCuboid(Location position1, Location position2){
    10.  
    11. if(position1.getWorld().getName() != position2.getWorld().getName()){
    12. throw new UnsupportedOperationException("'Position1' and 'Position2' location need to be in the same world!");
    13. }
    14.  
    15. List<Location> cube = new ArrayList<Location>();
    16.  
    17. int minX = (int) Math.min(position1.getX(), position2.getX());
    18. int maxX = (int) Math.max(position1.getX(), position2.getX());
    19.  
    20. int minY = (int) Math.min(position1.getY(), position2.getY());
    21. int maxY = (int) Math.max(position1.getY(), position2.getY());
    22.  
    23. int minZ = (int) Math.min(position1.getZ(), position2.getZ());
    24. int maxZ = (int) Math.max(position1.getZ(), position2.getZ());
    25.  
    26. for(int x = minX; x <= maxX; x++){
    27. for(int y = minY; y <= maxY; y++){
    28. for(int z = minZ; z <= maxZ; z++){
    29. cube.add(new Location(position1.getWorld(), x, y, z));
    30. }
    31. }
    32. }
    33. return cube;
    34. }
     
Thread Status:
Not open for further replies.

Share This Page