1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Checking corner block

Discussion in 'Development' started by Kenn Fatt, Apr 16, 2017.

  1. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    Hello everyone!

    I just create a function to check that block is in corner or not (true false).
    I was tried a method with checking (X + 1), (X - 1), (Z + 1), (Z - 1), but its not accurate, maybe my algorithm did it wrongly.

    this is my algo:
    PHP:
    public function isCorner(Block $b) : bool
      
    {
        
    $x = (int) $b->getX();
        
    $y = (int) $b->getY();
        
    $z = (int) $b->getZ();
        
    $l $b->getLevel();
        
    var_dump($x);
        
    var_dump($y);
        
    var_dump($z);
        
    $id $b->getId();
        if (
    $l->getBlockIdAt($x 1$y$z) == $id && $l->getBlockIdAt($x 1$y$z) !== $id) {
          echo 
    "if ke 1\n";
          if (
    $l->getBlockIdAt($x$y$z 1) == $id && $l->getBlockIdAt($x$y$z 1) !== $id) {
            return 
    true;
          } elseif (
    $l->getBlockIdAt($x$y$z 1) == $id && $l->getBlockIdAt($x$y$z 1) !== $id) {
            return 
    true;
          } else {
            return 
    false;
          }
        } elseif (
    $l->getBlockIdAt($x 1$y$z) == $id && $l->getBlockIdAt($x 1$y$z) !== $id) {
          echo 
    "if ke 2\n";
          if (
    $l->getBlockIdAt($x$y$z 1) == $id && $l->getBlockIdAt($x$y$z 1) !== $id) {
            return 
    true;
          } elseif (
    $l->getBlockIdAt($x$y$z 1) == $id && $l->getBlockIdAt($x$y$z 1) !== $id) {
            return 
    true;
          } else {
            return 
    false;
          }
        } else {
          echo 
    "if ke 3\n";
          return 
    false;
        }
      }
    when i debugging, all if are called (if ke 1, if ke 2, if ke 3) but always return to false.
    then i try other way, i use Block::getSide(); but im not sure if it can really works with.

    so please, tell me about Block::getSide() what is first parameter and second parameter for? or tell me what should i change from my code to get more accurate calculation.
     
  2. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    EDITED:

    okay i got it.
    PHP:
       const SIDE_DOWN 0;
       const 
    SIDE_UP 1;
       const 
    SIDE_NORTH 2;
       const 
    SIDE_SOUTH 3;
       const 
    SIDE_WEST 4;
       const 
    SIDE_EAST 5;
    so i need someone to explain where is my fault on my own function?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.