Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

The best way to check area collision

Comments in 'Plugin Development' started by Creeperface, Jun 13, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i tried to make some code to check area collision and i made this:
    PHP:
    public function checkCollision($loc1$loc2Level $level){
            
    $res = new Config($this->plugin->getDataFolder()."res_".$level->getName());
            
    $residences $res->getAll();
            
    $y min($loc1->y$loc2->y);
            
    $z min($loc1->y$loc2->y);
                for(
    $x min($loc1->x$loc2->x); $x != max($loc1->x$loc2->x); $x++){
                    foreach(
    $residences["Residences"] as $r){
                        if((
    min($r["Area"]["X1"], $r["Area"]["X2"]) <= $x) && (max($r["Area"]["X1"], $r["Area"]["X2"]) >= $x) && (min($r["Area"]["Y1"], $r["Area"]["Y2"]) <= $y) && (max($r["Area"]["Y1"], $r["Area"]["Y2"]) >= $y) && (min($r["Area"]["Z1"], $r["Area"]["Z2"]) <= $z) && (max($r["Area"]["X1"], $r["Area"]["X2"]) >= $z)){
                            return 
    true;
                        }
                    }
                    if(
    $y == max($loc1->y$loc2->y) && $x == max($loc1->x$loc2->x) && $z == max($loc1->z$loc2->z)){
                        break;
                    }
                    if(
    $x == max($loc1->x$loc2->x)){
                        if(
    $z == max($loc1->z$loc2->z)){
                            
    $y++;
                            
    $x min($loc1->x$loc2->x);
                            
    $z min($loc1->z$loc2->z);
                        }
                        else{
                            
    $x min($loc1->x$loc2->x);
                            
    $z++;
                        }
                    }
                }
        }
    but it check all blocks from selected area with all other residences and i think it is not good way.
    $loc1 and $loc2 are corners of the selected area.
    So have somebody better idea?
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    THX and some example please?

Share This Page

Advertisement