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
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
31
32final 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}
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock)
Definition Light.php:55
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Light.php:60
describeBlockItemState(RuntimeDataDescriber $w)
Definition Light.php:38
setLightLevel(int $level)
Definition Light.php:45