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

@ -31,7 +31,6 @@ use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
@ -136,13 +135,13 @@ abstract class Projectile extends Entity{
}
$axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3);
$ob = $axisalignedbb->calculateIntercept($this, $moveVector);
$rayTraceResult = $axisalignedbb->calculateIntercept($this, $moveVector);
if($ob === null){
if($rayTraceResult === null){
continue;
}
$distance = $this->distanceSquared($ob->hitVector);
$distance = $this->distanceSquared($rayTraceResult->hitVector);
if($distance < $nearDistance){
$nearDistance = $distance;
@ -151,14 +150,8 @@ abstract class Projectile extends Entity{
}
if($nearEntity !== null){
$movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity);
}
if($movingObjectPosition !== null){
if($movingObjectPosition->entityHit !== null){
$this->onCollideWithEntity($movingObjectPosition->entityHit);
return false;
}
$this->onCollideWithEntity($nearEntity);
return false;
}
if($this->isCollided and !$this->hadCollision){ //Collided with a block