PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Arrow.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\entity;
23 
28 
29 class Arrow extends Projectile{
30  const NETWORK_ID = 80;
31 
32  public $width = 0.5;
33  public $length = 0.5;
34  public $height = 0.5;
35 
36  protected $gravity = 0.05;
37  protected $drag = 0.01;
38 
39  protected $damage = 6;
40 
41  public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null){
42  $this->shootingEntity = $shootingEntity;
43  parent::__construct($chunk, $nbt);
44  }
45 
46  public function onUpdate($currentTick){
47  if($this->closed){
48  return false;
49  }
50 
51  $this->timings->startTiming();
52 
53  $hasUpdate = parent::onUpdate($currentTick);
54 
55  if($this->age > 1200){
56  $this->kill();
57  $hasUpdate = true;
58  }
59 
60  $this->timings->stopTiming();
61 
62  return $hasUpdate;
63  }
64 
65  public function spawnTo(Player $player){
66  $pk = new AddEntityPacket();
67  $pk->type = Arrow::NETWORK_ID;
68  $pk->eid = $this->getId();
69  $pk->x = $this->x;
70  $pk->y = $this->y;
71  $pk->z = $this->z;
72  $pk->did = 0; //TODO: send motion here
73  $player->dataPacket($pk);
74 
75  $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
76 
77  parent::spawnTo($player);
78  }
79 }
dataPacket(DataPacket $packet, $needACK=false)
Definition: Player.php:745