|
96 | 96 | use pocketmine\level\Level;
|
97 | 97 | use pocketmine\level\Location;
|
98 | 98 | use pocketmine\level\Position;
|
| 99 | +use pocketmine\level\sound\PlaySound; |
99 | 100 | use pocketmine\math\AxisAlignedBB;
|
100 | 101 | use pocketmine\math\Vector2;
|
101 | 102 | use pocketmine\math\Vector3;
|
|
114 | 115 | use pocketmine\network\mcpe\protocol\SetActorDataPacket;
|
115 | 116 | use pocketmine\network\mcpe\protocol\SetActorLinkPacket;
|
116 | 117 | use pocketmine\network\mcpe\protocol\SetActorMotionPacket;
|
| 118 | +use pocketmine\network\mcpe\protocol\StopSoundPacket; |
117 | 119 | use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
118 | 120 | use pocketmine\network\mcpe\protocol\types\EntityLink;
|
119 | 121 | use pocketmine\Player;
|
@@ -1615,34 +1617,24 @@ protected function broadcastMotion() : void{
|
1615 | 1617 | }
|
1616 | 1618 |
|
1617 | 1619 | /**
|
1618 |
| - * Pushes the this entity and other entity |
| 1620 | + * Pushes the other entity |
1619 | 1621 | *
|
1620 | 1622 | * @param Entity $entity
|
1621 | 1623 | */
|
1622 |
| - protected function applyEntityCollision(Entity $entity) : void{ |
1623 |
| - if($this->canBePushed() and !$this->isRiding() and !$entity->isRiding()){ |
1624 |
| - if(!($entity instanceof Player and $entity->isSpectator()) and !($this instanceof Player and $this->isSpectator())){ |
| 1624 | + public function applyEntityCollision(Entity $entity) : void{ |
| 1625 | + if(!$this->isRiding() and !$entity->isRiding()){ |
| 1626 | + if(!($entity instanceof Player and $entity->isSpectator())){ |
1625 | 1627 | $d0 = $entity->x - $this->x;
|
1626 | 1628 | $d1 = $entity->z - $this->z;
|
1627 | 1629 | $d2 = abs(max($d0, $d1));
|
1628 | 1630 |
|
1629 |
| - if($d2 >= 0.009){ |
| 1631 | + if($d2 > 0){ |
1630 | 1632 | $d2 = sqrt($d2);
|
1631 |
| - $d0 = $d0 / $d2; |
1632 |
| - $d1 = $d1 / $d2; |
1633 |
| - $d3 = 1 / $d2; |
| 1633 | + $d0 /= $d2; |
| 1634 | + $d1 /= $d2; |
| 1635 | + $d3 = min(1, 1 / $d2); |
1634 | 1636 |
|
1635 |
| - if($d3 > 1) $d3 = 1; |
1636 |
| - |
1637 |
| - $d0 = $d0 * $d3; |
1638 |
| - $d1 = $d1 * $d3; |
1639 |
| - $d0 = $d0 * 0.05; |
1640 |
| - $d1 = $d1 * 0.05; |
1641 |
| - $d0 = $d0 * (1 - $this->entityCollisionReduction); |
1642 |
| - $d1 = $d1 * (1 - $this->entityCollisionReduction); |
1643 |
| - |
1644 |
| - $this->motion = $this->motion->subtract($d0, 0, $d1); |
1645 |
| - $entity->motion = $entity->motion->add($d0, 0, $d1); |
| 1637 | + $entity->setMotion($entity->getMotion()->add($d0 * $d3 * 0.05, 0, $d1 * $d3 * 0.05)); |
1646 | 1638 | }
|
1647 | 1639 | }
|
1648 | 1640 | }
|
@@ -2136,7 +2128,9 @@ public function onCollideWithPlayer(Player $player) : void{
|
2136 | 2128 | }
|
2137 | 2129 |
|
2138 | 2130 | public function onCollideWithEntity(Entity $entity) : void{
|
2139 |
| - $entity->applyEntityCollision($this); |
| 2131 | + if($entity->canBePushed()){ |
| 2132 | + $this->applyEntityCollision($entity); |
| 2133 | + } |
2140 | 2134 | }
|
2141 | 2135 |
|
2142 | 2136 | public function isUnderwater() : bool{
|
@@ -2439,10 +2433,8 @@ protected function checkBlockCollision() : void{
|
2439 | 2433 | }
|
2440 | 2434 |
|
2441 | 2435 | protected function checkEntityCollision() : void{
|
2442 |
| - if($this->canBePushed()){ |
2443 |
| - foreach($this->level->getCollidingEntities($this->getBoundingBox()->expandedCopy(0.2, 0, 0.2), $this) as $e){ |
2444 |
| - $this->onCollideWithEntity($e); |
2445 |
| - } |
| 2436 | + foreach($this->level->getCollidingEntities($this->getBoundingBox()->expandedCopy(0.2, 0, 0.2), $this) as $e){ |
| 2437 | + $this->onCollideWithEntity($e); |
2446 | 2438 | }
|
2447 | 2439 | }
|
2448 | 2440 |
|
@@ -2570,6 +2562,29 @@ public function addMotion(float $x, float $y, float $z) : void{
|
2570 | 2562 | $this->motion->z += $z;
|
2571 | 2563 | }
|
2572 | 2564 |
|
| 2565 | + /** |
| 2566 | + * @param string $sound |
| 2567 | + * @param float $volume |
| 2568 | + * @param float $pitch |
| 2569 | + * @param array|null $targets |
| 2570 | + */ |
| 2571 | + public function playSound(string $sound, float $volume = 1.0, float $pitch = 1.0, array $targets = null) : void{ |
| 2572 | + $this->level->addSound(new PlaySound($this, $sound, $volume, $pitch), $targets ?? null); |
| 2573 | + } |
| 2574 | + |
| 2575 | + /** |
| 2576 | + * @param string $sound |
| 2577 | + * @param bool $stopAll |
| 2578 | + * @param array|null $targets |
| 2579 | + */ |
| 2580 | + public function stopSound(string $sound, bool $stopAll = false, array $targets = null) : void{ |
| 2581 | + $pk = new StopSoundPacket(); |
| 2582 | + $pk->soundName = $sound; |
| 2583 | + $pk->stopAll = $stopAll; |
| 2584 | + |
| 2585 | + $this->server->broadcastPacket($targets ?? $this->level->getViewersForPosition($this), $pk); |
| 2586 | + } |
| 2587 | + |
2573 | 2588 | public function isOnGround() : bool{
|
2574 | 2589 | return $this->onGround;
|
2575 | 2590 | }
|
|
0 commit comments