PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Vine.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\block;
23 
30 
31 class Vine extends Transparent{
32 
33  protected $id = self::VINE;
34 
35  public function __construct($meta = 0){
36  $this->meta = $meta;
37  }
38 
39  public function isSolid(){
40  return false;
41  }
42 
43  public function getName(){
44  return "Vines";
45  }
46 
47  public function getHardness(){
48  return 1;
49  }
50 
51  public function hasEntityCollision(){
52  return true;
53  }
54 
55  public function onEntityCollide(Entity $entity){
56  $entity->fallDistance = 0;
57  }
58 
59  protected function recalculateBoundingBox(){
60 
61  $f1 = 1;
62  $f2 = 1;
63  $f3 = 1;
64  $f4 = 0;
65  $f5 = 0;
66  $f6 = 0;
67 
68  $flag = $this->meta > 0;
69 
70  if(($this->meta & 0x02) > 0){
71  $f4 = max($f4, 0.0625);
72  $f1 = 0;
73  $f2 = 0;
74  $f5 = 1;
75  $f3 = 0;
76  $f6 = 1;
77  $flag = true;
78  }
79 
80  if(($this->meta & 0x08) > 0){
81  $f1 = min($f1, 0.9375);
82  $f4 = 1;
83  $f2 = 0;
84  $f5 = 1;
85  $f3 = 0;
86  $f6 = 1;
87  $flag = true;
88  }
89 
90  if(($this->meta & 0x01) > 0){
91  $f3 = min($f3, 0.9375);
92  $f6 = 1;
93  $f1 = 0;
94  $f4 = 1;
95  $f2 = 0;
96  $f5 = 1;
97  $flag = true;
98  }
99 
100  if(!$flag and $this->getSide(1)->isSolid()){
101  $f2 = min($f2, 0.9375);
102  $f5 = 1;
103  $f1 = 0;
104  $f4 = 1;
105  $f3 = 0;
106  $f6 = 1;
107  }
108 
109  return new AxisAlignedBB(
110  $this->x + $f1,
111  $this->y + $f2,
112  $this->z + $f3,
113  $this->x + $f4,
114  $this->y + $f5,
115  $this->z + $f6
116  );
117  }
118 
119 
120  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
121  if($target->isSolid()){
122  $faces = [
123  0 => 0,
124  1 => 0,
125  2 => 1,
126  3 => 4,
127  4 => 8,
128  5 => 2,
129  ];
130  if(isset($faces[$face])){
131  $this->meta = $faces[$face];
132  $this->getLevel()->setBlock($block, $this, true, true);
133 
134  return true;
135  }
136  }
137 
138  return false;
139  }
140 
141  public function getBreakTime(Item $item){
142  if($item->isShears()){
143  return 0.02;
144  }elseif($item->isSword()){
145  return 0.2;
146  }elseif($item->isAxe()){
147  switch($item->isAxe()){
148  case Tool::TIER_WOODEN:
149  return 0.15;
150  case Tool::TIER_STONE:
151  return 0.075;
152  case Tool::TIER_IRON:
153  return 0.05;
154  case Tool::TIER_DIAMOND:
155  return 0.0375;
156  case Tool::TIER_GOLD:
157  return 0.025;
158  }
159  }
160 
161  return 0.3;
162  }
163 
164  public function onUpdate($type){
165  if($type === Level::BLOCK_UPDATE_NORMAL){
166  /*if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
167  Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
168  $this->getLevel()->setBlock($this, new Air(), true, true, true);
169  return Level::BLOCK_UPDATE_NORMAL;
170  }*/
171  }
172 
173  return false;
174  }
175 
176  public function getDrops(Item $item){
177  if($item->isShears()){
178  return [
179  [$this->id, 0, 1],
180  ];
181  }else{
182  return [];
183  }
184  }
185 }
getSide($side, $step=1)
Definition: Block.php:1028