Add a hook to enable blocks to react to projectiles colliding with them

this enables implementing blocks such as the target block.
This commit is contained in:
Dylan K. Taylor 2022-07-07 01:44:13 +01:00
parent 3e4f01d85e
commit c67e42a723
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 9 additions and 0 deletions

View File

@ -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[]
*/

View File

@ -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);
}
}