Solved Get each location in a radius/shape

Discussion in 'Spigot Plugin Development' started by Wilsoon, Mar 20, 2020.

Thread Status:
Not open for further replies.
  1. Sometimes I would want something to grab each block/location around the player's location like in a circle like thing.
    Something like getting the player's location then getting each of the locations relative to the player's location:
    Shown in the attachment (getting each location of stone), then doing something with these locations such as striking a lightning bolt, is there an easier way of doing this or must I do it manually?
  2. Maths.
  3. drives_a_ford


    If you just want the surface blocks around a player this is rather straight forward.

    Say you want the surface blocks within radius r.
    You get the center's x coordinate xc, iterate from x = xc-r to xc+r (inclusive).
    You get the center's z coordinate zc, iterate from z = zc-r to zc+r (inclusive).
    Within the two nested loops, you make sure the block is within the radius ((xc - x) * (xc - x) + (zc - z) * (zc - z) <= r * r).
    If it is, then World#getHighestBlockAt at the x and z and do with it what you please.

    PS: What I described will catch blocks within a circular radius of the player, but always the highest blocks. So this will not work under ground or under cliffs and such.
  4. When I create circles with integers as radius I personally like to add 0.25 to the radius. That will not make the circles any bigger but it gives them a smother look in Minecraft imo.
  5. I haven't really done much with the Math part of Java since I really can't remember any of the things what it does (abs, round, etc.) so I am unable to understand what any of y'all said. Can I get just a quick code example or a better explanation?
  6. I think @drives_a_ford gave a rather simple explanation on how to create a code that solves your question. If you don’t want to follow instructions like these you will have a difficult time getting help for any kind of code problem.

    I‘d suggest you to rather ask questions about the parts you don’t understand.
  7. This is mainly what I don't get. How would the nested for loops look like?
  8. drives_a_ford


    One loop inside another...
    This is really basic stuff...
  9. Ok, I got it.
Thread Status:
Not open for further replies.