PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Zombie.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 
26 use pocketmine\item\Item as ItemItem;
29 
30 class Zombie extends Monster{
31  const NETWORK_ID = 32;
32 
33  public $width = 0.6;
34  public $length = 0.6;
35  public $height = 1.8;
36 
37  public function getName(){
38  return "Zombie";
39  }
40 
41  public function spawnTo(Player $player){
42 
43  $pk = new AddMobPacket();
44  $pk->eid = $this->getId();
45  $pk->type = Zombie::NETWORK_ID;
46  $pk->x = $this->x;
47  $pk->y = $this->y;
48  $pk->z = $this->z;
49  $pk->yaw = $this->yaw;
50  $pk->pitch = $this->pitch;
51  $pk->metadata = $this->getData();
52  $player->dataPacket($pk);
53 
54  $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
55 
56  parent::spawnTo($player);
57  }
58 
59  public function getData(){ //TODO
60  $flags = 0;
61  $flags |= $this->fireTicks > 0 ? 1 : 0;
62  //$flags |= ($this->crouched === true ? 0b10:0) << 1;
63  //$flags |= ($this->inAction === true ? 0b10000:0);
64  $d = [
65  0 => ["type" => 0, "value" => $flags],
66  1 => ["type" => 1, "value" => $this->airTicks],
67  16 => ["type" => 0, "value" => 0],
68  17 => ["type" => 6, "value" => [0, 0, 0]],
69  ];
70 
71  return $d;
72  }
73 
74  public function getDrops(){
75  $drops = [
76  ItemItem::get(ItemItem::FEATHER, 0, 1)
77  ];
78  if($this->lastDamageCause instanceof EntityDamageByEntityEvent and $this->lastDamageCause->getEntity() instanceof Player){
79  if(mt_rand(0, 199) < 5){
80  switch(mt_rand(0, 2)){
81  case 0:
82  $drops[] = ItemItem::get(ItemItem::IRON_INGOT, 0, 1);
83  break;
84  case 1:
85  $drops[] = ItemItem::get(ItemItem::CARROT, 0, 1);
86  break;
87  case 2:
88  $drops[] = ItemItem::get(ItemItem::POTATO, 0, 1);
89  break;
90  }
91  }
92  }
93 
94  return $drops;
95  }
96 }
dataPacket(DataPacket $packet, $needACK=false)
Definition: Player.php:745