PocketMine-MP
5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
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\utils\Utils
;
39
use
pocketmine\world\BlockTransaction
;
40
use
pocketmine\world\sound\AnvilFallSound
;
41
use
pocketmine\world\sound\Sound
;
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
73
protected
function
recalculateCollisionBoxes
() : array{
74
return [
AxisAlignedBB
::one()->squash(
Facing
::axis(
Facing
::rotateY($this->facing, false)), 1 / 8)];
75
}
76
77
public
function
getSupportType
(
int
$facing) : SupportType{
78
return SupportType::NONE;
79
}
80
81
public
function
onInteract
(
Item
$item,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
82
if($player instanceof
Player
){
83
$player->setCurrentWindow(
new
AnvilInventory
($this->position));
84
}
85
86
return
true
;
87
}
88
89
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
90
if($player !== null){
91
$this->facing = Facing::rotateY($player->getHorizontalFacing(),
false
);
92
}
93
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
94
}
95
96
public
function
onHitGround
(
FallingBlock
$blockEntity) : bool{
97
if(
Utils
::getRandomFloat() < 0.05 + (round($blockEntity->getFallDistance()) - 1) * 0.05){
98
if
($this->damage !== self::VERY_DAMAGED){
99
$this->damage = $this->damage + 1;
100
}
else
{
101
return
false
;
102
}
103
}
104
return
true
;
105
}
106
107
public
function
getFallDamagePerBlock
() : float{
108
return 2.0;
109
}
110
111
public
function
getMaxFallDamage
() : float{
112
return 40.0;
113
}
114
115
public
function
getLandSound
() : ?
Sound
{
116
return new
AnvilFallSound
();
117
}
118
}
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:89
pocketmine\block\Anvil\getMaxFallDamage
getMaxFallDamage()
Definition
block/Anvil.php:111
pocketmine\block\Anvil\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
block/Anvil.php:73
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:96
pocketmine\block\Anvil\onInteract
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
block/Anvil.php:81
pocketmine\block\Anvil\describeBlockItemState
describeBlockItemState(RuntimeDataDescriber $w)
Definition
block/Anvil.php:54
pocketmine\block\Anvil\getSupportType
getSupportType(int $facing)
Definition
block/Anvil.php:77
pocketmine\block\Anvil\getFallDamagePerBlock
getFallDamagePerBlock()
Definition
block/Anvil.php:107
pocketmine\block\Anvil\getLandSound
getLandSound()
Definition
block/Anvil.php:115
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:170
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\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