PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Ladder.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 
29 
30 class Ladder extends Transparent{
31 
32  protected $id = self::LADDER;
33 
34  public function __construct($meta = 0){
35  $this->meta = $meta;
36  }
37 
38  public function getName(){
39  return "Ladder";
40  }
41 
42  public function hasEntityCollision(){
43  return true;
44  }
45 
46  public function isSolid(){
47  return false;
48  }
49 
50  public function getHardness(){
51  return 2;
52  }
53 
54  public function onEntityCollide(Entity $entity){
55  $entity->fallDistance = 0;
56  $entity->onGround = true;
57  }
58 
59  protected function recalculateBoundingBox(){
60 
61  $f = 0.125;
62 
63  if($this->meta === 2){
64  return new AxisAlignedBB(
65  $this->x,
66  $this->y,
67  $this->z + 1 - $f,
68  $this->x + 1,
69  $this->y + 1,
70  $this->z + 1
71  );
72  }elseif($this->meta === 3){
73  return new AxisAlignedBB(
74  $this->x,
75  $this->y,
76  $this->z,
77  $this->x + 1,
78  $this->y + 1,
79  $this->z + $f
80  );
81  }elseif($this->meta === 4){
82  return new AxisAlignedBB(
83  $this->x + 1 - $f,
84  $this->y,
85  $this->z,
86  $this->x + 1,
87  $this->y + 1,
88  $this->z + 1
89  );
90  }elseif($this->meta === 5){
91  return new AxisAlignedBB(
92  $this->x,
93  $this->y,
94  $this->z,
95  $this->x + $f,
96  $this->y + 1,
97  $this->z + 1
98  );
99  }
100 
101  return null;
102  }
103 
104 
105  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
106  if($target->isTransparent() === false){
107  $faces = [
108  2 => 2,
109  3 => 3,
110  4 => 4,
111  5 => 5,
112  ];
113  if(isset($faces[$face])){
114  $this->meta = $faces[$face];
115  $this->getLevel()->setBlock($block, $this, true, true);
116 
117  return true;
118  }
119  }
120 
121  return false;
122  }
123 
124  public function onUpdate($type){
125  if($type === Level::BLOCK_UPDATE_NORMAL){
126  /*if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
127  Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
128  $this->getLevel()->setBlock($this, new Air(), true, true, true);
129  return Level::BLOCK_UPDATE_NORMAL;
130  }*/
131  }
132 
133  return false;
134  }
135 
136  public function getDrops(Item $item){
137  return [
138  [$this->id, 0, 1],
139  ];
140  }
141 }