mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 00:59:51 +00:00
Ring bell when hit by a projectile (#5505)
This commit is contained in:
parent
0f81b7be15
commit
5226300b99
@ -29,9 +29,11 @@ use pocketmine\block\utils\HorizontalFacingTrait;
|
|||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataReader;
|
use pocketmine\data\runtime\RuntimeDataReader;
|
||||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||||
|
use pocketmine\entity\projectile\Projectile;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
@ -134,14 +136,7 @@ final class Bell extends Transparent{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$faceHit = Facing::opposite($player->getHorizontalFacing());
|
$faceHit = Facing::opposite($player->getHorizontalFacing());
|
||||||
if(
|
if($this->isValidFaceToRing($faceHit)){
|
||||||
$this->attachmentType->equals(BellAttachmentType::CEILING()) ||
|
|
||||||
($this->attachmentType->equals(BellAttachmentType::FLOOR()) && Facing::axis($faceHit) === Facing::axis($this->facing)) ||
|
|
||||||
(
|
|
||||||
($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) || $this->attachmentType->equals(BellAttachmentType::TWO_WALLS())) &&
|
|
||||||
($faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true))
|
|
||||||
)
|
|
||||||
){
|
|
||||||
$this->ring($faceHit);
|
$this->ring($faceHit);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -150,6 +145,13 @@ final class Bell extends Transparent{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
|
||||||
|
$faceHit = Facing::opposite($projectile->getHorizontalFacing());
|
||||||
|
if($this->isValidFaceToRing($faceHit)){
|
||||||
|
$this->ring($faceHit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function ring(int $faceHit) : void{
|
public function ring(int $faceHit) : void{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
$world->addSound($this->position, new BellRingSound());
|
$world->addSound($this->position, new BellRingSound());
|
||||||
@ -158,4 +160,15 @@ final class Bell extends Transparent{
|
|||||||
$world->broadcastPacketToViewers($this->position, $tile->createFakeUpdatePacket($faceHit));
|
$world->broadcastPacketToViewers($this->position, $tile->createFakeUpdatePacket($faceHit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isValidFaceToRing(int $faceHit) : bool{
|
||||||
|
return (
|
||||||
|
$this->attachmentType->equals(BellAttachmentType::CEILING()) ||
|
||||||
|
($this->attachmentType->equals(BellAttachmentType::FLOOR()) && Facing::axis($faceHit) === Facing::axis($this->facing)) ||
|
||||||
|
(
|
||||||
|
($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) || $this->attachmentType->equals(BellAttachmentType::TWO_WALLS())) &&
|
||||||
|
($faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user