PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
SnowLayer.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\BlockEventHelper
;
27
use
pocketmine\block\utils\Fallable
;
28
use pocketmine\block\utils\FallableTrait;
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\AxisAlignedBB
;
34
use
pocketmine\math\Facing
;
35
use
pocketmine\math\Vector3
;
36
use
pocketmine\player\Player
;
37
use
pocketmine\world\BlockTransaction
;
38
use
function
floor;
39
use
function
max;
40
41
class
SnowLayer
extends
Flowable
implements
Fallable
{
42
use FallableTrait;
43
44
public
const
MIN_LAYERS = 1;
45
public
const
MAX_LAYERS = 8;
46
47
protected
int
$layers = self::MIN_LAYERS;
48
49
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
50
$w->boundedIntAuto(self::MIN_LAYERS, self::MAX_LAYERS, $this->layers);
51
}
52
53
public
function
getLayers() : int{ return $this->layers; }
54
56
public
function
setLayers
(
int
$layers) : self{
57
if($layers < self::MIN_LAYERS || $layers > self::MAX_LAYERS){
58
throw
new \InvalidArgumentException(
"Layers must be in range "
. self::MIN_LAYERS .
" ... "
. self::MAX_LAYERS);
59
}
60
$this->layers = $layers;
61
return
$this;
62
}
63
64
public
function
canBeReplaced
() : bool{
65
return $this->layers < self::MAX_LAYERS;
66
}
67
71
protected
function
recalculateCollisionBoxes
() : array{
72
//TODO: this zero-height BB is intended to stay in lockstep with a MCPE bug
73
return [
AxisAlignedBB
::one()->trim(
Facing
::UP, $this->layers >= 4 ? 0.5 : 1)];
74
}
75
76
public
function
getSupportType
(
int
$facing) : SupportType{
77
if(!$this->canBeReplaced()){
78
return
SupportType::FULL;
79
}
80
return
SupportType::NONE;
81
}
82
83
private
function
canBeSupportedAt(Block $block) : bool{
84
return $block->getAdjacentSupportType(Facing::DOWN) === SupportType::FULL;
85
}
86
87
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
88
if($blockReplace instanceof
SnowLayer
){
89
if
($blockReplace->layers >= self::MAX_LAYERS){
90
return false;
91
}
92
$this->layers = $blockReplace->layers + 1;
93
}
94
if
($this->canBeSupportedAt($blockReplace)){
95
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
96
}
97
98
return
false
;
99
}
100
101
public
function
ticksRandomly
() : bool{
102
return true;
103
}
104
105
public
function
onRandomTick
() : void{
106
$world = $this->position->getWorld();
107
if
($world->getBlockLightAt($this->position->x, $this->position->y, $this->position->z) >= 12){
108
BlockEventHelper::melt($this, VanillaBlocks::AIR());
109
}
110
}
111
112
public
function
getDropsForCompatibleTool
(
Item
$item) : array{
113
return [
114
VanillaItems
::SNOWBALL()->setCount(max(1, (int) floor($this->layers / 2)))
115
];
116
}
117
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Flowable
Definition
Flowable.php:34
pocketmine\block\SnowLayer
Definition
SnowLayer.php:41
pocketmine\block\SnowLayer\ticksRandomly
ticksRandomly()
Definition
SnowLayer.php:101
pocketmine\block\SnowLayer\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
SnowLayer.php:49
pocketmine\block\SnowLayer\setLayers
setLayers(int $layers)
Definition
SnowLayer.php:56
pocketmine\block\SnowLayer\getDropsForCompatibleTool
getDropsForCompatibleTool(Item $item)
Definition
SnowLayer.php:112
pocketmine\block\SnowLayer\getSupportType
getSupportType(int $facing)
Definition
SnowLayer.php:76
pocketmine\block\SnowLayer\onRandomTick
onRandomTick()
Definition
SnowLayer.php:105
pocketmine\block\SnowLayer\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
SnowLayer.php:71
pocketmine\block\SnowLayer\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
SnowLayer.php:87
pocketmine\block\SnowLayer\canBeReplaced
canBeReplaced()
Definition
SnowLayer.php:64
pocketmine\block\utils\BlockEventHelper
Definition
BlockEventHelper.php:39
pocketmine\item\Item
Definition
Item.php:60
pocketmine\item\VanillaItems
Definition
VanillaItems.php:340
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Facing
Definition
Facing.php:28
pocketmine\math\Vector3
Definition
Vector3.php:36
pocketmine\player\Player
Definition
Player.php:170
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block\utils\Fallable
Definition
Fallable.php:30
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
src
block
SnowLayer.php
Generated by
1.12.0