# Check if a something happened in a certain area

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

1. Offline

### BalAnceActive Member

Joined:
Mar 10, 2015
Posts:
125
Minecraft User:
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. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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. Offline

### aliulyNotable MemberPlugin Developer

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

### CreeperfaceNotable MemberPlugin Developer

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

### xpyctumActive MemberPlugin Developer

Joined:
Jan 13, 2014
Posts:
292
Plugins:
4
Minecraft User:
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. Offline

### CreeperfaceNotable MemberPlugin Developer

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

### aliulyNotable MemberPlugin 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.

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. Offline

### FalkStaff MemberGlobal Moderator

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

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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.