PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
WoodSlab.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 WoodSlab extends Transparent{
29 
30  protected $id = self::WOOD_SLAB;
31 
32  public function __construct($meta = 0){
33  $this->meta = $meta;
34  }
35 
36  public function getHardness(){
37  return 15;
38  }
39 
40  public function getName(){
41  static $names = [
42  0 => "Oak",
43  1 => "Spruce",
44  2 => "Birch",
45  3 => "Jungle",
46  4 => "Acacia",
47  5 => "Dark Oak",
48  6 => "",
49  7 => ""
50  ];
51  return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Wooden 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::WOOD_SLAB and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
81  $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
82 
83  return true;
84  }elseif($block->getId() === self::WOOD_SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
85  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
86 
87  return true;
88  }else{
89  $this->meta |= 0x08;
90  }
91  }elseif($face === 1){
92  if($target->getId() === self::WOOD_SLAB and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
93  $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
94 
95  return true;
96  }elseif($block->getId() === self::WOOD_SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
97  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
98 
99  return true;
100  }
101  }else{ //TODO: collision
102  if($block->getId() === self::WOOD_SLAB){
103  if(($block->getDamage() & 0x07) === ($this->meta & 0x07)){
104  $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
105 
106  return true;
107  }
108 
109  return false;
110  }else{
111  if($fy > 0.5){
112  $this->meta |= 0x08;
113  }
114  }
115  }
116 
117  if($block->getId() === self::WOOD_SLAB and ($target->getDamage() & 0x07) !== ($this->meta & 0x07)){
118  return false;
119  }
120  $this->getLevel()->setBlock($block, $this, true, true);
121 
122  return true;
123  }
124 
125  public function getBreakTime(Item $item){
126 
127  switch($item->isAxe()){
128  case 5:
129  return 0.4;
130  case 4:
131  return 0.5;
132  case 3:
133  return 0.75;
134  case 2:
135  return 0.25;
136  case 1:
137  return 1.5;
138  default:
139  return 3;
140  }
141  }
142 
143  public function getDrops(Item $item){
144  return [
145  [$this->id, $this->meta & 0x07, 1],
146  ];
147  }
148 }
static get($id, $meta=0, Position $pos=null)
Definition: Block.php:782