PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Torch.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 Torch extends Flowable{
29 
30  protected $id = self::TORCH;
31 
32  public function __construct($meta = 0){
33  $this->meta = $meta;
34  }
35 
36  public function getLightLevel(){
37  return 15;
38  }
39 
40  public function getName(){
41  return "Torch";
42  }
43 
44 
45  public function onUpdate($type){
46  if($type === Level::BLOCK_UPDATE_NORMAL){
47  $side = $this->getDamage();
48  $faces = [
49  1 => 4,
50  2 => 5,
51  3 => 2,
52  4 => 3,
53  5 => 0,
54  6 => 0,
55  0 => 0,
56  ];
57 
58  if($this->getSide($faces[$side])->isTransparent() === true and !($side === 0 and $this->getSide(0)->getId() === self::FENCE)){
59  $this->getLevel()->useBreakOn($this);
60 
61  return Level::BLOCK_UPDATE_NORMAL;
62  }
63  }
64 
65  return false;
66  }
67 
68  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
69  if($target->isTransparent() === false and $face !== 0){
70  $faces = [
71  1 => 5,
72  2 => 4,
73  3 => 3,
74  4 => 2,
75  5 => 1,
76  ];
77  $this->meta = $faces[$face];
78  $this->getLevel()->setBlock($block, $this, true, true);
79 
80  return true;
81  }elseif($this->getSide(0)->isTransparent() === false or $this->getSide(0)->getId() === self::FENCE){
82  $this->meta = 0;
83  $this->getLevel()->setBlock($block, $this, true, true);
84 
85  return true;
86  }
87 
88  return false;
89  }
90 
91  public function getDrops(Item $item){
92  return [
93  [$this->id, 0, 1],
94  ];
95  }
96 }
getSide($side, $step=1)
Definition: Block.php:1028