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