mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Dye now can be used to change Sign text color (#4690)
This commit is contained in:
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\utils\Utils;
|
||||
use function array_fill;
|
||||
use function array_pad;
|
||||
@ -37,6 +38,8 @@ class SignText{
|
||||
|
||||
/** @var string[] */
|
||||
private array $lines;
|
||||
private Color $baseColor;
|
||||
private bool $glowing;
|
||||
|
||||
/**
|
||||
* @param string[]|null $lines index-sensitive; omitting an index will leave it unchanged
|
||||
@ -45,7 +48,7 @@ class SignText{
|
||||
* @throws \InvalidArgumentException if invalid keys (out of bounds or string) are found in the array
|
||||
* @throws \InvalidArgumentException if any line is not valid UTF-8 or contains a newline
|
||||
*/
|
||||
public function __construct(?array $lines = null){
|
||||
public function __construct(?array $lines = null, ?Color $baseColor = null, bool $glowing = false){
|
||||
$this->lines = array_fill(0, self::LINE_COUNT, "");
|
||||
if($lines !== null){
|
||||
if(count($lines) > self::LINE_COUNT){
|
||||
@ -61,6 +64,8 @@ class SignText{
|
||||
$this->lines[$k] = $line;
|
||||
}
|
||||
}
|
||||
$this->baseColor = $baseColor ?? new Color(0, 0, 0);
|
||||
$this->glowing = $glowing;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,8 +74,8 @@ class SignText{
|
||||
*
|
||||
* @throws \InvalidArgumentException if the text is not valid UTF-8
|
||||
*/
|
||||
public static function fromBlob(string $blob) : SignText{
|
||||
return new self(array_slice(array_pad(explode("\n", $blob), self::LINE_COUNT, ""), 0, self::LINE_COUNT));
|
||||
public static function fromBlob(string $blob, ?Color $baseColor = null, bool $glowing = false) : SignText{
|
||||
return new self(array_slice(array_pad(explode("\n", $blob), self::LINE_COUNT, ""), 0, self::LINE_COUNT), $baseColor, $glowing);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,4 +108,19 @@ class SignText{
|
||||
$this->checkLineIndex($index);
|
||||
return $this->lines[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base text color of sign. Color codes using the § escape character will override this color when used.
|
||||
*/
|
||||
public function getBaseColor() : Color{
|
||||
return $this->baseColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the sign text is glowing. When true, the text will have an outline (usually a darker tone of the
|
||||
* base color, or white for black text), and will glow in the dark, making it readable without any light sources.
|
||||
*/
|
||||
public function isGlowing() : bool{
|
||||
return $this->glowing;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user