PocketMine-MP
5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
BaseBanner.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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block
;
25
26
use
pocketmine\block\tile\Banner
as TileBanner;
27
use
pocketmine\block\utils\BannerPatternLayer
;
28
use
pocketmine\block\utils\Colored
;
29
use pocketmine\block\utils\ColoredTrait;
30
use pocketmine\block\utils\SupportType;
31
use
pocketmine\item\Banner
as ItemBanner;
32
use
pocketmine\item\Item
;
33
use
pocketmine\item\VanillaItems
;
34
use
pocketmine\math\Facing
;
35
use
pocketmine\math\Vector3
;
36
use
pocketmine\player\Player
;
37
use
pocketmine\world\BlockTransaction
;
38
use
function
assert;
39
use
function
count;
40
41
abstract
class
BaseBanner
extends
Transparent
implements
Colored
{
42
use ColoredTrait;
43
48
protected
array $patterns = [];
49
50
public
function
readStateFromWorld
() :
Block
{
51
parent::
readStateFromWorld
();
52
$tile = $this->position->getWorld()->getTile($this->position);
53
if
($tile instanceof TileBanner){
54
if
($tile->getType() === TileBanner::TYPE_OMINOUS){
55
//illager banner is implemented as a separate block, as it doesn't support base color or custom patterns
56
return
$this->getOminousVersion();
57
}
58
$this->color = $tile->getBaseColor();
59
$this->
setPatterns
($tile->getPatterns());
60
}
61
62
return
$this;
63
}
64
65
abstract
protected
function
getOminousVersion() : Block;
66
67
public
function
writeStateToWorld
() : void{
68
parent::writeStateToWorld();
69
$tile = $this->position->getWorld()->getTile($this->position);
70
assert($tile instanceof TileBanner);
71
$tile->setBaseColor($this->color);
72
$tile->setPatterns($this->patterns);
73
}
74
75
public
function
isSolid
() : bool{
76
return false;
77
}
78
79
public
function
getMaxStackSize
() : int{
80
return 16;
81
}
82
87
public
function
getPatterns
() : array{
88
return $this->patterns;
89
}
90
97
public
function
setPatterns
(array $patterns) : self{
98
foreach($patterns as $pattern){
99
if
(!$pattern instanceof
BannerPatternLayer
){
100
throw
new \TypeError(
"Array must only contain "
. BannerPatternLayer::class .
" objects"
);
101
}
102
}
103
$this->patterns = $patterns;
104
return
$this;
105
}
106
107
protected
function
recalculateCollisionBoxes
() : array{
108
return [];
109
}
110
111
public
function
getSupportType
(
Facing
$facing) : SupportType{
112
return SupportType::NONE;
113
}
114
115
private
function
canBeSupportedBy(
Block
$block) : bool{
116
return $block->isSolid();
117
}
118
119
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
120
if(!$this->canBeSupportedBy($blockReplace->getSide($this->getSupportingFace()))){
121
return
false
;
122
}
123
if
($item instanceof ItemBanner){
124
$this->color = $item->getColor();
125
$this->setPatterns($item->getPatterns());
126
}
127
128
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
129
}
130
131
abstract
protected
function
getSupportingFace() : Facing;
132
133
public
function
onNearbyBlockChange
() : void{
134
if(!$this->canBeSupportedBy($this->getSide($this->getSupportingFace()))){
135
$this->position->getWorld()->useBreakOn($this->position);
136
}
137
}
138
139
public
function
getDropsForCompatibleTool
(
Item
$item) : array{
140
$drop = $this->asItem();
141
if
($drop instanceof ItemBanner && count($this->patterns) > 0){
142
$drop->setPatterns($this->patterns);
143
}
144
145
return
[$drop];
146
}
147
148
public
function
getPickedItem
(
bool
$addUserData =
false
) :
Item
{
149
$result = $this->asItem();
150
if
($addUserData && $result instanceof ItemBanner && count($this->patterns) > 0){
151
$result->setPatterns($this->patterns);
152
}
153
return
$result;
154
}
155
156
public
function
asItem
() :
Item
{
157
return
VanillaItems
::BANNER()->setColor($this->color);
158
}
159
}
pocketmine\block\BaseBanner
Definition
BaseBanner.php:41
pocketmine\block\BaseBanner\getDropsForCompatibleTool
getDropsForCompatibleTool(Item $item)
Definition
BaseBanner.php:139
pocketmine\block\BaseBanner\getSupportType
getSupportType(Facing $facing)
Definition
BaseBanner.php:111
pocketmine\block\BaseBanner\asItem
asItem()
Definition
BaseBanner.php:156
pocketmine\block\BaseBanner\setPatterns
setPatterns(array $patterns)
Definition
BaseBanner.php:97
pocketmine\block\BaseBanner\getMaxStackSize
getMaxStackSize()
Definition
BaseBanner.php:79
pocketmine\block\BaseBanner\getPatterns
getPatterns()
Definition
BaseBanner.php:87
pocketmine\block\BaseBanner\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
BaseBanner.php:107
pocketmine\block\BaseBanner\isSolid
isSolid()
Definition
BaseBanner.php:75
pocketmine\block\BaseBanner\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
Definition
BaseBanner.php:119
pocketmine\block\BaseBanner\getPickedItem
getPickedItem(bool $addUserData=false)
Definition
BaseBanner.php:148
pocketmine\block\BaseBanner\onNearbyBlockChange
onNearbyBlockChange()
Definition
BaseBanner.php:133
pocketmine\block\BaseBanner\readStateFromWorld
readStateFromWorld()
Definition
BaseBanner.php:50
pocketmine\block\BaseBanner\writeStateToWorld
writeStateToWorld()
Definition
BaseBanner.php:67
pocketmine\block\Block
Definition
Block.php:63
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\tile\Banner
Definition
block/tile/Banner.php:38
pocketmine\block\utils\BannerPatternLayer
Definition
BannerPatternLayer.php:32
pocketmine\item\Banner
Definition
item/Banner.php:36
pocketmine\item\Item
Definition
Item.php:62
pocketmine\item\VanillaItems
Definition
VanillaItems.php:362
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\Player
Definition
Player.php:174
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block\utils\Colored
Definition
Colored.php:26
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
BaseBanner.php
Generated by
1.12.0