PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
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
30
31final 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}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Light.php:59
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock)
Definition Light.php:54
describeBlockItemState(RuntimeDataDescriber $w)
Definition Light.php:37
setLightLevel(int $level)
Definition Light.php:44