PocketMine-MP
5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
Button.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\utils\AnyFacing
;
27
use pocketmine\block\utils\AnyFacingTrait;
28
use
pocketmine\data\runtime\RuntimeDataDescriber
;
29
use
pocketmine\item\Item
;
30
use
pocketmine\math\Facing
;
31
use
pocketmine\math\Vector3
;
32
use
pocketmine\player\Player
;
33
use
pocketmine\world\BlockTransaction
;
34
use
pocketmine\world\sound\RedstonePowerOffSound
;
35
use
pocketmine\world\sound\RedstonePowerOnSound
;
36
37
abstract
class
Button
extends
Flowable
implements
AnyFacing
{
38
use AnyFacingTrait;
39
40
protected
bool
$pressed =
false
;
41
42
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
43
$w->facing($this->facing);
44
$w->bool($this->pressed);
45
}
46
47
public
function
isPressed() : bool{ return $this->pressed; }
48
50
public
function
setPressed
(
bool
$pressed) : self{
51
$this->pressed = $pressed;
52
return
$this;
53
}
54
55
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
56
if($this->canBeSupportedAt($blockReplace, $face)){
57
$this->facing = $face;
58
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
59
}
60
return
false
;
61
}
62
63
abstract
protected
function
getActivationTime() : int;
64
65
public
function
onInteract
(
Item
$item,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
66
if(!$this->pressed){
67
$this->pressed =
true
;
68
$world = $this->position->getWorld();
69
$world->setBlock($this->position, $this);
70
$world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime());
71
$world->addSound($this->position->add(0.5, 0.5, 0.5),
new
RedstonePowerOnSound
());
72
}
73
74
return
true
;
75
}
76
77
public
function
onScheduledUpdate
() : void{
78
if($this->pressed){
79
$this->pressed =
false
;
80
$world = $this->position->getWorld();
81
$world->setBlock($this->position, $this);
82
$world->addSound($this->position->add(0.5, 0.5, 0.5),
new
RedstonePowerOffSound
());
83
}
84
}
85
86
public
function
onNearbyBlockChange
() : void{
87
if(!$this->canBeSupportedAt($this, $this->facing)){
88
$this->position->getWorld()->useBreakOn($this->position);
89
}
90
}
91
92
private
function
canBeSupportedAt(Block $block,
int
$face) : bool{
93
return $block->getAdjacentSupportType(Facing::opposite($face))->hasCenterSupport();
94
}
95
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Button
Definition
Button.php:37
pocketmine\block\Button\onNearbyBlockChange
onNearbyBlockChange()
Definition
Button.php:86
pocketmine\block\Button\setPressed
setPressed(bool $pressed)
Definition
Button.php:50
pocketmine\block\Button\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
Button.php:55
pocketmine\block\Button\onInteract
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
Button.php:65
pocketmine\block\Button\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Button.php:42
pocketmine\block\Button\onScheduledUpdate
onScheduledUpdate()
Definition
Button.php:77
pocketmine\block\Flowable
Definition
Flowable.php:33
pocketmine\item\Item
Definition
Item.php:60
pocketmine\math\Facing
Definition
Facing.php:28
pocketmine\math\Vector3
Definition
Vector3.php:36
pocketmine\player\Player
Definition
Player.php:173
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\world\sound\RedstonePowerOffSound
Definition
RedstonePowerOffSound.php:30
pocketmine\world\sound\RedstonePowerOnSound
Definition
RedstonePowerOnSound.php:30
pocketmine\block\utils\AnyFacing
Definition
AnyFacing.php:28
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:37
pocketmine\block
Definition
ActivatorRail.php:24
src
block
Button.php
Generated by
1.12.0