PocketMine-MP
5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
AmethystCluster.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\utils\AmethystTrait;
27
use
pocketmine\block\utils\AnyFacing
;
28
use pocketmine\block\utils\AnyFacingTrait;
29
use
pocketmine\block\utils\FortuneDropHelper
;
30
use pocketmine\block\utils\SupportType;
31
use
pocketmine\data\runtime\RuntimeDataDescriber
;
32
use
pocketmine\item\Item
;
33
use
pocketmine\item\VanillaItems
;
34
use
pocketmine\math\Axis
;
35
use
pocketmine\math\AxisAlignedBB
;
36
use
pocketmine\math\Facing
;
37
use
pocketmine\math\Vector3
;
38
use
pocketmine\player\Player
;
39
use
pocketmine\utils\AssumptionFailedError
;
40
use
pocketmine\world\BlockTransaction
;
41
42
final
class
AmethystCluster
extends
Transparent
implements
AnyFacing
{
43
use AmethystTrait;
44
use AnyFacingTrait;
45
46
public
const
STAGE_SMALL_BUD = 0;
47
public
const
STAGE_MEDIUM_BUD = 1;
48
public
const
STAGE_LARGE_BUD = 2;
49
public
const
STAGE_CLUSTER = 3;
50
51
private
int
$stage = self::STAGE_CLUSTER;
52
53
public
function
describeBlockItemState
(
RuntimeDataDescriber
$w) : void{
54
$w->boundedIntAuto(self::STAGE_SMALL_BUD, self::STAGE_CLUSTER, $this->stage);
55
}
56
57
public
function
getStage() : int{ return $this->stage; }
58
59
public
function
setStage(
int
$stage) : self{
60
if($stage < self::STAGE_SMALL_BUD || $stage > self::STAGE_CLUSTER){
61
throw
new \InvalidArgumentException(
"Size must be in range "
. self::STAGE_SMALL_BUD .
" ... "
. self::STAGE_CLUSTER);
62
}
63
$this->stage = $stage;
64
return
$this;
65
}
66
67
public
function
getLightLevel
() : int{
68
return match($this->stage){
69
self::STAGE_SMALL_BUD => 1,
70
self::STAGE_MEDIUM_BUD => 2,
71
self::STAGE_LARGE_BUD => 4,
72
self::STAGE_CLUSTER => 5,
73
default
=>
throw
new
AssumptionFailedError
(
"Invalid stage $this->stage"
),
74
};
75
}
76
77
protected
function
recalculateCollisionBoxes
() : array{
78
$myAxis =
Facing
::axis($this->facing);
79
80
$box = AxisAlignedBB::one();
81
foreach
([Axis::Y, Axis::Z, Axis::X] as $axis){
82
if
($axis === $myAxis){
83
continue
;
84
}
85
$box->squash($axis, $this->stage === self::STAGE_SMALL_BUD ? 4 / 16 : 3 / 16);
86
}
87
$box->trim($this->facing, 1 - ($this->stage === self::STAGE_CLUSTER ? 7 / 16 : ($this->stage + 3) / 16));
88
89
return
[$box];
90
}
91
92
private
function
canBeSupportedAt(Block $block,
int
$facing) : bool{
93
return $block->getAdjacentSupportType($facing) === SupportType::FULL;
94
}
95
96
public
function
getSupportType
(
int
$facing) : SupportType{
97
return SupportType::NONE;
98
}
99
100
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
101
if(!$this->canBeSupportedAt($blockReplace,
Facing
::opposite($face))){
102
return
false
;
103
}
104
105
$this->facing = $face;
106
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
107
}
108
109
public
function
onNearbyBlockChange
() : void{
110
if(!$this->canBeSupportedAt($this,
Facing
::opposite($this->facing))){
111
$this->position->getWorld()->useBreakOn($this->position);
112
}
113
}
114
115
public
function
isAffectedBySilkTouch
() : bool{
116
return true;
117
}
118
119
public
function
getDropsForCompatibleTool
(
Item
$item) : array{
120
if($this->stage === self::STAGE_CLUSTER){
121
return
[VanillaItems::AMETHYST_SHARD()->setCount(FortuneDropHelper::weighted($item, min: 4, maxBase: 4))];
122
}
123
124
return
[];
125
}
126
127
public
function
getDropsForIncompatibleTool
(
Item
$item) : array{
128
if($this->stage === self::STAGE_CLUSTER){
129
return
[VanillaItems::AMETHYST_SHARD()->setCount(FortuneDropHelper::weighted($item, min: 2, maxBase: 2))];
130
}
131
132
return
[];
133
}
134
}
pocketmine\block\AmethystCluster
Definition
AmethystCluster.php:42
pocketmine\block\AmethystCluster\onNearbyBlockChange
onNearbyBlockChange()
Definition
AmethystCluster.php:109
pocketmine\block\AmethystCluster\describeBlockItemState
describeBlockItemState(RuntimeDataDescriber $w)
Definition
AmethystCluster.php:53
pocketmine\block\AmethystCluster\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
AmethystCluster.php:100
pocketmine\block\AmethystCluster\getSupportType
getSupportType(int $facing)
Definition
AmethystCluster.php:96
pocketmine\block\AmethystCluster\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
AmethystCluster.php:77
pocketmine\block\AmethystCluster\getDropsForCompatibleTool
getDropsForCompatibleTool(Item $item)
Definition
AmethystCluster.php:119
pocketmine\block\AmethystCluster\getLightLevel
getLightLevel()
Definition
AmethystCluster.php:67
pocketmine\block\AmethystCluster\isAffectedBySilkTouch
isAffectedBySilkTouch()
Definition
AmethystCluster.php:115
pocketmine\block\AmethystCluster\getDropsForIncompatibleTool
getDropsForIncompatibleTool(Item $item)
Definition
AmethystCluster.php:127
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\utils\FortuneDropHelper
Definition
FortuneDropHelper.php:33
pocketmine\item\Item
Definition
Item.php:60
pocketmine\item\VanillaItems
Definition
VanillaItems.php:346
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Axis
Definition
Axis.php:26
pocketmine\math\Facing
Definition
Facing.php:28
pocketmine\math\Vector3
Definition
Vector3.php:36
pocketmine\player\Player
Definition
Player.php:173
pocketmine\utils\AssumptionFailedError
Definition
AssumptionFailedError.php:31
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block\utils\AnyFacing
Definition
AnyFacing.php:28
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:37
pocketmine\block
Definition
ActivatorRail.php:24
src
block
AmethystCluster.php
Generated by
1.12.0