Hello, I make it very important for me, the mini game, and ask adequate assistance. How to get the coordinates of the block in which the player hit with an arrow? Please help, I will be very grateful Please ,lease , please help me ))
Listen to ProjectileHitEvent and check that the Projectile is an Arrow instance and then find the Player.
But ProjectileHitEvent does not seem to provide a way to get what the arrow hit? http://jenkins.pocketmine.net/job/P...event_1_1entity_1_1_projectile_hit_event.html You might want to listen to EntityDamageEvent, then check if instanceof EntityDamageByEntityEvent then check if $event->getDamager() is instanceof Arrow and $event->getEntity is instanceof Player
Checking if the damager is an arrow is harder than you think. He also wanted to check the block and to do that you can simply take 1 away from the y of the arrow and check it for a block.
PHP: public function onEntityDamage(EntityDamageEvent $event){ $p = $event->getEntity(); if($p instanceof Player && $event instanceof EntityDamageByEntityEvent){ $dmg = $event->getDamager(); if($dmg instanceof Arrow){ $block = $p->getLevel()->getBlock($p); } } }
But what if arrow hit wall horizontaly? PHP: $shooter = $arrow->shootingEntity;if($shooter instanceof Player){ # Check, because shooter could be any other mob, or no shooter at all} And for block where arrow hits use trygonometry. PHP: $y = -sin(deg2rad($arrow->lastPitch));$xz = cos(deg2rad($this->lastPitch));$x = -$xz * sin(deg2rad($this->lastYaw));$z = $xz * cos(deg2rad($this->lastYaw));$pos = $this->temporalVector->setComponents($x, $y, $z)->normalize();$block = $arrow->getLevel()->getBlock($pos);
Try using this patch. https://github.com/hmy2001/PocketMine-MP/tree/e1ba8333065f94460b2d4133986a1c22348b81fc