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