From c67e42a723310a8959117dee7dd9b2cb58d3c3bb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 7 Jul 2022 01:44:13 +0100 Subject: [PATCH] Add a hook to enable blocks to react to projectiles colliding with them this enables implementing blocks such as the target block. --- src/block/Block.php | 8 ++++++++ src/entity/projectile/Projectile.php | 1 + 2 files changed, 9 insertions(+) diff --git a/src/block/Block.php b/src/block/Block.php index cddfe0440..38abcfb4f 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -32,6 +32,7 @@ use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; +use pocketmine\entity\projectile\Projectile; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; use pocketmine\item\ItemBlock; @@ -626,6 +627,13 @@ class Block{ return null; } + /** + * Called when a projectile collides with one of this block's collision boxes. + */ + public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ + //NOOP + } + /** * @return AxisAlignedBB[] */ diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 41c5aa4cf..74bb5a0a2 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -306,5 +306,6 @@ abstract class Projectile extends Entity{ */ protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{ $this->blockHit = $blockHit->getPosition()->asVector3(); + $blockHit->onProjectileHit($this, $hitResult); } }