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