Check fences to one direction

Discussion in 'Plugin Development' started by FabioZumbi12, Nov 30, 2015.

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

    FabioZumbi12

    Hello,

    I developing a plugin and i need to make a loop on all fences to check if this fences are a retangle or square.

    I need to check to make this valid:
    [​IMG]

    And this invalid:
    [​IMG]

    Basicly, i need to check if the fences only go to front and right, or go to back and left, not to front and both directions.

    I tryed this:
    Code:
    for (int bi = 0; bi < block.size(); ++bi) {
                        BlockFace backface = current.getFace(block[bi]);
                        BlockFace currface = block[bi].getFace(current);
                        if (currface.equals(BlockFace.UP) || currface.equals(BlockFace.DOWN) ||
                                (currface.equals(BlockFace.EAST) && backface.equals(BlockFace.WEST)) ||
                                (currface.equals(BlockFace.NORTH) && backface.equals(BlockFace.SOUTH)) ||
                                (currface.equals(BlockFace.WEST) && backface.equals(BlockFace.EAST)) ||
                                (currface.equals(BlockFace.SOUTH) && backface.equals(BlockFace.NORTH)) ||
                                //curvas
                                (currface.equals(BlockFace.WEST) && backface.equals(BlockFace.NORTH)) ||
                                (currface.equals(BlockFace.EAST) && backface.equals(BlockFace.NORTH)) ||
                                (currface.equals(BlockFace.SOUTH) && backface.equals(BlockFace.EAST)) ||
                                (currface.equals(BlockFace.WEST) && backface.equals(BlockFace.SOUTH))
                                ){
                           ...
                          loop continues...
                          ...
                        } else {
                            seterror("Need to be a square!")
                            break;
                        }
    }
    But always is valid :/
     
  2. Offline

    mythbusterma

    @FabioZumbi12

    That logic looks awful, to be honest.

    Use a simple state machine, start at one corner, then check if it's the correct direction, or the only valid turn for that direction.
     
  3. Offline

    FabioZumbi12

    Yes, is awlful because i have no ideia on how to do.

    The "block" is a "Block[]" with all fences from a other scan from last block to next block.

    I know the fences have two faces, the back and front, but how to check if the front block(following direction of loop) isn't a fence and then, check to the +90 degrees to get another block and validade as fence?
     
  4. Offline

    Scimiguy

    It's just a bit of logic with some looping that you need.

    If you can't figure out how to handle it yourself, you could consider submitting a plugin request instead

    Otherwise, maybe take a look at a Wall Follower algorithm, might be a good start
     
  5. Offline

    mcdorli

    1.: Create a while loop. Loop trough all the block in one direction, until it is air or not a fence, always check for fences in the other directions, stop if there are.
    2.: Once you got to a corner, turn around, and store somehow the next direction you need to go.
    3.: Repeat the first 2 points, until you get back to the original position, if the fence turns too much, or it turns in a wrong direction, then end the cycle.
    It's not that hard.
     
  6. Offline

    FabioZumbi12

    But theres a code example to Loop and get the fences only for -> direction and for <- direction?
     
  7. Offline

    mcdorli

    We won't provide code here, and I don't think there would be.
     
Thread Status:
Not open for further replies.

Share This Page