PocketMine-MP
5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
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\ColoredTrait;
29
use pocketmine\block\utils\SupportType;
30
use
pocketmine\item\Banner
as ItemBanner;
31
use
pocketmine\item\Item
;
32
use
pocketmine\item\VanillaItems
;
33
use
pocketmine\math\Vector3
;
34
use
pocketmine\player\Player
;
35
use
pocketmine\world\BlockTransaction
;
36
use
function
assert;
37
use
function
count;
38
39
abstract
class
BaseBanner
extends
Transparent
{
40
use ColoredTrait;
41
46
protected
array $patterns = [];
47
48
public
function
readStateFromWorld
() :
Block
{
49
parent::
readStateFromWorld
();
50
$tile = $this->position->getWorld()->getTile($this->position);
51
if
($tile instanceof TileBanner){
52
$this->color = $tile->getBaseColor();
53
$this->
setPatterns
($tile->getPatterns());
54
}
55
56
return
$this;
57
}
58
59
public
function
writeStateToWorld
() : void{
60
parent::writeStateToWorld();
61
$tile = $this->position->getWorld()->getTile($this->position);
62
assert($tile instanceof TileBanner);
63
$tile->setBaseColor($this->color);
64
$tile->setPatterns($this->patterns);
65
}
66
67
public
function
isSolid
() : bool{
68
return false;
69
}
70
71
public
function
getMaxStackSize
() : int{
72
return 16;
73
}
74
79
public
function
getPatterns
() : array{
80
return $this->patterns;
81
}
82
89
public
function
setPatterns
(array $patterns) : self{
90
foreach($patterns as $pattern){
91
if
(!$pattern instanceof
BannerPatternLayer
){
92
throw
new \TypeError(
"Array must only contain "
. BannerPatternLayer::class .
" objects"
);
93
}
94
}
95
$this->patterns = $patterns;
96
return
$this;
97
}
98
99
protected
function
recalculateCollisionBoxes
() : array{
100
return [];
101
}
102
103
public
function
getSupportType
(
int
$facing) : SupportType{
104
return SupportType::NONE;
105
}
106
107
private
function
canBeSupportedBy(
Block
$block) : bool{
108
return $block->isSolid();
109
}
110
111
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
112
if(!$this->canBeSupportedBy($blockReplace->getSide($this->getSupportingFace()))){
113
return
false
;
114
}
115
if
($item instanceof ItemBanner){
116
$this->color = $item->getColor();
117
$this->setPatterns($item->getPatterns());
118
}
119
120
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
121
}
122
123
abstract
protected
function
getSupportingFace() : int;
124
125
public
function
onNearbyBlockChange
() : void{
126
if(!$this->canBeSupportedBy($this->getSide($this->getSupportingFace()))){
127
$this->position->getWorld()->useBreakOn($this->position);
128
}
129
}
130
131
public
function
getDropsForCompatibleTool
(
Item
$item) : array{
132
$drop = $this->asItem();
133
if
($drop instanceof ItemBanner && count($this->patterns) > 0){
134
$drop->setPatterns($this->patterns);
135
}
136
137
return
[$drop];
138
}
139
140
public
function
getPickedItem
(
bool
$addUserData =
false
) :
Item
{
141
$result = $this->asItem();
142
if
($addUserData && $result instanceof ItemBanner && count($this->patterns) > 0){
143
$result->setPatterns($this->patterns);
144
}
145
return
$result;
146
}
147
148
public
function
asItem
() :
Item
{
149
return
VanillaItems
::BANNER()->setColor($this->color);
150
}
151
}
pocketmine\block\BaseBanner
Definition
BaseBanner.php:39
pocketmine\block\BaseBanner\getDropsForCompatibleTool
getDropsForCompatibleTool(Item $item)
Definition
BaseBanner.php:131
pocketmine\block\BaseBanner\asItem
asItem()
Definition
BaseBanner.php:148
pocketmine\block\BaseBanner\setPatterns
setPatterns(array $patterns)
Definition
BaseBanner.php:89
pocketmine\block\BaseBanner\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
BaseBanner.php:111
pocketmine\block\BaseBanner\getMaxStackSize
getMaxStackSize()
Definition
BaseBanner.php:71
pocketmine\block\BaseBanner\getPatterns
getPatterns()
Definition
BaseBanner.php:79
pocketmine\block\BaseBanner\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
BaseBanner.php:99
pocketmine\block\BaseBanner\isSolid
isSolid()
Definition
BaseBanner.php:67
pocketmine\block\BaseBanner\getSupportType
getSupportType(int $facing)
Definition
BaseBanner.php:103
pocketmine\block\BaseBanner\getPickedItem
getPickedItem(bool $addUserData=false)
Definition
BaseBanner.php:140
pocketmine\block\BaseBanner\onNearbyBlockChange
onNearbyBlockChange()
Definition
BaseBanner.php:125
pocketmine\block\BaseBanner\readStateFromWorld
readStateFromWorld()
Definition
BaseBanner.php:48
pocketmine\block\BaseBanner\writeStateToWorld
writeStateToWorld()
Definition
BaseBanner.php:59
pocketmine\block\Block
Definition
Block.php:62
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:37
pocketmine\item\Item
Definition
Item.php:60
pocketmine\item\VanillaItems
Definition
VanillaItems.php:346
pocketmine\math\Vector3
Definition
Vector3.php:36
pocketmine\player\Player
Definition
Player.php:170
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block
Definition
ActivatorRail.php:24
src
block
BaseBanner.php
Generated by
1.12.0