PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
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
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\utils\SupportType;
33
34class Torch extends Flowable{
35
36 protected int $facing = Facing::UP;
37
38 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
39 $w->facingExcept($this->facing, Facing::DOWN);
40 }
41
42 public function getFacing() : int{ return $this->facing; }
43
45 public function setFacing(int $facing) : self{
46 if($facing === Facing::DOWN){
47 throw new \InvalidArgumentException("Torch may not face DOWN");
48 }
49 $this->facing = $facing;
50 return $this;
51 }
52
53 public function getLightLevel() : int{
54 return 14;
55 }
56
57 public function onNearbyBlockChange() : void{
58 if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){
59 $this->position->getWorld()->useBreakOn($this->position);
60 }
61 }
62
63 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
64 if($face !== Facing::DOWN && $this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
65 $this->facing = $face;
66 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
67 }else{
68 foreach([
69 Facing::SOUTH,
70 Facing::WEST,
71 Facing::NORTH,
72 Facing::EAST,
73 Facing::DOWN
74 ] as $side){
75 if($this->canBeSupportedAt($blockReplace, $side)){
76 $this->facing = Facing::opposite($side);
77 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
78 }
79 }
80 }
81 return false;
82 }
83
84 private function canBeSupportedAt(Block $block, int $face) : bool{
85 return $face === Facing::DOWN ?
86 $block->getAdjacentSupportType($face)->hasCenterSupport() :
87 $block->getAdjacentSupportType($face) === SupportType::FULL;
88 }
89}
setFacing(int $facing)
Definition Torch.php:45
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition Torch.php:63
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Torch.php:38