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