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