mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Separate BannerPatternLayer from BannerPatternType
This commit is contained in:
parent
2bc0f9f7a2
commit
a44203a3d4
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\tile\Banner as TileBanner;
|
||||
use pocketmine\block\utils\BannerPattern;
|
||||
use pocketmine\block\utils\BannerPatternLayer;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\item\Banner as ItemBanner;
|
||||
@ -44,8 +44,8 @@ abstract class BaseBanner extends Transparent{
|
||||
protected $baseColor;
|
||||
|
||||
/**
|
||||
* @var BannerPattern[]
|
||||
* @phpstan-var list<BannerPattern>
|
||||
* @var BannerPatternLayer[]
|
||||
* @phpstan-var list<BannerPatternLayer>
|
||||
*/
|
||||
protected $patterns = [];
|
||||
|
||||
@ -83,22 +83,23 @@ abstract class BaseBanner extends Transparent{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BannerPattern[]
|
||||
* @phpstan-return list<BannerPattern>
|
||||
* @return BannerPatternLayer[]
|
||||
* @phpstan-return list<BannerPatternLayer>
|
||||
*/
|
||||
public function getPatterns() : array{
|
||||
return $this->patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BannerPattern[] $patterns
|
||||
* @phpstan-param list<BannerPattern> $patterns
|
||||
* @param BannerPatternLayer[] $patterns
|
||||
*
|
||||
* @phpstan-param list<BannerPatternLayer> $patterns
|
||||
* @return $this
|
||||
*/
|
||||
public function setPatterns(array $patterns) : self{
|
||||
$checked = array_filter($patterns, fn($v) => $v instanceof BannerPattern);
|
||||
$checked = array_filter($patterns, fn($v) => $v instanceof BannerPatternLayer);
|
||||
if(count($checked) !== count($patterns)){
|
||||
throw new \TypeError("Deque must only contain " . BannerPattern::class . " objects");
|
||||
throw new \TypeError("Deque must only contain " . BannerPatternLayer::class . " objects");
|
||||
}
|
||||
$this->patterns = $checked;
|
||||
return $this;
|
||||
|
@ -23,7 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\tile;
|
||||
|
||||
use pocketmine\block\utils\BannerPattern;
|
||||
use pocketmine\block\utils\BannerPatternLayer;
|
||||
use pocketmine\block\utils\BannerPatternType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -47,8 +48,8 @@ class Banner extends Spawnable{
|
||||
private $baseColor;
|
||||
|
||||
/**
|
||||
* @var BannerPattern[]
|
||||
* @phpstan-var list<BannerPattern>
|
||||
* @var BannerPatternLayer[]
|
||||
* @phpstan-var list<BannerPatternLayer>
|
||||
*/
|
||||
private $patterns = [];
|
||||
|
||||
@ -67,7 +68,7 @@ class Banner extends Spawnable{
|
||||
if($patterns !== null){
|
||||
/** @var CompoundTag $pattern */
|
||||
foreach($patterns as $pattern){
|
||||
$this->patterns[] = new BannerPattern($pattern->getString(self::TAG_PATTERN_NAME), $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)));
|
||||
$this->patterns[] = new BannerPatternLayer(BannerPatternType::fromString($pattern->getString(self::TAG_PATTERN_NAME)), $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,7 +79,7 @@ class Banner extends Spawnable{
|
||||
$patterns = new ListTag();
|
||||
foreach($this->patterns as $pattern){
|
||||
$patterns->push(CompoundTag::create()
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getId())
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getType()->getPatternId())
|
||||
->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
|
||||
);
|
||||
}
|
||||
@ -91,7 +92,7 @@ class Banner extends Spawnable{
|
||||
$patterns = new ListTag();
|
||||
foreach($this->patterns as $pattern){
|
||||
$patterns->push(CompoundTag::create()
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getId())
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getType()->getPatternId())
|
||||
->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
|
||||
);
|
||||
}
|
||||
@ -113,16 +114,17 @@ class Banner extends Spawnable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BannerPattern[]
|
||||
* @phpstan-return list<BannerPattern>
|
||||
* @return BannerPatternLayer[]
|
||||
* @phpstan-return list<BannerPatternLayer>
|
||||
*/
|
||||
public function getPatterns() : array{
|
||||
return $this->patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BannerPattern[] $patterns
|
||||
* @phpstan-param list<BannerPattern> $patterns
|
||||
* @param BannerPatternLayer[] $patterns
|
||||
*
|
||||
* @phpstan-param list<BannerPatternLayer> $patterns
|
||||
*/
|
||||
public function setPatterns(array $patterns) : void{
|
||||
$this->patterns = $patterns;
|
||||
|
@ -1,89 +0,0 @@
|
||||
<?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\utils;
|
||||
|
||||
use pocketmine\block\BaseBanner;
|
||||
|
||||
/**
|
||||
* Contains information about a pattern layer on a banner.
|
||||
* @see BaseBanner
|
||||
*/
|
||||
class BannerPattern{
|
||||
public const BORDER = "bo";
|
||||
public const BRICKS = "bri";
|
||||
public const CIRCLE = "mc";
|
||||
public const CREEPER = "cre";
|
||||
public const CROSS = "cr";
|
||||
public const CURLY_BORDER = "cbo";
|
||||
public const DIAGONAL_LEFT = "lud";
|
||||
public const DIAGONAL_RIGHT = "rd";
|
||||
public const DIAGONAL_UP_LEFT = "ld";
|
||||
public const DIAGONAL_UP_RIGHT = "rud";
|
||||
public const FLOWER = "flo";
|
||||
public const GRADIENT = "gra";
|
||||
public const GRADIENT_UP = "gru";
|
||||
public const HALF_HORIZONTAL = "hh";
|
||||
public const HALF_HORIZONTAL_BOTTOM = "hhb";
|
||||
public const HALF_VERTICAL = "vh";
|
||||
public const HALF_VERTICAL_RIGHT = "vhr";
|
||||
public const MOJANG = "moj";
|
||||
public const RHOMBUS = "mr";
|
||||
public const SKULL = "sku";
|
||||
public const SMALL_STRIPES = "ss";
|
||||
public const SQUARE_BOTTOM_LEFT = "bl";
|
||||
public const SQUARE_BOTTOM_RIGHT = "br";
|
||||
public const SQUARE_TOP_LEFT = "tl";
|
||||
public const SQUARE_TOP_RIGHT = "tr";
|
||||
public const STRAIGHT_CROSS = "sc";
|
||||
public const STRIPE_BOTTOM = "bs";
|
||||
public const STRIPE_CENTER = "cs";
|
||||
public const STRIPE_DOWNLEFT = "dls";
|
||||
public const STRIPE_DOWNRIGHT = "drs";
|
||||
public const STRIPE_LEFT = "ls";
|
||||
public const STRIPE_MIDDLE = "ms";
|
||||
public const STRIPE_RIGHT = "rs";
|
||||
public const STRIPE_TOP = "ts";
|
||||
public const TRIANGLE_BOTTOM = "bt";
|
||||
public const TRIANGLE_TOP = "tt";
|
||||
public const TRIANGLES_BOTTOM = "bts";
|
||||
public const TRIANGLES_TOP = "tts";
|
||||
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(string $id, DyeColor $color){
|
||||
$this->id = $id;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
public function getId() : string{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
}
|
47
src/block/utils/BannerPatternLayer.php
Normal file
47
src/block/utils/BannerPatternLayer.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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\utils;
|
||||
|
||||
use pocketmine\block\BaseBanner;
|
||||
|
||||
/**
|
||||
* Contains information about a pattern layer on a banner.
|
||||
* @see BaseBanner
|
||||
*/
|
||||
class BannerPatternLayer{
|
||||
private BannerPatternType $type;
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(BannerPatternType $type, DyeColor $color){
|
||||
$this->type = $type;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
public function getType() : BannerPatternType{ return $this->type; }
|
||||
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
}
|
128
src/block/utils/BannerPatternType.php
Normal file
128
src/block/utils/BannerPatternType.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?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\utils;
|
||||
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
* This must be regenerated whenever registry members are added, removed or changed.
|
||||
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
|
||||
*
|
||||
* @method static BannerPatternType BORDER()
|
||||
* @method static BannerPatternType BRICKS()
|
||||
* @method static BannerPatternType CIRCLE()
|
||||
* @method static BannerPatternType CREEPER()
|
||||
* @method static BannerPatternType CROSS()
|
||||
* @method static BannerPatternType CURLY_BORDER()
|
||||
* @method static BannerPatternType DIAGONAL_LEFT()
|
||||
* @method static BannerPatternType DIAGONAL_RIGHT()
|
||||
* @method static BannerPatternType DIAGONAL_UP_LEFT()
|
||||
* @method static BannerPatternType DIAGONAL_UP_RIGHT()
|
||||
* @method static BannerPatternType FLOWER()
|
||||
* @method static BannerPatternType GRADIENT()
|
||||
* @method static BannerPatternType GRADIENT_UP()
|
||||
* @method static BannerPatternType HALF_HORIZONTAL()
|
||||
* @method static BannerPatternType HALF_HORIZONTAL_BOTTOM()
|
||||
* @method static BannerPatternType HALF_VERTICAL()
|
||||
* @method static BannerPatternType HALF_VERTICAL_RIGHT()
|
||||
* @method static BannerPatternType MOJANG()
|
||||
* @method static BannerPatternType RHOMBUS()
|
||||
* @method static BannerPatternType SKULL()
|
||||
* @method static BannerPatternType SMALL_STRIPES()
|
||||
* @method static BannerPatternType SQUARE_BOTTOM_LEFT()
|
||||
* @method static BannerPatternType SQUARE_BOTTOM_RIGHT()
|
||||
* @method static BannerPatternType SQUARE_TOP_LEFT()
|
||||
* @method static BannerPatternType SQUARE_TOP_RIGHT()
|
||||
* @method static BannerPatternType STRAIGHT_CROSS()
|
||||
* @method static BannerPatternType STRIPE_BOTTOM()
|
||||
* @method static BannerPatternType STRIPE_CENTER()
|
||||
* @method static BannerPatternType STRIPE_DOWNLEFT()
|
||||
* @method static BannerPatternType STRIPE_DOWNRIGHT()
|
||||
* @method static BannerPatternType STRIPE_LEFT()
|
||||
* @method static BannerPatternType STRIPE_MIDDLE()
|
||||
* @method static BannerPatternType STRIPE_RIGHT()
|
||||
* @method static BannerPatternType STRIPE_TOP()
|
||||
* @method static BannerPatternType TRIANGLES_BOTTOM()
|
||||
* @method static BannerPatternType TRIANGLES_TOP()
|
||||
* @method static BannerPatternType TRIANGLE_BOTTOM()
|
||||
* @method static BannerPatternType TRIANGLE_TOP()
|
||||
*/
|
||||
final class BannerPatternType{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("border", "bo"),
|
||||
new self("bricks", "bri"),
|
||||
new self("circle", "mc"),
|
||||
new self("creeper", "cre"),
|
||||
new self("cross", "cr"),
|
||||
new self("curly_border", "cbo"),
|
||||
new self("diagonal_left", "lud"),
|
||||
new self("diagonal_right", "rd"),
|
||||
new self("diagonal_up_left", "ld"),
|
||||
new self("diagonal_up_right", "rud"),
|
||||
new self("flower", "flo"),
|
||||
new self("gradient", "gra"),
|
||||
new self("gradient_up", "gru"),
|
||||
new self("half_horizontal", "hh"),
|
||||
new self("half_horizontal_bottom", "hhb"),
|
||||
new self("half_vertical", "vh"),
|
||||
new self("half_vertical_right", "vhr"),
|
||||
new self("mojang", "moj"),
|
||||
new self("rhombus", "mr"),
|
||||
new self("skull", "sku"),
|
||||
new self("small_stripes", "ss"),
|
||||
new self("square_bottom_left", "bl"),
|
||||
new self("square_bottom_right", "br"),
|
||||
new self("square_top_left", "tl"),
|
||||
new self("square_top_right", "tr"),
|
||||
new self("straight_cross", "sc"),
|
||||
new self("stripe_bottom", "bs"),
|
||||
new self("stripe_center", "cs"),
|
||||
new self("stripe_downleft", "dls"),
|
||||
new self("stripe_downright", "drs"),
|
||||
new self("stripe_left", "ls"),
|
||||
new self("stripe_middle", "ms"),
|
||||
new self("stripe_right", "rs"),
|
||||
new self("stripe_top", "ts"),
|
||||
new self("triangle_bottom", "bt"),
|
||||
new self("triangle_top", "tt"),
|
||||
new self("triangles_bottom", "bts"),
|
||||
new self("triangles_top", "tts")
|
||||
);
|
||||
}
|
||||
|
||||
private string $patternId;
|
||||
|
||||
private function __construct(string $name, string $patternId){
|
||||
$this->Enum___construct($name);
|
||||
$this->patternId = $patternId;
|
||||
}
|
||||
|
||||
public function getPatternId() : string{ return $this->patternId; }
|
||||
}
|
@ -25,7 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\tile\Banner as TileBanner;
|
||||
use pocketmine\block\utils\BannerPattern;
|
||||
use pocketmine\block\utils\BannerPatternLayer;
|
||||
use pocketmine\block\utils\BannerPatternType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@ -41,8 +42,8 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* @var BannerPattern[]
|
||||
* @phpstan-var list<BannerPattern>
|
||||
* @var BannerPatternLayer[]
|
||||
* @phpstan-var list<BannerPatternLayer>
|
||||
*/
|
||||
private $patterns = [];
|
||||
|
||||
@ -70,16 +71,17 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BannerPattern[]
|
||||
* @phpstan-return list<BannerPattern>
|
||||
* @return BannerPatternLayer[]
|
||||
* @phpstan-return list<BannerPatternLayer>
|
||||
*/
|
||||
public function getPatterns() : array{
|
||||
return $this->patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BannerPattern[] $patterns
|
||||
* @phpstan-param list<BannerPattern> $patterns
|
||||
* @param BannerPatternLayer[] $patterns
|
||||
*
|
||||
* @phpstan-param list<BannerPatternLayer> $patterns
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
@ -102,7 +104,7 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
if($patterns !== null){
|
||||
/** @var CompoundTag $t */
|
||||
foreach($patterns as $t){
|
||||
$this->patterns[] = new BannerPattern($t->getString(self::TAG_PATTERN_NAME), $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)));
|
||||
$this->patterns[] = new BannerPatternLayer(BannerPatternType::fromString($t->getString(self::TAG_PATTERN_NAME)), $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,7 +117,7 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
$colorIdMap = DyeColorIdMap::getInstance();
|
||||
foreach($this->patterns as $pattern){
|
||||
$patterns->push(CompoundTag::create()
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getId())
|
||||
->setString(self::TAG_PATTERN_NAME, $pattern->getType()->getPatternId())
|
||||
->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user