PocketMine-MP
5.23.3 git-fbaa125d0ce21ffef98fc1630881a92bedfbaa73
Loading...
Searching...
No Matches
MobHead.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\MobHead
as TileMobHead;
27
use pocketmine\block\utils\MobHeadType;
28
use
pocketmine\data\runtime\RuntimeDataDescriber
;
29
use
pocketmine\item\Item
;
30
use
pocketmine\math\AxisAlignedBB
;
31
use
pocketmine\math\Facing
;
32
use
pocketmine\math\Vector3
;
33
use
pocketmine\player\Player
;
34
use
pocketmine\world\BlockTransaction
;
35
use
function
assert;
36
use
function
floor;
37
38
class
MobHead
extends
Flowable
{
39
public
const
MIN_ROTATION = 0;
40
public
const
MAX_ROTATION = 15;
41
42
protected
MobHeadType $mobHeadType = MobHeadType::SKELETON;
43
44
protected
int
$facing = Facing::NORTH;
45
protected
int
$rotation = self::MIN_ROTATION;
//TODO: split this into floor skull and wall skull handling
46
47
public
function
describeBlockItemState
(
RuntimeDataDescriber
$w) : void{
48
$w->enum($this->mobHeadType);
49
}
50
51
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
52
$w->facingExcept($this->facing,
Facing
::DOWN);
53
}
54
55
public
function
readStateFromWorld
() :
Block
{
56
parent::readStateFromWorld();
57
$tile = $this->position->getWorld()->getTile($this->position);
58
if
($tile instanceof TileMobHead){
59
$this->mobHeadType = $tile->getMobHeadType();
60
$this->rotation = $tile->getRotation();
61
}
62
63
return
$this;
64
}
65
66
public
function
writeStateToWorld
() : void{
67
parent::writeStateToWorld();
68
//extra block properties storage hack
69
$tile = $this->position->getWorld()->getTile($this->position);
70
assert($tile instanceof TileMobHead);
71
$tile->setRotation($this->rotation);
72
$tile->setMobHeadType($this->mobHeadType);
73
}
74
75
public
function
getMobHeadType() : MobHeadType{
76
return $this->mobHeadType;
77
}
78
80
public
function
setMobHeadType
(MobHeadType $mobHeadType) : self{
81
$this->mobHeadType = $mobHeadType;
82
return
$this;
83
}
84
85
public
function
getFacing() : int{ return $this->facing; }
86
88
public
function
setFacing
(
int
$facing) : self{
89
if($facing ===
Facing
::DOWN){
90
throw
new \InvalidArgumentException(
"Skull may not face DOWN"
);
91
}
92
$this->facing = $facing;
93
return
$this;
94
}
95
96
public
function
getRotation() : int{ return $this->rotation; }
97
99
public
function
setRotation
(
int
$rotation) : self{
100
if($rotation < self::MIN_ROTATION || $rotation > self::MAX_ROTATION){
101
throw
new \InvalidArgumentException(
"Rotation must be in range "
. self::MIN_ROTATION .
" ... "
. self::MAX_ROTATION);
102
}
103
$this->rotation = $rotation;
104
return
$this;
105
}
106
110
protected
function
recalculateCollisionBoxes
() : array{
111
$collisionBox =
AxisAlignedBB
::one()
112
->contract(0.25, 0, 0.25)
113
->trim(
Facing
::UP, 0.5);
114
if
($this->facing !== Facing::UP){
115
$collisionBox = $collisionBox
116
->offsetTowards(Facing::opposite($this->facing), 0.25)
117
->offsetTowards(Facing::UP, 0.25);
118
}
119
return
[$collisionBox];
120
}
121
122
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
123
if($face ===
Facing
::DOWN){
124
return
false
;
125
}
126
127
$this->facing = $face;
128
if
($player !==
null
&& $face === Facing::UP){
129
$this->rotation = ((int) floor(($player->getLocation()->getYaw() * 16 / 360) + 0.5)) & 0xf;
130
}
131
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
132
}
133
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Flowable
Definition
Flowable.php:34
pocketmine\block\MobHead
Definition
MobHead.php:38
pocketmine\block\MobHead\readStateFromWorld
readStateFromWorld()
Definition
MobHead.php:55
pocketmine\block\MobHead\setFacing
setFacing(int $facing)
Definition
MobHead.php:88
pocketmine\block\MobHead\writeStateToWorld
writeStateToWorld()
Definition
MobHead.php:66
pocketmine\block\MobHead\setRotation
setRotation(int $rotation)
Definition
MobHead.php:99
pocketmine\block\MobHead\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
MobHead.php:122
pocketmine\block\MobHead\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
MobHead.php:110
pocketmine\block\MobHead\describeBlockItemState
describeBlockItemState(RuntimeDataDescriber $w)
Definition
MobHead.php:47
pocketmine\block\MobHead\setMobHeadType
setMobHeadType(MobHeadType $mobHeadType)
Definition
MobHead.php:80
pocketmine\block\MobHead\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
MobHead.php:51
pocketmine\block\tile\MobHead
Definition
tile/MobHead.php:36
pocketmine\item\Item
Definition
Item.php:60
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\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
src
block
MobHead.php
Generated by
1.12.0