Getting all nearby blocks

Discussion in 'Plugin Development' started by DogeDebugger, May 7, 2015.

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


    So i want to get all nearby blocks in a 25x25 (x and z only) radius from a location, and then pick out 10 of them to do something.

    Picking them out won't be too hard, but how do i actually get all nearby blocks? Method or something?
  2. Offline


  3. Offline


    I know, but loop through what...
  4. Offline



    25 x 25 doesn't specify a radius (a property of a circle), it specifies a rectangle.

    Which one do you mean?
  5. Offline


    Rectangle, sorry
  6. Offline


    @DogeDebugger With the location (center), make a new location with -25 in each direction and another one with 25 in each direction, then just loop through these numbers?
  7. Offline


    Like this?
      Location loc1 = new Location(w, loc.getX() + 25, loc.getY(), loc.getZ() + 25);
                 Location loc2 = new Location(w, loc.getX() - 25, loc.getY(), loc.getZ() - 25);
  8. Offline


    @DogeDebugger Actually, thinking that you need to loop in it, I'd go with something like this
    //Get one corner
    int minX = center.getBlockX() - 12;
    int minY = center.getBlockY() - 12;
    int minZ = center.getBlockZ() - 12;
    //Get the other corner
    int maxX = center.getBlockX() + 12;
    int maxY = center.getBlockY() + 12;
    int maxZ = center.getBlockZ() + 12;
    //Then you loop here and do your stuff
    Edit: The number should be 12, using 25 will get you a 51x51 cuboid.
  9. Offline


    So i have this:
    int minX = loc.getBlockX() - 25;
                            int minZ = loc.getBlockZ() - 25;
                            int maxX = loc.getBlockX() + 25;
                            int maxZ = loc.getBlockZ() + 25;
                            Location min = new Location(w, minX, loc.getBlockY(), minZ);
                            Location max = new Location(w, maxX, loc.getBlockY(), maxZ);
    Now how may i get all locations between the 2 locations i just defined?

    After that I can proceed xD
  10. Offline


    @DogeDebugger No no, just loop with the numbers and call World#getBlockAt(int, int, int)
  11. Offline


    for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
                            for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
                                for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
                                    Block blk = min.getWorld().getBlockAt(
                                            new Location(min.getWorld(), x, y, z));
                                    if(blk.getType().equals(Material.GOLD_BLOCK)) {
                                        Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Gold!");
                                        Location loc1 = blk.getLocation();
                                        p.sendMessage(ChatColor.GOLD + "" + loc1.getX() + ", " + loc1.getY() + ", " + loc1.getZ() + "");
                                        Location l = loc1.add(0, 30, 0);
                                        ParticleEffect.VILLAGER_HAPPY.display(l, 30, 0, 0, 0,
                                                10, 10);
            return false;       

    Ok, so i looped through the numbers and successfully got the blocks between them (thanks btw ^-^).

    This is supposed to see if any of the blocks are gold, and if they are, they spawn a 30 block beam of VILLAGER_HAPPY on them, and sends the block's locations to me. It all works except for the actual spawning of the beam, incorrect code to get it to work i guess?
  12. Offline


    @DogeDebugger Particles usually have a limit of render in the client (particles can't render too far), maybe this is the cause?

    Otherwise maybe the parameters that are passed to the ParticleEffect are wrong? I don't know.
  13. Offline


    Okay, I'll do some more research on that. I'm open for suggestions guys!
Thread Status:
Not open for further replies.

Share This Page