PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Villager.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 
24 
28 
29 class Villager extends Creature implements NPC, Ageable{
30  const PROFESSION_FARMER = 0;
31  const PROFESSION_LIBRARIAN = 1;
32  const PROFESSION_PRIEST = 2;
33  const PROFESSION_BLACKSMITH = 3;
34  const PROFESSION_BUTCHER = 4;
35  const PROFESSION_GENERIC = 5;
36 
37  const NETWORK_ID = 15;
38 
39  public $width = 0.6;
40  public $length = 0.6;
41  public $height = 1.8;
42 
43  public function getName(){
44  return "Villager";
45  }
46 
47  protected function initEntity(){
48  parent::initEntity();
49  if(!isset($this->namedtag->Profession)){
50  $this->setProfession(self::PROFESSION_GENERIC);
51  }
52  }
53 
54  public function spawnTo(Player $player){
55  $pk = new AddMobPacket();
56  $pk->eid = $this->getId();
57  $pk->type = Villager::NETWORK_ID;
58  $pk->x = $this->x;
59  $pk->y = $this->y;
60  $pk->z = $this->z;
61  $pk->yaw = $this->yaw;
62  $pk->pitch = $this->pitch;
63  $pk->metadata = $this->getData();
64  $player->dataPacket($pk);
65 
66  $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
67 
68  parent::spawnTo($player);
69  }
70 
71  public function getData(){ //TODO
72  $flags = 0;
73  $flags |= $this->fireTicks > 0 ? 1 : 0;
74  //$flags |= ($this->crouched === true ? 0b10:0) << 1;
75  //$flags |= ($this->inAction === true ? 0b10000:0);
76  $d = [
77  0 => ["type" => 0, "value" => $flags],
78  1 => ["type" => 1, "value" => $this->airTicks],
79  16 => ["type" => 0, "value" => 0],
80  17 => ["type" => 6, "value" => [0, 0, 0]],
81  ];
82 
83  return $d;
84  }
85 
91  public function setProfession($profession){
92  $this->namedtag->Profession = new Int("Profession", $profession);
93  }
94 
95  public function getProfession(){
96  return $this->namedtag["Profession"];
97  }
98 }
dataPacket(DataPacket $packet, $needACK=false)
Definition: Player.php:745
setProfession($profession)
Definition: Villager.php:91