PocketMine-MP
5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
Light.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
declare(strict_types=1);
23
24
namespace
pocketmine\block
;
25
26
use
pocketmine\data\runtime\RuntimeDataDescriber
;
27
use
pocketmine\item\Item
;
28
use
pocketmine\math\Facing
;
29
use
pocketmine\math\Vector3
;
30
use
pocketmine\player\Player
;
31
32
final
class
Light
extends
Flowable
{
33
public
const
MIN_LIGHT_LEVEL = 0;
34
public
const
MAX_LIGHT_LEVEL = 15;
35
36
private
int
$level = self::MAX_LIGHT_LEVEL;
37
38
public
function
describeBlockItemState
(
RuntimeDataDescriber
$w) : void{
39
$w->boundedIntAuto(self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL, $this->level);
40
}
41
42
public
function
getLightLevel
() : int{ return $this->level; }
43
45
public
function
setLightLevel
(
int
$level) : self{
46
if($level < self::MIN_LIGHT_LEVEL || $level > self::MAX_LIGHT_LEVEL){
47
throw
new \InvalidArgumentException(
"Light level must be in the range "
. self::MIN_LIGHT_LEVEL .
" ... "
. self::MAX_LIGHT_LEVEL);
48
}
49
$this->level = $level;
50
return
$this;
51
}
52
53
public
function
canBeReplaced
() : bool{ return true; }
54
55
public
function
canBePlacedAt
(
Block
$blockReplace,
Vector3
$clickVector,
Facing
$face,
bool
$isClickedBlock) : bool{
56
//light blocks behave like solid blocks when placing them on another light block
57
return $blockReplace->canBeReplaced() && $blockReplace->getTypeId() !== $this->getTypeId();
58
}
59
60
public
function
onInteract
(
Item
$item,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
61
$this->level = $this->level === self::MAX_LIGHT_LEVEL ?
62
self::MIN_LIGHT_LEVEL :
63
$this->level + 1;
64
65
$this->position->getWorld()->setBlock($this->position, $this);
66
67
return
true
;
68
}
69
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Flowable
Definition
Flowable.php:34
pocketmine\block\Light
Definition
Light.php:32
pocketmine\block\Light\canBePlacedAt
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock)
Definition
Light.php:55
pocketmine\block\Light\canBeReplaced
canBeReplaced()
Definition
Light.php:53
pocketmine\block\Light\onInteract
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
Light.php:60
pocketmine\block\Light\describeBlockItemState
describeBlockItemState(RuntimeDataDescriber $w)
Definition
Light.php:38
pocketmine\block\Light\setLightLevel
setLightLevel(int $level)
Definition
Light.php:45
pocketmine\block\Light\getLightLevel
getLightLevel()
Definition
Light.php:42
pocketmine\item\Item
Definition
Item.php:62
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\Player
Definition
Player.php:173
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
Light.php
Generated by
1.12.0