Hey! I am trying to make a "FireBall" plugin which breaks the block that is aimed at by a player's crosshair. So I was wondering on how to get the block that player's crosshair is aiming, since I couldn't find anything related to this based on my search on forums and PocketMineMP github.
It's the cross symbol thingy you see when you turn on "split control" But you can see this as default when playing on win10 version
oh, cool now iknow Lol so what do you want to do? when you shoot fire ball\ snow ball with crsr (crosshair) do stuff?
use this function: PHP: public function onShoot(ProjectileHitBlockEvent $event) { //use custom name to this func$block = $event->getBlockHit(); //to get block hit$snow = $event->getEntity(); //to get entity => Snow/Fireball/Arrowif ($snow instanceof Snowball) { //to check if entity is snow bal and it isnt fire ball or arrow if ($block->getId() === Block::SNOW) { //check if Block hit is Snow //set it to AIR with $level->setBlock($block->x, $block->y, $block->z, Block::AIR); } }}//and DONE Solved?
You can get the block the player is looking at with $player->getTargetBlock(int $max_distance). In order to destroy it, use $player->getLevel()->setBlock($target_block, BlockFactory::get(BlockIds::AIR)).
Thank you both for your explanations! I was looking for the $player->getTargetBlock Thank you so much!