PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Slab.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 Slab extends Transparent{
29 
30  protected $id = self::SLAB;
31 
32  public function __construct($meta = 0){
33  $this->meta = $meta;
34  }
35 
36  public function getHardness(){
37  return 30;
38  }
39 
40  public function getName(){
41  static $names = [
42  0 => "Stone",
43  1 => "Sandstone",
44  2 => "Wooden",
45  3 => "Cobblestone",
46  4 => "Brick",
47  5 => "Stone Brick",
48  6 => "Quartz",
49  7 => "",
50  ];
51  return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
52  }
53 
54  protected function recalculateBoundingBox(){
55 
56  if(($this->meta & 0x08) > 0){
57  return new AxisAlignedBB(
58  $this->x,
59  $this->y + 0.5,
60  $this->z,
61  $this->x + 1,
62  $this->y + 1,
63  $this->z + 1
64  );
65  }else{
66  return new AxisAlignedBB(
67  $this->x,
68  $this->y,
69  $this->z,
70  $this->x + 1,
71  $this->y + 0.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  $this->meta &= 0x07;
79  if($face === 0){
80  if($target->getId() === self::SLAB and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
81  $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
82 
83  return true;
84  }elseif($block->getId() === self::SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
85  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
86 
87  return true;
88  }else{
89  $this->meta |= 0x08;
90  }
91  }elseif($face === 1){
92  if($target->getId() === self::SLAB and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
93  $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
94 
95  return true;
96  }elseif($block->getId() === self::SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
97  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
98 
99  return true;
100  }
101  //TODO: check for collision
102  }else{
103  if($block->getId() === self::SLAB){
104  if(($block->getDamage() & 0x07) === ($this->meta & 0x07)){
105  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
106 
107  return true;
108  }
109 
110  return false;
111  }else{
112  if($fy > 0.5){
113  $this->meta |= 0x08;
114  }
115  }
116  }
117 
118  if($block->getId() === self::SLAB and ($target->getDamage() & 0x07) !== ($this->meta & 0x07)){
119  return false;
120  }
121  $this->getLevel()->setBlock($block, $this, true, true);
122 
123  return true;
124  }
125 
126  public function getBreakTime(Item $item){
127 
128  switch($item->isPickaxe()){
129  case 5:
130  return 0.4;
131  case 4:
132  return 0.5;
133  case 3:
134  return 0.75;
135  case 2:
136  return 0.25;
137  case 1:
138  return 1.5;
139  default:
140  return 10;
141  }
142  }
143 
144  public function getDrops(Item $item){
145  if($item->isPickaxe() >= 1){
146  return [
147  [$this->id, $this->meta & 0x07, 1],
148  ];
149  }else{
150  return [];
151  }
152  }
153 }
static get($id, $meta=0, Position $pos=null)
Definition: Block.php:782