PocketMine-MP
5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
block/Anvil.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\inventory\window\AnvilInventoryWindow
;
27
use
pocketmine\block\utils\Fallable
;
28
use pocketmine\block\utils\FallableTrait;
29
use
pocketmine\block\utils\HorizontalFacing
;
30
use pocketmine\block\utils\HorizontalFacingOption;
31
use pocketmine\block\utils\HorizontalFacingTrait;
32
use
pocketmine\block\utils\MenuAccessor
;
33
use pocketmine\block\utils\MenuAccessorTrait;
34
use pocketmine\block\utils\SupportType;
35
use
pocketmine\data\runtime\RuntimeDataDescriber
;
36
use
pocketmine\entity\object\FallingBlock
;
37
use
pocketmine\item\Item
;
38
use
pocketmine\math\AxisAlignedBB
;
39
use
pocketmine\math\Facing
;
40
use
pocketmine\math\Vector3
;
41
use
pocketmine\player\Player
;
42
use
pocketmine\utils\Utils
;
43
use
pocketmine\world\BlockTransaction
;
44
use
pocketmine\world\Position
;
45
use
pocketmine\world\sound\AnvilFallSound
;
46
use
pocketmine\world\sound\Sound
;
47
use
function
round;
48
49
class
Anvil
extends
Transparent
implements
Fallable
,
HorizontalFacing
,
MenuAccessor
{
50
use FallableTrait;
51
use HorizontalFacingTrait;
52
use MenuAccessorTrait;
53
54
public
const
UNDAMAGED = 0;
55
public
const
SLIGHTLY_DAMAGED = 1;
56
public
const
VERY_DAMAGED = 2;
57
58
private
int
$damage = self::UNDAMAGED;
59
60
public
function
describeBlockItemState
(
RuntimeDataDescriber
$w) : void{
61
$w->boundedIntAuto(self::UNDAMAGED, self::VERY_DAMAGED, $this->damage);
62
}
63
64
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
65
$w->enum($this->facing);
66
}
67
68
public
function
getDamage() : int{ return $this->damage; }
69
71
public
function
setDamage
(
int
$damage) : self{
72
if($damage < self::UNDAMAGED || $damage > self::VERY_DAMAGED){
73
throw
new \InvalidArgumentException(
"Damage must be in range "
. self::UNDAMAGED .
" ... "
. self::VERY_DAMAGED);
74
}
75
$this->damage = $damage;
76
return
$this;
77
}
78
79
protected
function
recalculateCollisionBoxes
() : array{
80
return [
AxisAlignedBB
::one()->squashedCopy(
Facing
::axis(
Facing
::rotateY($this->facing->toFacing(), false)), 1 / 8)];
81
}
82
83
public
function
getSupportType
(
Facing
$facing) : SupportType{
84
return SupportType::NONE;
85
}
86
87
protected
function
newMenu(
Player
$player,
Position
$position) :
AnvilInventoryWindow
{
88
return new
AnvilInventoryWindow
($player, $position);
89
}
90
91
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
92
if($player !== null){
93
$this->facing = HorizontalFacingOption::fromFacing(Facing::rotateY($player->getHorizontalFacing(),
false
));
94
}
95
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
96
}
97
98
public
function
onHitGround
(
FallingBlock
$blockEntity) : bool{
99
if(
Utils
::getRandomFloat() < 0.05 + (round($blockEntity->getFallDistance()) - 1) * 0.05){
100
if
($this->damage !== self::VERY_DAMAGED){
101
$this->damage = $this->damage + 1;
102
}
else
{
103
return
false
;
104
}
105
}
106
return
true
;
107
}
108
109
public
function
getFallDamagePerBlock
() : float{
110
return 2.0;
111
}
112
113
public
function
getMaxFallDamage
() : float{
114
return 40.0;
115
}
116
117
public
function
getLandSound
() : ?
Sound
{
118
return new
AnvilFallSound
();
119
}
120
}
pocketmine\block\Anvil
Definition
block/Anvil.php:49
pocketmine\block\Anvil\getMaxFallDamage
getMaxFallDamage()
Definition
block/Anvil.php:113
pocketmine\block\Anvil\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
block/Anvil.php:79
pocketmine\block\Anvil\setDamage
setDamage(int $damage)
Definition
block/Anvil.php:71
pocketmine\block\Anvil\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
block/Anvil.php:64
pocketmine\block\Anvil\getSupportType
getSupportType(Facing $facing)
Definition
block/Anvil.php:83
pocketmine\block\Anvil\onHitGround
onHitGround(FallingBlock $blockEntity)
Definition
block/Anvil.php:98
pocketmine\block\Anvil\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
Definition
block/Anvil.php:91
pocketmine\block\Anvil\describeBlockItemState
describeBlockItemState(RuntimeDataDescriber $w)
Definition
block/Anvil.php:60
pocketmine\block\Anvil\getFallDamagePerBlock
getFallDamagePerBlock()
Definition
block/Anvil.php:109
pocketmine\block\Anvil\getLandSound
getLandSound()
Definition
block/Anvil.php:117
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\inventory\window\AnvilInventoryWindow
Definition
AnvilInventoryWindow.php:31
pocketmine\entity\object\FallingBlock
Definition
FallingBlock.php:53
pocketmine\item\Item
Definition
Item.php:62
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\Player
Definition
Player.php:173
pocketmine\utils\Utils
Definition
Utils.php:105
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\world\Position
Definition
Position.php:31
pocketmine\world\sound\AnvilFallSound
Definition
AnvilFallSound.php:30
pocketmine\block\utils\Fallable
Definition
Fallable.php:30
pocketmine\block\utils\HorizontalFacing
Definition
HorizontalFacing.php:26
pocketmine\block\utils\MenuAccessor
Definition
MenuAccessor.php:32
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\world\sound\Sound
Definition
Sound.php:29
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
Anvil.php
Generated by
1.12.0