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