PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Trapdoor.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 
27 
28 class Trapdoor extends Transparent{
29 
30  protected $id = self::TRAPDOOR;
31 
32  public function __construct($meta = 0){
33  $this->meta = $meta;
34  }
35 
36  public function getName(){
37  return "Trapdoor";
38  }
39 
40  public function getHardness(){
41  return 15;
42  }
43 
44  public function canBeActivated(){
45  return true;
46  }
47 
48  protected function recalculateBoundingBox(){
49 
50  $damage = $this->getDamage();
51 
52  $f = 0.1875;
53 
54  if(($damage & 0x08) > 0){
55  $bb = new AxisAlignedBB(
56  $this->x,
57  $this->y + 1 - $f,
58  $this->z,
59  $this->x + 1,
60  $this->y + 1,
61  $this->z + 1
62  );
63  }else{
64  $bb = new AxisAlignedBB(
65  $this->x,
66  $this->y,
67  $this->z,
68  $this->x + 1,
69  $this->y + $f,
70  $this->z + 1
71  );
72  }
73 
74  if(($damage & 0x04) > 0){
75  if(($damage & 0x03) === 0){
76  $bb->setBounds(
77  $this->x,
78  $this->y,
79  $this->z + 1 - $f,
80  $this->x + 1,
81  $this->y + 1,
82  $this->z + 1
83  );
84  }elseif(($damage & 0x03) === 1){
85  $bb->setBounds(
86  $this->x,
87  $this->y,
88  $this->z,
89  $this->x + 1,
90  $this->y + 1,
91  $this->z + $f
92  );
93  }
94  if(($damage & 0x03) === 2){
95  $bb->setBounds(
96  $this->x + 1 - $f,
97  $this->y,
98  $this->z,
99  $this->x + 1,
100  $this->y + 1,
101  $this->z + 1
102  );
103  }
104  if(($damage & 0x03) === 3){
105  $bb->setBounds(
106  $this->x,
107  $this->y,
108  $this->z,
109  $this->x + $f,
110  $this->y + 1,
111  $this->z + 1
112  );
113  }
114  }
115 
116  return $bb;
117  }
118 
119  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
120  if(($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1){
121  $faces = [
122  2 => 0,
123  3 => 1,
124  4 => 2,
125  5 => 3,
126  ];
127  $this->meta = $faces[$face] & 0x03;
128  if($fy > 0.5){
129  $this->meta |= 0x08;
130  }
131  $this->getLevel()->setBlock($block, $this, true, true);
132 
133  return true;
134  }
135 
136  return false;
137  }
138 
139  public function getDrops(Item $item){
140  return [
141  [$this->id, 0, 1],
142  ];
143  }
144 
145  public function onActivate(Item $item, Player $player = null){
146  $this->meta ^= 0x04;
147  $this->getLevel()->setBlock($this, $this, true);
148 
149  return true;
150  }
151 }