Implemented Light blocks

This commit is contained in:
Dylan K. Taylor
2022-07-02 22:39:11 +01:00
parent 30149c6ed4
commit 2a0fade893
8 changed files with 86 additions and 2 deletions

57
src/block/Light.php Normal file
View File

@ -0,0 +1,57 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\data\runtime\block\BlockDataReader;
use pocketmine\data\runtime\block\BlockDataWriter;
final class Light extends Flowable{
public const MIN_LIGHT_LEVEL = 0;
public const MAX_LIGHT_LEVEL = 15;
private int $level = self::MAX_LIGHT_LEVEL;
public function getRequiredTypeDataBits() : int{ return 4; }
protected function decodeType(BlockDataReader $r) : void{
$this->level = $r->readBoundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL);
}
protected function encodeType(BlockDataWriter $w) : void{
$w->writeInt(4, $this->level);
}
public function getLightLevel() : int{ return $this->level; }
/** @return $this */
public function setLightLevel(int $level) : self{
if($level < self::MIN_LIGHT_LEVEL || $level > self::MAX_LIGHT_LEVEL){
throw new \InvalidArgumentException("Light level must be in the range " . self::MIN_LIGHT_LEVEL . " ... " . self::MAX_LIGHT_LEVEL);
}
$this->level = $level;
return $this;
}
public function canBeReplaced() : bool{ return true; }
}