mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Projectile: clean up dodgy code
This commit is contained in:
parent
847ae26cad
commit
b3f15435cc
@ -44,7 +44,6 @@ use pocketmine\nbt\tag\CompoundTag;
|
|||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use function assert;
|
|
||||||
use function atan2;
|
use function atan2;
|
||||||
use function ceil;
|
use function ceil;
|
||||||
use function count;
|
use function count;
|
||||||
@ -170,8 +169,6 @@ abstract class Projectile extends Entity{
|
|||||||
$start = $this->location->asVector3();
|
$start = $this->location->asVector3();
|
||||||
$end = $start->add($dx, $dy, $dz);
|
$end = $start->add($dx, $dy, $dz);
|
||||||
|
|
||||||
$blockHit = null;
|
|
||||||
$entityHit = null;
|
|
||||||
$hitResult = null;
|
$hitResult = null;
|
||||||
|
|
||||||
$world = $this->getWorld();
|
$world = $this->getWorld();
|
||||||
@ -181,8 +178,7 @@ abstract class Projectile extends Entity{
|
|||||||
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
|
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
|
||||||
if($blockHitResult !== null){
|
if($blockHitResult !== null){
|
||||||
$end = $blockHitResult->hitVector;
|
$end = $blockHitResult->hitVector;
|
||||||
$blockHit = $block;
|
$hitResult = [$block, $blockHitResult];
|
||||||
$hitResult = $blockHitResult;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,8 +202,7 @@ abstract class Projectile extends Entity{
|
|||||||
|
|
||||||
if($distance < $entityDistance){
|
if($distance < $entityDistance){
|
||||||
$entityDistance = $distance;
|
$entityDistance = $distance;
|
||||||
$entityHit = $entity;
|
$hitResult = [$entity, $entityHitResult];
|
||||||
$hitResult = $entityHitResult;
|
|
||||||
$end = $entityHitResult->hitVector;
|
$end = $entityHitResult->hitVector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,26 +218,18 @@ abstract class Projectile extends Entity{
|
|||||||
$this->recalculateBoundingBox();
|
$this->recalculateBoundingBox();
|
||||||
|
|
||||||
if($hitResult !== null){
|
if($hitResult !== null){
|
||||||
/** @var ProjectileHitEvent|null $ev */
|
[$objectHit, $rayTraceResult] = $hitResult;
|
||||||
$ev = null;
|
if($objectHit instanceof Entity){
|
||||||
if($entityHit !== null){
|
$ev = new ProjectileHitEntityEvent($this, $rayTraceResult, $objectHit);
|
||||||
$ev = new ProjectileHitEntityEvent($this, $hitResult, $entityHit);
|
$specificHitFunc = fn() => $this->onHitEntity($objectHit, $rayTraceResult);
|
||||||
}elseif($blockHit !== null){
|
|
||||||
$ev = new ProjectileHitBlockEvent($this, $hitResult, $blockHit);
|
|
||||||
}else{
|
}else{
|
||||||
assert(false, "unknown hit type");
|
$ev = new ProjectileHitBlockEvent($this, $rayTraceResult, $objectHit);
|
||||||
|
$specificHitFunc = fn() => $this->onHitBlock($objectHit, $rayTraceResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ev !== null){
|
$ev->call();
|
||||||
$ev->call();
|
$this->onHit($ev);
|
||||||
$this->onHit($ev);
|
$specificHitFunc();
|
||||||
|
|
||||||
if($ev instanceof ProjectileHitEntityEvent){
|
|
||||||
$this->onHitEntity($ev->getEntityHit(), $ev->getRayTraceResult());
|
|
||||||
}elseif($ev instanceof ProjectileHitBlockEvent){
|
|
||||||
$this->onHitBlock($ev->getBlockHit(), $ev->getRayTraceResult());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->isCollided = $this->onGround = true;
|
$this->isCollided = $this->onGround = true;
|
||||||
$this->motion = Vector3::zero();
|
$this->motion = Vector3::zero();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user