Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Arrow and bow

Comments in 'Plugin Development' started by TheMaks, Oct 29, 2015.

  1. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    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 ,:please , please help me ))
  2. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Listen to ProjectileHitEvent and check that the Projectile is an Arrow instance and then find the Player.
    iDirtPlayzMC likes this.
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    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
    CrazedMiner likes this.
  4. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    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.
  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    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);
                }
            }
        }
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    CrazedMiner likes this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    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);
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The problem is, it is really inefficient to calculate it twice.
  9. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Why does my minecraft pe stop when i touch arrow on my server??
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder

Share This Page

Advertisement