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

Check if a something happened in a certain area

Comments in 'Plugin Development' started by BalAnce, Jun 23, 2015.

  1. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Say i have two points that make a cuboid. How could i tell if lets say a block broke inside the cuboid. I know like how to get the cordiate of the block but im asking how to check if inside of the range if that makes sense. Thanks in advance! :)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Say first coordinate is new Vector3(11, 22, 33)
    Second coordinate is new Vector3(33, 11, 22)
    These are the two points that make a cuboid.
    To check if new Vector3(20, 20, 30) is inside it:
    PHP:
    $a = new Vector3(112233);
    $b = new Vector3(331122);
    $toCheck = new Vector3(202020);
    $isInside =
        
    min($first->x$second->x) <= $toCheck->and
        
    max($first->x$second->x) >= $toCheck->and
        
    min($first->y$second->y) <= $toCheck->and
        
    max($first->y$second->y) >= $toCheck->and
        
    min($first->z$second->z) <= $toCheck->and
        
    max($first->z$second->z) >= $toCheck->z;
    BalAnce likes this.
  3. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    The other option is to use AxisAlignedBB.
    Falk likes this.
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    what is better axisAligned or PEMapModde┬┤s way?
  5. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    PHP:
    //AxisAlignedBB
    public function __construct($minX$minY$minZ$maxX$maxY$maxZ){
    $this->minX $minX;
    $this->minY $minY;
    $this->minZ $minZ;
    $this->maxX $maxX;
    $this->maxY $maxY;
    $this->maxZ $maxZ;
    }
    //and checking
    public function isVectorInside(Vector3 $vector){
    if(
    $vector-><= $this->minX or $vector->>= $this->maxX){
    return 
    false;
    }
    if(
    $vector-><= $this->minY or $vector->>= $this->maxY){
    return 
    false;
    }
    return 
    $vector->$this->minZ and $vector->$this->maxZ;
    }

  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    My view is whenever you can use an api function vs writing your own I would choose the api.

    It is advantages:

    You don't need to write it. Somebody else's doing it for you. Other people reading your code would know what you are doing. You don't need to debug it. Etc.
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    And it has extra abstraction meaning that the API can be changed drastically and your plugin will still function.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    My view is, for these purely calculated stuff, implementing it may optimize your plugin as you are only using the minimal execution required, instead of in APIs that may change in a backwards-compatible way such that it takes extra time to ensure backwards compatibility.

Share This Page

Advertisement