Solved Checking Structures

Discussion in 'Plugin Development' started by TGRHavoc, Apr 15, 2014.

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

    TGRHavoc

    Is there a way to check if a certain structure exists?

    For example, is there a way to check if someone has built a simple house-like structure, and if they do... Send a message?
     
  2. Offline

    coasterman10

    You can try iterating over blocks and using an algorithm to determine whether the structure is a house. Note that continuous iteration would become extremely resource intensive, so you will need to be careful with when you're checking and the area over which you're checking. You also need to develop an algorithm for detecting the shape of blocks and seeing if they're like that of a building, which will not be terribly easy.
     
  3. Offline

    TGRHavoc

    coasterman10 Ok, thanks for the reply... Another question, how would I go about using iterators?
     
  4. Offline

    coasterman10

    I don't use Iterators very much, but the basic idea is that you would loop over an amount of blocks over the X, Y, and Z coordinates, something like this:
    Code:java
    1. for (int x = xMin; x <= xMax; x++) {
    2. for (int y = yMin; y <= yMax; y++) {
    3. for (int z = zMin; z <= zMax; z++) {
    4. // Check block at (x, y, z)
    5. }
    6. }
    7. }

    There is also a BlockIterator class which may or may not work more smoothly. I'm not experienced with using those.
     
  5. Offline

    TGRHavoc

    So, loop through all the blocks near the player (when they place a certain block) and use an algorithm to check if it resembles a house?
     
  6. Offline

    coasterman10

    That would work, the hardest part would probably be developing an algorithm to see if a structure resembles a house. Be warned though that this would probably also crash the server if there are multiple players building at once or placing lots of blocks. If the algorithm takes more than a tiny fraction of a tick to execute, you're in for trouble. Using NMS classes could speed up getting blocks a bit, but you should probably run it a different way, such as by command, or only run after they have not placed a block for several seconds, on a scheduled interval, etc.
     
  7. Offline

    TGRHavoc

    I was thinking more of checking when they place a special block that you wouldn't normally incorporate into a build (e.g. coal block).
    Anyways, thanks again for all your help :)
     
Thread Status:
Not open for further replies.

Share This Page