PocketMine-MP
5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
RedstoneComparator.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\tile\Comparator
;
27
use
pocketmine\block\utils\AnalogRedstoneSignalEmitter
;
28
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
29
use
pocketmine\block\utils\HorizontalFacing
;
30
use pocketmine\block\utils\HorizontalFacingTrait;
31
use
pocketmine\block\utils\PoweredByRedstone
;
32
use pocketmine\block\utils\PoweredByRedstoneTrait;
33
use pocketmine\block\utils\StaticSupportTrait;
34
use pocketmine\block\utils\SupportType;
35
use
pocketmine\data\runtime\RuntimeDataDescriber
;
36
use
pocketmine\item\Item
;
37
use
pocketmine\math\AxisAlignedBB
;
38
use
pocketmine\math\Facing
;
39
use
pocketmine\math\Vector3
;
40
use
pocketmine\player\Player
;
41
use
pocketmine\world\BlockTransaction
;
42
use
function
assert;
43
44
class
RedstoneComparator
extends
Flowable
implements
AnalogRedstoneSignalEmitter
,
PoweredByRedstone
,
HorizontalFacing
{
45
use HorizontalFacingTrait;
46
use AnalogRedstoneSignalEmitterTrait;
47
use PoweredByRedstoneTrait;
48
use StaticSupportTrait;
49
50
protected
bool
$isSubtractMode =
false
;
51
52
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
53
$w->horizontalFacing($this->facing);
54
$w->bool($this->isSubtractMode);
55
$w->bool($this->powered);
56
}
57
58
public
function
readStateFromWorld
() :
Block
{
59
parent::readStateFromWorld();
60
$tile = $this->position->getWorld()->getTile($this->position);
61
if
($tile instanceof
Comparator
){
62
$this->signalStrength = $tile->getSignalStrength();
63
}
64
65
return
$this;
66
}
67
68
public
function
writeStateToWorld
() : void{
69
parent::writeStateToWorld();
70
$tile = $this->position->getWorld()->getTile($this->position);
71
assert($tile instanceof
Comparator
);
72
$tile->setSignalStrength($this->signalStrength);
73
}
74
75
public
function
isSubtractMode() : bool{
76
return $this->isSubtractMode;
77
}
78
80
public
function
setSubtractMode
(
bool
$isSubtractMode) : self{
81
$this->isSubtractMode = $isSubtractMode;
82
return
$this;
83
}
84
85
protected
function
recalculateCollisionBoxes
() : array{
86
return [
AxisAlignedBB
::one()->trim(
Facing
::UP, 7 / 8)];
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::opposite($player->getHorizontalFacing());
92
}
93
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
94
}
95
96
public
function
onInteract
(
Item
$item,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
97
$this->isSubtractMode = !$this->isSubtractMode;
98
$this->position->getWorld()->setBlock($this->position, $this);
99
return
true
;
100
}
101
102
private
function
canBeSupportedAt(
Block
$block) : bool{
103
return $block->getAdjacentSupportType(
Facing
::DOWN) !== SupportType::NONE;
104
}
105
106
//TODO: redstone functionality
107
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Flowable
Definition
Flowable.php:33
pocketmine\block\RedstoneComparator
Definition
RedstoneComparator.php:44
pocketmine\block\RedstoneComparator\readStateFromWorld
readStateFromWorld()
Definition
RedstoneComparator.php:58
pocketmine\block\RedstoneComparator\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
RedstoneComparator.php:52
pocketmine\block\RedstoneComparator\setSubtractMode
setSubtractMode(bool $isSubtractMode)
Definition
RedstoneComparator.php:80
pocketmine\block\RedstoneComparator\writeStateToWorld
writeStateToWorld()
Definition
RedstoneComparator.php:68
pocketmine\block\RedstoneComparator\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
RedstoneComparator.php:85
pocketmine\block\RedstoneComparator\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
RedstoneComparator.php:89
pocketmine\block\RedstoneComparator\onInteract
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
RedstoneComparator.php:96
pocketmine\block\tile\Comparator
Definition
Comparator.php:33
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\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block\utils\AnalogRedstoneSignalEmitter
Definition
AnalogRedstoneSignalEmitter.php:26
pocketmine\block\utils\HorizontalFacing
Definition
HorizontalFacing.php:28
pocketmine\block\utils\PoweredByRedstone
Definition
PoweredByRedstone.php:26
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:37
pocketmine\block
Definition
ActivatorRail.php:24
src
block
RedstoneComparator.php
Generated by
1.12.0