PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
FenceGate.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 FenceGate extends Transparent{
29 
30  protected $id = self::FENCE_GATE;
31 
32  public function __construct($meta = 0){
33  $this->meta = $meta;
34  }
35 
36  public function getName(){
37  return "Oak Fence Gate";
38  }
39 
40  public function getHardness(){
41  return 15;
42  }
43 
44  public function canBeActivated(){
45  return true;
46  }
47 
48 
49  protected function recalculateBoundingBox(){
50 
51  if(($this->getDamage() & 0x04) > 0){
52  return null;
53  }
54 
55  $i = ($this->getDamage() & 0x03);
56  if($i === 2 and $i === 0){
57  return new AxisAlignedBB(
58  $this->x,
59  $this->y,
60  $this->z + 0.375,
61  $this->x + 1,
62  $this->y + 1.5,
63  $this->z + 0.625
64  );
65  }else{
66  return new AxisAlignedBB(
67  $this->x + 0.375,
68  $this->y,
69  $this->z,
70  $this->x + 0.625,
71  $this->y + 1.5,
72  $this->z + 1
73  );
74  }
75  }
76 
77  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
78  $faces = [
79  0 => 3,
80  1 => 0,
81  2 => 1,
82  3 => 2,
83  ];
84  $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03;
85  $this->getLevel()->setBlock($block, $this, true, true);
86 
87  return true;
88  }
89 
90  public function getDrops(Item $item){
91  return [
92  [$this->id, 0, 1],
93  ];
94  }
95 
96  public function onActivate(Item $item, Player $player = null){
97  $faces = [
98  0 => 3,
99  1 => 0,
100  2 => 1,
101  3 => 2,
102  ];
103  $this->meta = ($faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03) | ((~$this->meta) & 0x04);
104  $this->getLevel()->setBlock($this, $this, true);
105 
106  return true;
107  }
108 }