Math: Added RayTraceResult, removed dependence on MovingObjectPosition

MOP doesn't make any sense anyway.

RayTraceResult is a container which represents the point at which a line hits a bounding box. No dependence on blocks or entities is wanted or needed.
MovingObjectPosition has API changes to allow it to wrap RayTraceResult, but nothing uses MOP anymore anyway.

This would allow modularisation of the pocketmine\\math namespace.
This commit is contained in:
Dylan K. Taylor
2018-01-12 14:28:41 +00:00
parent fe4b5498e6
commit 45b02d92d4
5 changed files with 109 additions and 66 deletions

View File

@ -30,9 +30,9 @@ use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
@ -615,15 +615,15 @@ class Block extends Position implements BlockIds, Metadatable{
* @param Vector3 $pos1
* @param Vector3 $pos2
*
* @return MovingObjectPosition|null
* @return RayTraceResult|null
*/
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2) : ?MovingObjectPosition{
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2) : ?RayTraceResult{
$bbs = $this->getCollisionBoxes();
if(empty($bbs)){
return null;
}
/** @var MovingObjectPosition|null $currentHit */
/** @var RayTraceResult|null $currentHit */
$currentHit = null;
/** @var int|float $currentDistance */
$currentDistance = PHP_INT_MAX;
@ -641,12 +641,6 @@ class Block extends Position implements BlockIds, Metadatable{
}
}
if($currentHit !== null){
$currentHit->blockX = $this->x;
$currentHit->blockY = $this->y;
$currentHit->blockZ = $this->z;
}
return $currentHit;
}