22declare(strict_types=1);
24namespace pocketmine\block\utils;
28use
function array_fill;
29use
function array_pad;
30use
function array_slice;
34use
function str_contains;
37 public const LINE_COUNT = 4;
41 private Color $baseColor;
42 private bool $glowing;
51 public function __construct(?array $lines =
null, ?
Color $baseColor =
null,
bool $glowing =
false){
52 $this->lines = array_fill(0, self::LINE_COUNT,
"");
54 if(count($lines) > self::LINE_COUNT){
55 throw new \InvalidArgumentException(
"Expected at most 4 lines, got " . count($lines));
57 foreach($lines as $k => $line){
58 $this->checkLineIndex($k);
59 Utils::checkUTF8($line);
60 if(str_contains($line,
"\n")){
61 throw new \InvalidArgumentException(
"Line must not contain newlines");
64 $this->lines[$k] = $line;
67 $this->baseColor = $baseColor ??
new Color(0, 0, 0);
68 $this->glowing = $glowing;
78 return new self(array_slice(array_pad(explode(
"\n", $blob), self::LINE_COUNT,
""), 0, self::LINE_COUNT), $baseColor, $glowing);
90 private function checkLineIndex(
int|
string $index) : void{
92 throw new \InvalidArgumentException(
"Index must be an integer");
94 if($index < 0 || $index >= self::LINE_COUNT){
95 throw new \InvalidArgumentException(
"Line index is out of bounds");
105 $this->checkLineIndex($index);
106 return $this->lines[$index];
113 return $this->baseColor;
121 return $this->glowing;
__construct(?array $lines=null, ?Color $baseColor=null, bool $glowing=false)
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)