[Spherical Selection] - Need a basic idea.

Discussion in 'Plugin Development' started by Matthewenderle, May 28, 2012.

Thread Status:
Not open for further replies.
  1. Hello. I have been trying to make a plugin that will replace a certain block with another one. I decided to go with a sphere since this requires only one additional argument which is /pd <command> <radius>. I have been trying to get it to do what I want it to, but no avail. There are no errors, since I have no method. I am basically asking if anyone knows who to get a spherical selection based upon a player's possition (x, y, z). I have taken Geometry, Algebra 1, 2, and Advanced Algebra. and done rather well. The problem is that I can't come up with a way to make this work with bukkit/java. I have examined other projects source to look at how they do it, but they require multiple class files and i'd like to keep it to one if it is possible to do this.

    My method I thought of:
    Possible code for Hashmap w/ loop:

    Code:
    public static void radiusLamp(Player player)
          {
              player.getPlayer().sendMessage("  " + ChatColor.GOLD + Main.argRadius);
                Location here = player.getPlayer().getLocation();
                //String radius = Main.argPub;
                int radius = Main.argRadius;
                int radiusInv = radius - (2 * radius);
                double X = player.getPlayer().getLocation().getX();
                int pX = player.getLocation().getBlockX();
                int pY = player.getLocation().getBlockY();
                int pZ = player.getLocation().getBlockZ();
     
             
              if(radius >=160)
              {
                  player.getPlayer().sendMessage("You must specify a number smaller than 160.");
                  player.getPlayer().sendMessage("You did a radius of " + radius);
     
              }
              else
              {
                  for (int x = pX; (x <= radius) && (x >= radiusInv);)
                          selected_blocks.add(x);
     
                      for (int y = pY; (y <= radius) && (y >= radiusInv);)
                          for (int z = pZ; (z <= radius) && (z >= radiusInv);)
                      player.getPlayer().sendMessage("The Value of x is " + x);
               
                    player.getPlayer().sendMessage("The radius of the circle is " + radius);
                    player.getPlayer().sendMessage("The idc of the circle is " + radiusInv);
              }
    If you can, or know someone, that could help me in anyway, weather it's sharing code, a java formula, or even a good night sleep I would greatly appreciate it.
     
  2. Offline

    Nitnelave

    Well, you could do a triple loop that would check x y z from position-radius to position+radius, and check at every block if the distance if inferior to radius.
     
  3. Offline

    Malikk

    That wouldn't work because of the way Bukkit handles distance. 3 blocks straight away from you and 3 blocks diagonally away from you would both have a bukkit distance of 3, even tho the latter is clearly 'farther'. So using distance with bukkit will always form a square, not a circle. When is usually good enough, imo, lol. Actually getting a circle is quite a bit more difficult, but I can't say I've ever done it.
     
  4. Offline

    Nitnelave

    You can do it with space coordinates. Calculate yourself the distance with sqrt((x2-x1)² + (y2-y1)² + (z2-z1)²)
     
Thread Status:
Not open for further replies.

Share This Page